//----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);
}