if date <> date[1] then begin
tempHigh = 0;
tempLow = 99999;
tempOpen = opend(0);
if PositionProfit(1) < 0 then loseCount = -1;
if PositionProfit(1) >= 0 then loseCount = 0;
end;
mc = marketposition * currentcontracts;
if mc <> mc[1] then begin
tempHigh = 0;
tempLow = 99999;
end;
if mc <> mc[1] and PositionProfit(1) < 0 then loseCount = loseCount + 1;
if mc > 0 and high > tempHigh then tempHigh = high;
if mc < 0 and low < tempLow then tempLow = low;
if losecount < 2 and mc = 0 and time < 1329 then begin
buy ("b1") next bar at tempOpen + bs stop;
sell("s1") next bar at tempOpen - bs stop;
end;
if loseCount < 2 and mc > 0 and time < 1329 then begin
sell("s2") next bar at tempHigh - 10 stop;
end;
if loseCount < 2 and mc < 0 and time < 1329 then begin
buy ("b2") next bar at tempLow + 10 stop;
end;
if loseCount = 2 and mc > 0 and time < 1329 and tempHigh - 19 < entryprice(0) then begin
exitlong ("ex-b") next bar at tempHigh - 10 stop;
end;
if loseCount = 2 and mc > 0 and time < 1329 and tempHigh - 19 >= entryprice(0) then begin
sell("s3") next bar at tempHigh - 10 stop;
end;
if loseCount = 2 and mc < 0 and time < 1329 and tempLow + 19 > entryprice(0) then begin
exitshort ("ex-s") next bar at tempLow + 10 stop;
end;
if loseCount = 2 and mc < 0 and time < 1329 and tempLow + 19 <= entryprice(0) then begin
buy ("b3") next bar at tempLow + 10 stop;
end;
if time = 1329 and mc <> 0 then begin
exitlong ("b-end") next bar at market;
exitshort("s-end") next bar at market;
end;