//说明:此策略为后台自动移仓策略
//使用说明:后台加载此策略,时间可设置为每10分钟检测一次,当持有的仓位不是主力合约时自动换到主力合约。
variable:AccountID='800000';//指定交易账户
M1:=MONTH(); HY1:='IF' + If(M1>9,M1,'0'+numtostr(M1,0));//当前月合约 HY2:='IF' + If(M1+1>9,M1+1,'0'+numtostr(M1+1,0));//下月合约 HY0:='IF00';
VHY0:CALLSTOCK(HY0,VTVOL,6,0),linethick0; VHY1:CALLSTOCK(HY1,VTVOL,6,0),linethick0; VHY2:CALLSTOCK(HY2,VTVOL,6,0),linethick0;
if VHY1=VHY0 then CurMonth:=Month(); if VHY2=VHY0 then CurMonth:=Month()+1; 主力:CurMonth,linethick0; if CurMonth>M1 then begin PreBuyHold:tbuyholdingex(AccountID,HY1,1),linethick0; //上月买入持仓 PreSellHold:tsellholdingex(AccountID,HY1,1),linethick0; //上月卖出持仓 if PreBuyHold>0 then begin//多单移仓 tSell(1,PreBuyHold,mkt,0,0,AccountID,HY1); tbuy(1,PreBuyHold,mkt,0,0,AccountID,HY2); end if PreSellHold>0 then begin//空单移仓 tSellShort(1,PreSellHold,mkt,0,0,AccountID,HY1); tbuyShort(1,PreSellHold,mkt,0,0,AccountID,HY2); end end
//这个策略专门针对股指来实现的,如果需要用于商品,应做些修改
|