//股指期货自动交易程序(净单交易)
//编制
//日期:
r1:=barslast(date<>ref(date,1));
//********************************
rr1:=stkindiex('if00','qq25.持仓',0,22,65,400);
rr2:=stkindiex('if00','qq25.持仓',0,22,80,400);
rr3:=stkindiex('if00','qq25.持仓',0,22,85,400);
rr4:=stkindiex('if00','qq25.持仓',0,22,90,400);
rr5:=stkindiex('if00','qq25.持仓',0,22,115,400);
rr6:=stkindiex('if00','qq25.持仓',0,22,125,400);
rr7:=stkindiex('if00','qq25.持仓',0,22,185,400);
r12:=rr1+rr2+rr3+rr4+rr5+rr6+rr7;
//***************第一遍***************
if holding=0 and r12>0 then buy(1,r12,limitr,c);
if holding=0 and r12<0 then buyshort(1,abs(r12),limitr,c);
if holding>0 and r12>0 and holding>r12 then sell(1,holding-r12,limitr,c);
if holding>0 and r12>0 and holding<r12 then buy(1,r12-holding,limitr,c);
if holding>0 and r12<0 then
begin
sell(1,holding,limitr,c);
buyshort(1,abs(r12),limitr,c);
end
if holding<0 and r12<0 and holding>r12 then buyshort(1,holding-r12,limitr,c);
if holding<0 and r12<0 and holding<r12 then sellshort(1,r12-holding,limitr,c);
if holding<0 and r12>0 then
begin
sellshort(1,holding,limitr,c);
buy(1,r12,limitr,c);
end
if r12=0 and holding>0 then sell(holding>0,holding,limitr,c);
if r12=0 and holding<0 then sellshort(holding<0,abs(holding),limitr,c);
//***************第2遍***************
if holding=0 and r12>0 then buy(1,r12,limitr,c);
if holding=0 and r12<0 then buyshort(1,abs(r12),limitr,c);
if holding>0 and r12>0 and holding>r12 then sell(1,holding-r12,limitr,c);
if holding>0 and r12>0 and holding<r12 then buy(1,r12-holding,limitr,c);
if holding>0 and r12<0 then
begin
sell(1,holding,limitr,c);
buyshort(1,abs(r12),limitr,c);
end
if holding<0 and r12<0 and holding>r12 then buyshort(1,holding-r12,limitr,c);
if holding<0 and r12<0 and holding<r12 then sellshort(1,r12-holding,limitr,c);
if holding<0 and r12>0 then
begin
sellshort(1,holding,limitr,c);
buy(1,r12,limitr,c);
end
if r12=0 and holding>0 then sell(holding>0,holding,limitr,c);
if r12=0 and holding<0 then sellshort(holding<0,abs(holding),limitr,c);
//***************第3遍***************
if holding=0 and r12>0 then buy(1,r12,limitr,c);
if holding=0 and r12<0 then buyshort(1,abs(r12),limitr,c);
if holding>0 and r12>0 and holding>r12 then sell(1,holding-r12,limitr,c);
if holding>0 and r12>0 and holding<r12 then buy(1,r12-holding,limitr,c);
if holding>0 and r12<0 then
begin
sell(1,holding,limitr,c);
buyshort(1,abs(r12),limitr,c);
end
if holding<0 and r12<0 and holding>r12 then buyshort(1,holding-r12,limitr,c);
if holding<0 and r12<0 and holding<r12 then sellshort(1,r12-holding,limitr,c);
if holding<0 and r12>0 then
begin
sellshort(1,holding,limitr,c);
buy(1,r12,limitr,c);
end
if r12=0 and holding>0 then sell(holding>0,holding,limitr,c);
if r12=0 and holding<0 then sellshort(holding<0,abs(holding),limitr,c);
//********************************
盈亏:asset-1000000,colorred,linethick1,noaxis;
日盈亏:asset-ref(asset,todaybar),noaxis,colorred,linethick0;
持仓:holding,linethick0;
注意:1.信号不要闪,否则会来回交易;
2.最好是用专业版tbuy,tsell.....;
3.如果是标准版引用了3个程序的holding,最好是执行3遍。
[此贴子已经被作者于2015/2/10 15:33:25编辑过]