Once Flag1 = 0
Once Flag2 = 0
once Flag3=0
ONce Flag4=0
once flag5=0
once flag6=0
IF Not OnMarket OR (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) THEN
Flag1 = 0
Flag2 = 0
Flag3=0
Flag4=0
flag5=0
flag6=0
ENDIF
if longonmarket and close >= positionprice +22 then
Flag2 = 1
endif
if longonmarket and close >= positionprice +15 then
Flag3 = 1
endif
if longonmarket and close <= positionprice -15 then
Flag4 = 1
endif
if longonmarket and flag3 and close <= positionprice -15 then
Flag5 = 1
endif
if longonmarket and flag4 and close >= positionprice +15 then
Flag6 = 1
endif
if shortonmarket and close <= positionprice -22 then
Flag2 = 1
endif
if shortonmarket and close <= positionprice -10 then
Flag3 = 1
endif
if shortonmarket and close >= positionprice +10 then
Flag4 = 1
endif
if shortonmarket and flag3 and close >= positionprice +10 then
Flag5 = 1
endif
if shortonmarket and flag4 and close <= positionprice -10 then
Flag6 = 1
endif
if LongOnMarket AND Flag2 then
sell countoflongshares contracts at positionprice stop
endif
if LongOnMarket AND Flag6 then
sell countoflongshares contracts at positionprice stop
endif
if LongOnMarket AND Flag5 then
sell countoflongshares contracts at positionprice limit
endif
if shortonmarket and Flag2 then
buy countofshortshares contracts at positionprice stop
endif
if shortonmarket and Flag5 then
buy countofshortshares contracts at positionprice limit
endif
if shortonmarket and Flag6 then
buy countofshortshares contracts at positionprice stop
endif