用全局变量来记录一下
globalvariable:cs=0,tt=0;
if 平多条件 and 持仓判断 then begin
tsell();
sleep(1000);//暂停1秒等成交
if tnumprofit(1)>=0 then cs:=0;
if tnumprofit(1)<0 and tt<>time then begin
cs:=cs+1;
tt:=time;//用记录time的方式来防止反复迭代
end
end
if 平空条件 and 持仓判断 then begin
tsellshort();
sleep(1000);//暂停1秒等成交
if tnumprofit(1)>=0 then cs:=0;
if tnumprofit(1)<0 and tt<>time then begin
cs:=cs+1;
tt:=time;
end
end
if time=closetime(0) then cs:=0;//收盘后重置全局变量
开平仓条件加入:cs<3;