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