DEFPARAM CumulateOrders = False
//
Nperiods1 = 10 //lookback periods for RSI
Nperiods2 = 10 //lookback periods for STOCHASTIC
Nperiods3 = 10 //lookback periods for MACD
//
// 14-period RSI
RsiOB = 70 //OverBought
RsiOS = 100 - RsiOB //OverSold
MidLine = 50
myRSI = rsi[14](close)
L1 = summation[Nperiods1](myRSI CROSSES OVER MidLine) //Crossover in the last Nperiods1 bars
L2 = myRSI > MidLine //RSI must currently be > 50
L3 = 1
FOR i = 1 TO Nperiods1
IF myRSI[i] CROSSES OVER MidLine THEN
break
ENDIF
IF myRSI[i] < MidLine THEN //RSI souldn't have returned below 50 since
L3 = 0 // the crossover
break
ENDIF
NEXT
//
// Stochastic(10,3,6)
StOB = 80 //OverBought
StOS = 100 - StOB //OverSold
Kline = Stochastic[10,3](close)
Dline = Average[6,0](Kline)
L4 = summation[Nperiods2]((Kline CROSSES OVER Dline) AND (Kline < StOS)) //Crossover of lines K and D
// in the last Nperiods2 bars,
// provided it occurred when
// both lines were still in the
// OverSold area
L5 = (Kline < StOB) AND (Dline < StOB) //currently both lines are
// below the OverBought area
//
// MACD 12,26,9
myMACD = ExponentialAverage[12](close) - ExponentialAverage[26](close)
mySignalLine = ExponentialAverage[9](myMACD)
myHisto = myMACD - mySignalLine
L6 = summation[Nperiods3]((myMACD CROSSES OVER mySignalLine) AND (myMACD < 0)) //Crossover in the last
// Nperiods3 bars, provided
// it's below the ZERO line
L7 = 1
FOR i = 1 TO Nperiods3
IF myMACD[i] CROSSES OVER mySignalLine[i] THEN
break
ENDIF
IF myMACD[i] > 0 THEN //MACD souldn't have returned below 0 since the crossover
L7 = 0
break
ENDIF
NEXT
L8 = myMACD < 0 //MACD is currently below 0
//
LongCond = L1 AND L2 AND L3 AND L4 AND L5 AND L6 AND L7 AND L8 AND Not OnMarket
//
IF LongCond THEN
BUY 1 Contract at Market
ENDIF
SET STOP plOSS 300
SET TARGET pPROFIT 600