value1=Close of data2;
if date <> date[1] then begin
KB=0;
KS=0;
mkp=0;
end;
if marketposition=0 and value1 > 500 then begin buy("buy")
next bar at market;
if marketposition=0 and value1<-500 then begin sellshort("sell")
next bar at market;
if marketposition>0 then KB=1;
if marketposition<0 then KS=1;
end;
mkp=marketposition;
if mkp[1] <> 1 and mkp=1 then kb=kb+1;
if mkp[1] <> -1 and mkp=-1 then ks=ks+1;
if marketposition>0 then sell next bar at entryprice-20 stop;
if marketposition>0 then sell next bar at entryprice+20 stop;
if marketposition>0 then buytocover next bar at entryprice-20 stop;
if marketposition>0 then buytocover next bar at entryprice+20 stop;
if time>=1326 then sell("exitbuy1") this bar;
if time>=1326 then buytocover("exitshort1") this bar;
if marketposition=0 and value1 > 500 then begin buy("buy")
next bar at market;
if marketposition=0 and value1<-500 then begin sellshort("sell")
next bar at market;
if marketposition>0 then KB=1;
if marketposition<0 then KS=1;