function hourOpen(int hourblockstart, int hourblockend)
{
//blocks new trades between selected hours
//uses NYSE time, including DST
if ( (lhour(ET) >= hourblockstart) && (lhour(ET) < hourblockend) )
return 0; //between blocked hours, do not allow trade opens
else
return 1; //no conditions met, allow trades by default
}
function fridayCloseTrading(int fridayfinalhourET)
{
//blocks new open trades on fridays from the hour set
// uses NYSE time, including DST
if (ldow(ET) == FRIDAY && (lhour(ET)>= fridayfinalhourET))
return 0; // during the no new trade friday period.
else
return 1; // no condition met, allow new trades by default
}
function run()
{
set(PARAMETERS);
StartDate = 2011;
EndDate = 2013;
BarPeriod = 60;
LookBack = 250;
//edge trading logic
int FastPeriod = 12;
int SlowPeriod = 26;
int SignalPeriod = 9;
int MACDOpenLevel = 3;
int MACDCloseLevel= 2;
int MATrendPeriod=24;
int OpenOrders = 2;
int hourblockend = 3;
int hourblockstart = 14;
int fridayfinalhourET = 1;
vars PriceClose = series(priceClose());
MACD(PriceClose,FastPeriod,SlowPeriod,SignalPeriod);
vars MainLine = series(rMACD);
vars SignalLine = series(rMACDSignal);
vars MA1 = series(EMA(PriceClose,MATrendPeriod));
Stop = ATR(200)*optimize(3,1,10,1); //Adaptive Stop
Trail = ATR(200)*optimize(5,1,10,1); //Adaptive Trail
// TakeProfit = 100*PIP;
if(hourOpen(hourblockend,hourblockstart) && fridayCloseTrading(fridayfinalhourET)){
if(NumOpenTotal<OpenOrders && MainLine[0]<0 && crossOver(MainLine,SignalLine) && (-1*MainLine[0])>(0.0001*MACDOpenLevel) && rising(MA1))
reverseLong(1);
else if(NumOpenTotal<OpenOrders && MainLine[0]>0 && crossUnder(MainLine,SignalLine) && MainLine[0]>(0.0001*MACDOpenLevel) && falling(MA1))
reverseShort(1);
}
// plot("MainLine", MainLine[0], NEW, BLUE);
// plot("SignalLine", SignalLine[0], 0, RED);
// plot("TrendLine", MA1[0], NEW, BLACK);
}