cc00002743:=holding;//这句放在信号稳定的地方
drawtextex(1,1,800,0,'虚拟持仓为:'+numtostr(cc00002743,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan00002743:=cc00002743-hold;
if xiadan00002743>0.5 then begin
cang:=min(xiadan00002743,abs(hold));
if hold<0 then begin
tsellshort(1,cang,mkt,0,0,'00002743'),allowrepeat;
debugfile('D:\00002743.txt',numtostr(hold,0)+' '+numtostr(cc00002743,0)+' 平空 %.0f',cang);
end
cang:=xiadan00002743+min(hold,0);
if cang>0 then begin
tbuy(1,cang,mkt,0,0,'00002743'),allowrepeat;
debugfile('D:\00002743.txt',numtostr(hold,0)+' '+numtostr(cc00002743,0)+' 开多 %.0f',cang);
end
end
if xiadan00002743<-0.5 then begin
cang:=min(abs(xiadan00002743),abs(hold));
if hold>0 then begin
tsell(1,cang,mkt,0,0,'00002743'),allowrepeat;
debugfile('D:\00002743.txt',numtostr(hold,0)+' '+numtostr(cc00002743,0)+' 平多 %.0f',cang);
end
cang:=abs(xiadan00002743)-max(hold,0);
if cang>0 then begin
tbuyshort(1,cang,mkt,0,0,'00002743'),allowrepeat;
debugfile('D:\00002743.txt',numtostr(hold,0)+' '+numtostr(cc00002743,0)+' 开空 %.0f',cang);
end
end
hold:=cc00002743;
//注意:不勾选软件自带追单功能,此模型自带
//固定1秒轮询
if TISREMAIN(0)=1 and TSUBMIT(0)>10 then TCANCEL(1,0);
//TISPRVREMAIN(N) and TISPRVREMAIN(0)
if not (TISPRVREMAIN(0) <>1) then exit;
cc:=holding;
if holding>0 and c<ref(c,1) then sell(1,1,MARKETR);
if holding<0 and c>ref(c,1) then sellshort(1,1,MARKETR);
if holding=0 and c>ref(c,1) then buy(1,1,MARKETR);
if holding=0 and c<ref(c,1) then buyshort(1,1,MARKETR);
if not(islastbar) or workmode<>1 then exit;
tm:=20;//撤单时间
ac:='00002743';//下单账户
wt:=tremainqty(0,ac,stklabel);
buyhold:=tbuyholdingex(ac,stklabel,1);
sellhold:=tsellholdingex(ac,stklabel,1);
if wt>0.5 and tsubmit(0)>tm then tcancelex(1,0,ac,stklabel);//如果用软件自带的撤单功能,这句删除。
if wt<0.5 then begin
kc1:=max(cc,0)-buyhold;
kc2:=abs(min(cc,0))-sellhold;
if kc1<-0.5 then tsell(1,abs(kc1),mkt,0,0,ac),allowrepeat;
if kc2<-0.5 then tsellshort(1,abs(kc2),mkt,0,0,ac),allowrepeat;
if sellhold<0.5 and kc1>0.5 then tbuy(1,kc1,mkt,0,0,ac),allowrepeat;
if buyhold<0.5 and kc2>0.5 then tbuyshort(1,kc2,mkt,0,0,ac),allowrepeat;
end