N  = 100
sl = 100 * pipsize
tp = 400 * pipsize
OK = time >= 100000 AND time <= 170000
if OK and not onmarket and close crosses over average[N,0](close) then
   buy at market
   exitprice = close - sl
endif
if OK and not onmarket and close crosses under average[N,0](close) then
   sellshort at market
   exitprice = close + sl
endif
IF OK then
   set target profit tp
ELSE
   set target profit 0
endif
set stop   loss   0
if OK then
   if longonmarket then
      if close > exitprice then
         sell at exitprice STOP
      elsif close < exitprice then
         sell at exitprice LIMIT
      endif
   elsif shortonmarket then
      if close > exitprice then
         exitshort at exitprice LIMIT
      elsif close < exitprice then
         exitshort at exitprice STOP
      endif
   endif
endif
//graph positionprice * positionperf / pipsize as "tempGain"
graph OK > 0
graphonprice tradeprice                      as "Entry price"
graphonprice exitprice coloured(255,0,0,255) as "Stop Loss"