//********************************
if AA then
begin
if tisremain(2)>0.5 then tcancel(1,2);
if tisremain(3)>0.5 then tcancel(1,3);
end
if BB then
begin
if tisremain(4)>0.5 then tcancel(1,4);
if tisremain(1)>0.5 then tcancel(1,1);
end
//********************************
if tholding2<=0 and AA then
begin
tsellshort(1,0,lmt,C-nn2),NOATTACK;
tbuy(1,tn,lmt,C-nn2),NOATTACK;
end
if tholding2>=0 and BB then
begin
tsell(1,0,lmt,C+nn2),NOATTACK;
tbuyshort(1,tn,C+nn2),NOATTACK;
end
//****************************
if tholding2<0 and CC then
begin
if tisremain(4)>0.5 then tcancel(1,4);
if tisremain(1)>0.5 then tcancel(1,1);
tsellshort(1,0,mkt);
tbuy(1,tn,mkt);
end
if tholding2>0 and DD then
begin
if tisremain(2)>0.5 then tcancel(1,2);
if tisremain(3)>0.5 then tcancel(1,3);
tsell(1,0,mkt);
tbuyshort(1,tn,mkt);
end
//*****************************