if marketposition=0 and kb<1 and value1 > 500 and value2 <-500 then begin buy("buy")
next bar at market;
end;
if marketposition=0 and ks<1 and value1 <-500 and value2 > 500 then begin sellshort("sell")
next bar at market;
end;
mkp=marketposition;
if marketposition>0 then KB=1;
if marketposition<0 then KS=1;
if marketposition>0 then sell next bar at entryprice-30 stop;
if marketposition>0 then sell next bar at entryprice+30 LIMIT;
if marketposition<0 then buytocover next bar at entryprice-30 LIMiT;
if marketposition<0 then buytocover next bar at entryprice+30 stop;
if time>=1326 then sell("exitbuy1") this bar;
if time>=1326 then buytocover("exitshort1") this bar;