Hi all,

OK, they are most likely not closing themselves but I can't put my finger on what the issue is.
The strategy is simple enough and based on price levels. Once price is inside the upper/lower zone, it places a sell/buy below/above the zone by a certain number of pips. Trades are meant to stay open until TP or the end of the test period.

The code:
Code:
//----globals
if(is(INITRUN))
{
	var sixthLen 	= 1682;
	var splitBy 	= 6;
	//var TP 			= 50*PIP; //takeprofit in pips converted to price value
	//var buffer 		= 10*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 (LL(period) + ((HH(period)-LL(period))/splitBy));
}

//----order functions
function CheckForTradeOpportunity()
{
	var TP 			= 50*PIP; //takeprofit in pips converted to price value
        var buffer 		= 10*PIP; //distance from market for pendings to be placed
	
	vars Price = series(priceClose()); //create the price series for the selected asset
		
	EntryTime = 10000000;
			
	//check to see if we can enter long
	if(NumOpenLong + NumPendingLong < tradeLim) 
	{
		if(crossUnder(Price, sixthLow(sixthLen, splitBy))) //> need to change this to a comparative function or add another block for non cross events
		{
			enterLong(0, sixthLow(sixthLen, splitBy) + buffer, 0, TP);
			printf("nprice = %.5f, sixthsLow = %.5f, pending price = %.5f", price(), sixthLow(sixthLen, splitBy), sixthLow(sixthLen, splitBy) + buffer);		
		}	
	}
	
	//check to see if we can enter short
	if(NumOpenShort + NumPendingShort < tradeLim) 
	{
		if(crossOver(Price, sixthHigh(sixthLen, splitBy)))
		{
			enterShort(0, sixthHigh(sixthLen, splitBy) - buffer, 0, TP);
			printf("nprice = %.5f, sixthsHigh = %.5f, pending price = %.5f", price(), sixthHigh(sixthLen, splitBy), sixthLow(sixthLen, splitBy) + buffer);	
		}	
	}
}

//----main exectution block, comparable to OnTick()
function run()
{
	set(LOGFILE);
	BarPeriod = 60;
	LookBack = sixthLen;
	//PlotBars = 500;
	StartDate = 2012;
	EndDate = 2017;
	Hedge = 2; //allows full hedging, default = 0 -> no hedgintg	
	
	CheckForTradeOpportunity();
		
//--------------
	
	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);
}



Inspecting the resulting plot reveals there are trades closing at a loss before the simulation is over. I'm not sure why and it is likely some default global I'm not aware of despite having found and checked it in the manual. Any ideas?

Cheers,
BobbyT

EDIT: changed the start/end period to highlight another problem. There are trades being placed at what appears to be erroneous prices. Check the plot in the first half of July 2010. There is a trade that has opened at the peak of a small rally. This trade is well outside of the trade zone (both upper and lower zones). This is easily seen against the red channel which marks out the inner boundary of the trade zone.
I'm taken aback by the amount of teething problems I'm having switching over to Zorro. Having said that, the platforms I'm familiar with have massive user bases and chances are if you have a problem you can normally find info about it somewhere. Alas, Zorro is still growing. So I have to bother you poor sods if I need help. Sorry (these posts will get more interesting with time but at this stage I'm still learning to crawl before I can walk in Zorro land)

Last edited by BobbyT; 07/18/17 03:31.