//不平日内开仓,且控制日内开仓不超过10手。
r1:=todaybar-1;
tn:=1;//每次交易手数,要和主程序的一致
r4:=stkindiex('if00','htcs.持仓(1)',0,22,20,0),linethick0;//
//r5:=stkindiex('iF00','qq24.持仓(1)',0,21,3,0),linethick0;//
r6:=r4,linethick0;
rr:=r6-ref(r6,1),noaxis;
k1:=tbuyholding(0)=0;
k2:=tsellholding(0)=0;
r10:=tbuyholding(1);
r11:=abs(tsellholding(1));
//********************
GLOBALVARIABLE:a1=0;
if r1=0 then
begin
a1:=0;
end
nn1:=10;
//********************
if rr>0 and k2 then
begin
if r11>=rr then
begin
tsellshort(1,rr,lmt,c);
end
if r11<rr and r11>0 then
begin
tsellshort(1,r11,lmt,c);
tbuy(1,rr-r11,lmt,c);
a1:=a1+rr-r11;
end
if r11=0 then
begin
tbuy(1,rr,lmt,c);
a1:=a1+rr;
end
end
if rr<0 and k1 then
begin
if r10>=abs(rr) then
begin
tsell(1,abs(rr),lmt,c);
end
if r10<abs(rr) and r10>0 then
begin
tsell(1,r10,lmt,c);
tbuyshort(1,abs(rr)-r10,lmt,c);
a1:=a1+abs(rr)-r10;
end
if r10=0 then
begin
tbuyshort(1,abs(rr),lmt,c);
a1:=a1+abs(rr);
end
end
//************************
if rr>0 and not(k2) and a1<=nn1-rr then
begin
tbuy(1,rr,lmt,c);
a1:=a1+rr;
end
if rr>0 and not(k2) and a1>nn1-rr and a1<nn1 then
begin
r13:=nn1-a1;
tbuy(1,r13,lmt,c);
a1:=nn1;
end
//---------------------------
if rr<0 and not(k1) and a1<=nn1-abs(rr) then
begin
tbuyshort(1,abs(rr),lmt,c);
a1:=a1+abs(rr);
end
if rr<0 and not(k1) and a1>nn1-abs(rr) and a1<nn1 then
begin
r14:=nn1-a1;
tbuyshort(1,r14,lmt,c);
a1:=nn1;
end
//-----------a1=nn1 时第3种处理方法-------------
if a1=nn1 and rr=0 and r10<>r11 then
begin
if r10>r11 then
begin
tsell(1,r10-r11,lmt,c);
end
if r10<r11 then
begin
tsellshort(1,r11-r10,lmt,c);
end
end
//第二天同步,
r15:=tholding;
if rr=0 and k1 and k2 and r6<>r15 then
begin
if r15>r6 then
begin
tsell(1,r15-r6,lmt,c);
end
if r15<r6 then
begin
tsellshort(1,r6-r15,lmt,c);
end
end
//---------------------------
DEBUGOUT('日交易次数IF.....%.0f',a1);
DEBUGOUT('理论持仓IF.......%.0f',r6);
DEBUGOUT('实际持仓IF.......%.0f',tholding);