要求只开仓一次的,用全局变量来限定,比如假定策略A的开仓条件为c>o:
variable:bj=0;
if bj=0 and c>o and holding=0 then begin
buy(1,1,market);
bj:=1;
end
下面这一句写在代码的最后
if time=closetime(0) then bj:=0;
variable:bj1=0,bj2=0;
variable:p1=0,p2=0,p3=0,p4=0,p5=0;
if 条件A and bj1=0 then begin
buy.....;
bj1:=1;
end
if 条件B and bj2=0 then begin
buy.......;
bj2:=1;
end
if bj1=1 and 平仓A1 and p1=0 then begin
sell....;
p1:=1;
end
if bj1=1 and 平仓A2 and p2=0 then begin
sell....;
p2:=1;
end
if bj2=1 and 平仓b1 and p3=0 then begin
sell....;
p3:=1;
end
if bj2=1 and 平仓b2 and p4=0 then begin
sell....;
p4:=1;
end
if bj2=1 and 平仓b3 and p5=0 then begin
sell....;
p5:=1;
end
if time=closetime(0) then begin
bj1:=0;
bj2:=0;
p1:=0;p2:=0;p3:=0;p4:=0;p5:=0;
end