老师你好,下面是我的交易代码示例,其中,平多条件(PD)想表达的意思是:如果开空条件已成立,即使持有多单也马上平多开空(PK亦然),这时候系统就只有平仓,没有开仓,请问是什么原因?
dif:=ema(c,112)-ema(c,26);
dea:=ema(dif,9);
macd:=2*(dif-dea);
cpx:=ma(c,14);
entertime:=time<150000 and time>091600;
exittime:=time>=151400;
//交易条件
kd:=cross(c,cpx) and cpx>ref(cpx,1) and macd>0 and entertime;//开多条件
kk:=cross(cpx,c) and cpx<ref(cpx,1) and macd<0 and entertime;//开空条件
pd:=(macd<0 and cpx<ref(cpx,1)) or kk or exittime;//平多条件(如果开空条件成立,即使持有多单,马上平多开空)
pk:=(macd>0 and cpx>ref(cpx,1)) or kd or exittime;//平空条件(如果开多条件成立,即使持有空单,马上平空开多)
//交易系统
if holding<>0 then begin
sell(pd,0,limit,c),orderqueue;
sellshort(pk,0,limit,c),orderqueue;
end
if holding=0 then begin
buy(kd,1,limit,c),orderqueue;
buyshort(kk,1,limit,c),orderqueue;
end