DEFPARAM PRELOADBARS = 2000
DEFPARAM cumulateOrders = false
DEFPARAM FlatBefore = 080000
DEFPARAM FlatAfter = 205000
ST1 = Supertrend[1.5, 10]
ST2 = Supertrend[2.5, 10]
bbup = BollingerUp[20](close)
bbdn = BollingerDown[20](close)
BearishFractal = ((high[1] > high[2] AND high[1] > high) and close<=close[1] and close<=open[1] and close[1]=>open[2] and low<low[1]) or (high[1]>high and high[1] >high[2] and low[1]>low and low[1]>low[2])
BullishFractal = ((low[1] < low[2] AND low[1] < low) and close=>close[1] and close=>open[1] and close[1]<=open[2] and high>high[1]) or (low[1]<low and low[1]<low[2] and high[1]<high and high[1]<high[2])
IF BearishFractal THEN
BearishFractalPoint = high[1]
ENDIF
IF BullishFractal THEN
BullishFractalPoint = low[1]
ENDIF
//High and Low
if high crosses over bbup then
selltag = 1
buytag = 0
endif
if low crosses under bbdn then
selltag = 0
buytag = 1
endif
buycond = buytag and close crosses over BearishFractalPoint and not BullishFractalPoint=0
sellcond = selltag and close crosses under BullishFractalPoint and not BearishFractalPoint=0
if buycond THEN
BUY 1 CONTRACT AT market
set stop loss min(50,max(10,(close-(BullishFractalPoint-5*pipsize))))
endif
if sellcond THEN
SELLSHORT 1 CONTRACT at market
set stop loss min(50,max(10,((BearishFractalPoint+5*pipsize)-close)))
ENDIF
//Exit strategy
if longonmarket and close>tradeprice then
if (high > bbup and close > (tradeprice + 10*pipsize)) then
sell at (tradeprice + 10) stop
endif
if (st1 - tradeprice) > 50*pipsize and close crosses under st1 then
sell at market
elsif (st1 - tradeprice) > 10*pipsize and (st1 - tradeprice) <= 50*pipsize then
sell at st1 stop
endif
endif
if shortonmarket and close<tradeprice then
if low < bbdn and close < (tradeprice - 10*pipsize) then
exitshort at (tradeprice - 10) stop
endif
if (tradeprice - st1) > 50*pipsize and close crosses over st1 then
exitshort at market
elsif (tradeprice - st1) > 10*pipsize and (tradeprice - st1) <= 50*pipsize then
exitshort at st1 stop
endif
endif
if low > BearishFractalPoint then
BearishFractalPoint = 0
endif
if high < BullishFractalPoint then
BullishFractalPoint = 0
endif