Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (SBGuy, Quad), 768 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Trades not appearing with call to plot() #466823
07/04/17 01:15
07/04/17 01:15
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
Hi all,

Back again with another noob problem.
The basic RSI strategy I coded and posted about here: http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=466814#Post466814
will plot its trades on the price chart with the following call:
Code:
set(LOGFILE);
	//PlotWidth = 600;
	//PlotHeight1 = 300;
	plot("Signal",series(RSI(series(priceClose()), 14)),NEW,RED);
	plot("Threshold1",75,0,BLACK);
	plot("Threshold2",25,0,BLACK);
	set(PLOTNOW);



...yet another script I wrote as a foray into writing my own indicators does not plot trades. It is definitely taking them and the indicator values are plotted too. Just no trades.
Here's the full code:
Code:
//----globals
var sixthLen 	= 1682;
var splitBy 	= 6;
var TP 			= 100*PIP; //takeprofit in pips converted to price value
var buffer 		= 20*PIP; //distance from market for pendings to be placed
var tradeLim	= 2000;

//----sixths functions
var sixthHigh(period, splitBy)
{
	return (HH(period) - ((HH(period)-LL(period))/splitBy));
}

var sixthLow(period, splitBy)
{
	return (HH(period) + ((HH(period)-LL(period))/splitBy));
}

//----order functions
function CheckForLongOpportunity()
{
	vars Price = series(price()); //create the price series for the selected asset
			
	//check to see if we can enter a long
	if(NumOpenLong + NumPendingLong < tradeLim)
	{
		if(crossUnder(Price, sixthLow(sixthLen, splitBy)))
		{
			enterLong(0, price() + buffer, 0, TP);
			//reverseShort(1);
		}	
	}
}

function CheckForShortOpportunity()
{
	vars Price = series(price()); //create the price series for the selected asset
	
	//check to see if we can enter a short
	if(NumOpenShort + NumPendingShort < tradeLim) 
	{
		if(crossOver(Price, sixthHigh(sixthLen, splitBy)))
		{
			enterShort(0, price() - buffer, 0, TP);
			//reverseLong(1);
		}	
	}
}

//----main exectution block, comparable to OnTick()
function run()
{
	BarPeriod = 60;
	LookBack = sixthLen;
	//PlotBars = 500;
	StartDate = 2010;
	EndDate = 2015;
		
	//check to see if we should open a trade
	CheckForLongOpportunity();
	CheckForShortOpportunity();
	
	set(LOGFILE);
	plot("Lowest", LL(sixthLen), 0, BLACK);
	plot("Highest", HH(sixthLen), 0, BLACK);
	plot("upperTZ", HH(sixthLen) - ((HH(sixthLen)-LL(sixthLen))/splitBy), 0, RED);
	plot("lowerTZ", LL(sixthLen) + ((HH(sixthLen)-LL(sixthLen))/splitBy), 0, RED);
	set(PLOTNOW);
}



I'm truly sorry about posting such a quick succession of seemingly simple problems. This forum is the only resource (besides the zorro manual) that I have been able to find. And although the manual is pretty good, it doesn't (understandably and rightfully so) cater to those who are complete programming novices (novicii?). Once I get off ground floor I can start returning those helping hands.

Re: Trades not appearing with call to plot() [Re: BobbyT] #466830
07/04/17 09:42
07/04/17 09:42
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Two problems. First is here:

var TP = 100*PIP; //takeprofit in pips converted to price value
var buffer = 20*PIP;

These variables are not changed anymore in the script, so when you load a different asset or use a portfolio, they will be bwrong. Better set them up in the trading function.

Second is the reason why your trades are not plotted: They never close. You see that in the log.

Re: Trades not appearing with call to plot() [Re: jcl] #466842
07/04/17 16:18
07/04/17 16:18
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
Hi JCL,

I had read about globals not being set until the script was compiled unless they were set with if(InitRun) but it was a little confusing.

These variables are not changed, ever. Shouldn't they be read at runtime? I have a reasonable amount of experience in MQL4 and R so analogies to those environments may help me understand what is happening here.

Is it something like this: the script is run on (eg) EURUSD and the script is compiled, TP/buffer is calculated and the script proceeds. When it is run on another symbol, the script is already compiled so it does not recalculate these values(?).
So zorro scripts do not 'initialise' with every new run unlike MQL4 or R which will recalculate values upon runtime unless they are called from global variables or the local environment respectively(?)

I had checked the log and thought they may not be closing but I also thought that open trades would also be plotted. Small teething problems when moving to a new platform, I'll get there.

While I have you, could you please tell me what this is:
Code:
(EUR/AUD::S) Missed entry 1.4438 after 1 bar


Are the trades automatically expiring after one bar? There is no expiry set on them (that I know of). How can I make pendings remain until they are deleted? Also, how do I access the trade pool as I'd like to move pendings or set more pending trades relative to existing ones. I believe its through the TRADE* structure however structures/classes are something I've never understood. Do you have some simple boilerplate code that demonstrates the above?

Cheers,
BobbyT

PS: I'm a bit off topic now so if you'd like me to start a new thread feel free to say so laugh
Another PS/Edit: I have noticed that trades are closing when they shouldn't be. I have set no SL and no expiry on any trades yet in addition to pendings (possibly) being deleted, open trades are closing for no apparent reason. Any ideas?

Last edited by BobbyT; 07/04/17 16:45.
Re: Trades not appearing with call to plot() [Re: BobbyT] #466850
07/04/17 17:41
07/04/17 17:41
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Zorro does not know at compile time which symbol you might want to trade. Initializing global variables is ok, but you must not forget to set them to their real values after selecting the asset.

It is sort of difficult to plot open trades without knowing at which future price they will close. All remaining open trades are closed after the end of the simulation, but I think they are not plotted when they were still open at that time.

Re: Trades not appearing with call to plot() [Re: jcl] #466852
07/04/17 17:55
07/04/17 17:55
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
I see. So best option, like you suggested, is to define them within a function so they are defined every new asset traded. Thanks laugh

Fair enough. I have MQL4/MT4 on the brain. During backtests, entries are marked regardless of the trade outcome. A minor inconvenience but one that can be lived with/worked around easily enough.

Any ideas on the above log file entry? Or how to access the trade pool? Or should I start a new thread (or two) before this one spirals out of control?

Cheers,
BobbyT

Re: Trades not appearing with call to plot() [Re: BobbyT] #466855
07/04/17 18:13
07/04/17 18:13
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The default wait time for pending trades is 1 bar. If the entry is missed, you see that log message.

Re: Trades not appearing with call to plot() [Re: jcl] #466857
07/04/17 18:30
07/04/17 18:30
Joined: Jun 2017
Posts: 78
B
BobbyT Offline OP
Junior Member
BobbyT  Offline OP
Junior Member
B

Joined: Jun 2017
Posts: 78
This is the complete opposite to what I have experienced in other platforms. Normally pendings are placed with perpetual expiries. I guess it's just a reflection on the intended purpose of Zorro compared to other platforms. It's not a bad thing, just an observation.

Maybe the enterLong/Short functions could have an expiry variable added to them(?). Though given my level of understanding of the platform thus far its likely there's something this would break that I haven't played with yet.

Ill have a play with the TRADE* structure for accessing the trade pool now that I know how to extend the life of trades. I should have some code you (and anyone else reading my nonsense) to have a laugh/shake heads at by the end of the week but hopefully in the next few days.

Cheers,
BobbyT


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1