可以分开写
sell(cond1,1,market);//平多
buyshort(cond2,1,market)//开空
sellshort(cond3,1,market);//平空
buy(cond4,1,market);//开多
但是这样并没有成为分组啊。 这样只要一符合平仓条件就立马平掉了。
没有实现分组的功能
比如分组为A和B
那么通过A开仓的,就只能A来平仓
A: buy(1,1,thisclose);
A: SELL(1,1,thisclose);
B: buy(1,1,thisclose);
B: SELL(1,1,thisclose);
第四行语句,哪怕条件符合,也不会把第一行开的仓位平掉的
使用全局变量定义一个flag标志位。进行区分。
VARIABLE:a=0,b=0;
if cond1 and a=0 then begin
buy(1,1,MARKET);
a:=1;
end
if cond2 and a=1 then begin
buy(1,1,MARKET);
a:=0;
end
if cond1 and b=0 then begin
buy(1,1,MARKET);
b:=1;
end
if cond2 and b=1 then begin
buy(1,1,MARKET);
b:=0;
end