variable:n=0;
if holding>0 and 平多条件 then begin
sell.......;
if numprofit(1)>0 then n:=0;
if numprofit(1)<0 then n:=n+1;
end
if holding<0 and 平空条件 then begin
sellshort.......;
if numprofit(1)>0 then n:=0;
if numprofit(1)<0 then n:=n+1;
end
if n=3 and holding>0 then sell(1,holding/2,market);
if n=3 and holding<0 then sellshort(1,holding/2,market);