Globalvariable:hold=drawnull;
H1:=REF(HHV(H,20),1);
L1:=REF(LLV(L,20),1);
H2:=REF(HHV(H,10),1);
L2:=REF(LLV(L,10),1);
ENTRYLONGCOND:=H>H1 ;
ENTRYSHORTCOND:=L<L1 ;
IF (HOLDING = 0) AND ENTRYLONGCOND THEN
BEGIN
BUY(1,5,LIMITR,MAX(OPEN,H1),1),orderqueue,IGNORECHECKPRICE;
END
IF (HOLDING = 0) AND ENTRYSHORTCOND THEN
BEGIN
BUYSHORT(1,5,LIMITR,MIN(OPEN,L1),1),orderqueue,IGNORECHECKPRICE;
END
IF (HOLDING > 0) AND (ENTERBARS > 0) and LOW<=L2 THEN
BEGIN
SELL(1,HOLDING,LIMITR,MIN(OPEN,L2),1),orderqueue,IGNORECHECKPRICE;
END
IF (HOLDING < 0) AND (ENTERBARS > 0) and HIGH>=H2 THEN
BEGIN
SELLSHORT(1,HOLDING,LIMITR,MAX(OPEN,H2),1),orderqueue,IGNORECHECKPRICE;
END
cc807385:=holding;
drawtextex(1,1,800,0,\'虚拟持仓为:\'+numtostr(cc807385,0));//在图表上输入虚拟持仓以便监控
if not(islastbar) or workmode<>1 then exit;
xiadan807385:=cc807385-hold;
cang:=xiadan807385+min(hold,0);
if cang>0 then begin
tbuy(1,cang,lmt,MAX(OPEN,H1),0,\'807385\');
debugfile(\'D:\\807385.txt\',numtostr(hold,0)+\' \'+numtostr(cc807385,0)+\' 开多 %.0f\',cang);
end
cang:=abs(xiadan807385)-max(hold,0);
if cang>0 then begin
tbuyshort(1,cang,lmt,MIN(OPEN,L1),0,\'807385\');
debugfile(\'D:\\807385.txt\',numtostr(hold,0)+\' \'+numtostr(cc807385,0)+\' 开空 %.0f\',cang);
end
if xiadan807385<-0.5 then begin
cang:=min(abs(xiadan807385),abs(hold));
if hold>0 then begin
tsell(1,cang,lmt,MIN(OPEN,L2),0,\'807385\');
debugfile(\'D:\\807385.txt\',numtostr(hold,0)+\' \'+numtostr(cc807385,0)+\' 平多 %.0f\',cang);
end
end
if xiadan807385>0.5 then begin
cang:=min(xiadan807385,abs(hold));
if hold<0 then begin
tsellshort(1,cang,lmt,MAX(OPEN,H2),0,\'807385\');
debugfile(\'D:\\807385.txt\',numtostr(hold,0)+\' \'+numtostr(cc807385,0)+\' 平空 %.0f\',cang);
end
end
hold:=cc807385;
cc:=holding;
if not(islastbar) or workmode<>1 then exit;
tm:=1;//撤单时间
ac:=\'807385\';//下单账户
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