DEFPARAM CumulateOrders = false
MinLookBack = 2 //2 crossing must have occured at least these bars before PullBack
MaxLookBack = 17 //17 crossing must have occured at most these bars before PullBack
MA50 = average[50,1](close)//50,1
MA20 = average[20,1](close)//20,1
// LONG side
x = close crosses over ma50
y = close crosses over ma20
IF x OR (close > MA50 AND low < MA50) THEN //when a pullback occurs...
IF summation[MinLookBack](y[1]) = 0 THEN
IF summation[MaxLookBack](y[MinLookBack + 1]) AND Not OnMarket AND close > open THEN
BUY 1 CONTRACT AT MARKET
SET STOP pLOSS 50 //50
SET TARGET pPROFIT 300 //300
ENDIF
ENDIF
ENDIF
// SHORT side
x = close crosses under ma50
y = close crosses under ma20
IF x OR (close < MA50 AND high > MA50) THEN //when a pullback occurs...
IF summation[MinLookBack](y[1]) = 0 THEN
IF summation[MaxLookBack](y[MinLookBack + 1]) AND Not OnMarket AND close < open THEN
SELLSHORT 1 CONTRACT AT MARKET
SET STOP pLOSS 50 //50
SET TARGET pPROFIT 300 //300
ENDIF
ENDIF
ENDIF