//股指期货自动交易程序(净单交易)
//编制:
//日期:
//********************************
rr1:=stkindiex('RB00','SP32.持仓(76)',0,2,0,600),linethick0;
rr2:=stkindiex('RB00','SP32.持仓(79)',0,2,0,600),linethick0;
rr3:=stkindiex('RB00','SP32.持仓(82)',0,2,0,600),linethick0;
rr4:=stkindiex('RB00','SP32.持仓(85)',0,2,0,600),linethick0;
rr5:=stkindiex('RB00','SP32.持仓(88)',0,2,0,600),linethick0;
rr6:=stkindiex('RB00','SP32.持仓(91)',0,2,0,600),linethick0;
rr7:=stkindiex('RB00','SP32.持仓(94)',0,2,0,600),linethick0;
rr8:=stkindiex('RB00','SP32.持仓(97)',0,2,0,600),linethick0;
rr9:=stkindiex('RB00','SP32.持仓(100)',0,2,0,600),linethick0;
rr10:=stkindiex('RB00','SP32.持仓(103)',0,2,0,600),linethick0;
rr11:=stkindiex('RB00','SP32.持仓(106)',0,2,0,600),linethick0;
rr12:=stkindiex('RB00','SP32.持仓(109)',0,2,0,600),linethick0;
r12:=rr1+rr2+rr3+rr4+rr5+rr6+rr7+rr8+rr9+rr10+rr11+rr12;
//******************************
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,abs(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;
variable:hc=0;
回撤:hhv(盈亏,3000)-盈亏,linethick0,coloryellow;
if 回撤>hc then hc:=回撤;
最大回撤:hc,linethick0,coloryellow;