DEFPARAM CumulateOrders = FALSE
ONCE BuyCond = 0
ONCE SellCond = 0
IF OnMarket THEN
BuyCond = 0
ENDIF
IF Not OnMarket THEN
SellCond = 0
ENDIF
Ema144 = exponentialaverage[144](close)
Ema89 = exponentialaverage[89](close)
Ema34 = exponentialaverage[34](close)
MyMacd = Macd[12,26,9](close)
StocK = Stochastic[8,4](close)
c1 = Ema34 CROSSES OVER Ema89
c2 = MyMacd > 0
c3 = StocK > 30
IF BuyCond = 0 THEN
BuyCond = c1 AND c2 AND c3
MyPrice= Ema34 //buy at Ema34 or
//MyPrice = low[1] + (range[1] / 2) //buy at half of previous candle
ENDIF
// Keep entering a pending orders bar after bar till Onmarket
IF BuyCond THEN
IF close > MyPrice THEN
BUY 1 CONTRACT AT MyPrice LIMIT //buy at a better price
ELSE
BUY 1 CONTRACT AT MyPrice STOP //buy at a worse price
ENDIF
ENDIF
IF SellCond = 0 THEN
SellCond = Ema34 CROSSES UNDER Ema144
SellPrice = Ema34
ENDIF
// Keep entering a pending orders bar after bar till Exit
IF SellCond THEN
IF close > SellPrice THEN
SELL 1 CONTRACT AT SellPrice STOP //exit at a worse price
ELSE
SELL 1 CONTRACT AT SellPrice LIMIT //exit at a better price
ENDIF
ENDIF