后台程序化运行时平仓的同时不会开仓,代码如下:急
jx:MA(C,30);
a:=(time>010000 and time<=045500 ) or (time>130000 and time<=152500) or (time>173000 and time<=185500);
KK:=cross(jx,c) and a; //开空条件
PK:=cross(c,jx) ; //平空条件
KD:=cross(c,jx) and a; //开多条件
PD:=cross(jx,c) ; //平多条件
平空:tSELLSHORT(PK,0,lmt,close); //平空信号
开多:tBUY(KD AND tbuyHOLDING(0)=0 and tsellHOLDING(0)=0,10,lmt,close); //开多信号
平多:tSELL(PD,0,lmt,close); //平多信号
开空:tBUYSHORT(KK AND tsellHOLDING(0)=0 and tbuyHOLDING(0)=0,10,lmt,close); //开空信号
平多2:tSELL(tOPENPROFIT<-1000,0,mkt);
平空2:tSELLSHORT(tOPENPROFIT<-1000,0,mkt);
if (time>045800 and time<=050000) or (time>152800 and time<=160000) or (time>185800 and time<=190000) then begin
tsell(1,0,mkt);
tsellshort(1,0,mkt);
end
因为有持仓判断的,所以用顺序下单试试看
平空:tSELLSHORT(PK,0,lmt,close),orderqueue; //平空信号
开多:tBUY(KD AND tbuyHOLDING(0)=0 and tsellHOLDING(0)=0,10,lmt,close),orderqueue; //开多信号
平多:tSELL(PD,0,lmt,close),orderqueue; //平多信号
开空:tBUYSHORT(KK AND tsellHOLDING(0)=0 and tbuyHOLDING(0)=0,10,lmt,close),orderqueue; //开空信号
平多2:tSELL(tOPENPROFIT<-1000,0,mkt),orderqueue;
平空2:tSELLSHORT(tOPENPROFIT<-1000,0,mkt),orderqueue;
if (time>045800 and time<=050000) or (time>152800 and time<=160000) or (time>185800 and time<=190000) then begin
tsell(1,0,mkt),orderqueue;
tsellshort(1,0,mkt),orderqueue;
end
顺序下单是不是先平仓成交了才发开仓委托?还是平仓跟开仓同时发出?
先成交之后,再发后面的单子,避免没成交导致持仓判断出错,再加一个sleep1秒,这样有充足时间去接收成交回报了
这个公式绝对不能用逐k线模式,一定要用序列模式
平空:tSELLSHORT(PK,0,lmt,close),orderqueue; //平空信号
sleep(1000);
开多:tBUY(KD AND tbuyHOLDING(0)=0 and tsellHOLDING(0)=0,10,lmt,close),orderqueue; //开多信号
平多:tSELL(PD,0,lmt,close),orderqueue; //平多信号
开空:tBUYSHORT(KK AND tsellHOLDING(0)=0 and tbuyHOLDING(0)=0,10,lmt,close),orderqueue; //开空信号
平多2:tSELL(tOPENPROFIT<-1000,0,mkt),orderqueue;
平空2:tSELLSHORT(tOPENPROFIT<-1000,0,mkt),orderqueue;
if (time>045800 and time<=050000) or (time>152800 and time<=160000) or (time>185800 and time<=190000) then begin
tsell(1,0,mkt),orderqueue;
tsellshort(1,0,mkt),orderqueue;
end