[原创]主力跟踪交易(大部分品种都可以) [金字塔]
- 咨询内容:
说明:这个是用RB作为代表的,只要是1——12合约的品种,只要直接用代码替换RB即可,如“CU”替换“RB”,其他的都不用动的。
具体后台交易的时候,最好监控相对应的品种指数,如这里监控RB指数。
input:手数(1,1,1000);
//螺纹合约信息
//rb01
rb01close:="rb01$close";
rb01OPENINT:="rb01$OPENINT";
//rb02
rb02close:="rb02$close";
rb02OPENINT:="rb02$OPENINT";
//rb03
rb03close:="rb03$close";
rb03OPENINT:="rb03$OPENINT";
//rb04
rb04close:="rb04$close";
rb04OPENINT:="rb04$OPENINT";
//rb05
rb05close:="rb05$close";
rb05OPENINT:="rb05$OPENINT";
//rb06
rb06close:="rb06$close";
rb06OPENINT:="rb06$OPENINT";
//rb07
rb07close:="rb07$close";
rb07OPENINT:="rb07$OPENINT";
//rb08
rb08close:="rb08$close";
rb08OPENINT:="rb08$OPENINT";
//rb09
rb09close:="rb09$close";
rb09OPENINT:="rb09$OPENINT";
//rb10
rb10close:="rb10$close";
rb10OPENINT:="rb10$OPENINT";
//rb11
rb11close:="rb11$close";
rb11OPENINT:="rb11$OPENINT";
//rb12
rb12close:="rb12$close";
rb12OPENINT:="rb12$OPENINT";
//判断主力合约
maxOPENINT:=
MAX(rb01OPENINT ,
MAX(rb02OPENINT ,
MAX(rb03OPENINT ,
MAX(rb04OPENINT ,
MAX(rb05OPENINT ,
MAX(rb06OPENINT ,
MAX(rb07OPENINT ,
MAX(rb08OPENINT ,
MAX(rb09OPENINT ,
MAX(rb10OPENINT ,
MAX(rb11OPENINT ,
rb12OPENINT) ) ) ) ) ) ) ) ) ) );
yf:=if(rb01OPENINT=maxOPENINT,1,
if(rb02OPENINT=maxOPENINT,2,
if(rb03OPENINT=maxOPENINT,3,
if(rb04OPENINT=maxOPENINT,4,
if(rb05OPENINT=maxOPENINT,5,
if(rb06OPENINT=maxOPENINT,6,
if(rb07OPENINT=maxOPENINT,7,
if(rb08OPENINT=maxOPENINT,8,
if(rb09OPENINT=maxOPENINT,9,
if(rb10OPENINT=maxOPENINT,10,
if(rb11OPENINT=maxOPENINT,11,
12))))))))))),LINETHICK0;
//主力合约代码字符串
if yf<10 then
begin
dm:=NUMTOSTR(yf,0);
hy:=STRCAT('0',dm);
end
else
hy:=NUMTOSTR(yf,0);
zlhy:=STRCAT('RB',hy);
DRAWTEXTEX(close>0,0,2,0,zlhy);
//买卖价格
mxclose:=if(rb01OPENINT=maxOPENINT,rb01close,
if(rb02OPENINT=maxOPENINT,rb02close,
if(rb03OPENINT=maxOPENINT,rb03close,
if(rb04OPENINT=maxOPENINT,rb04close,
if(rb05OPENINT=maxOPENINT,rb05close,
if(rb06OPENINT=maxOPENINT,rb06close,
if(rb07OPENINT=maxOPENINT,rb07close,
if(rb08OPENINT=maxOPENINT,rb08close,
if(rb09OPENINT=maxOPENINT,rb09close,
if(rb10OPENINT=maxOPENINT,rb10close,
if(rb11OPENINT=maxOPENINT,rb11close,
rb12close))))))))))),LINETHICK0;
//策略
dt:=cross(ma(close,10),ma(close,30));
kt:=cross(ma(close,30),ma(close,10));
//----------------交易指令开始---------------//
//没有持有该品种时——买卖指令
if TSELLHOLDINGEX(账户,zlhy,1)=0 and TBUYHOLDINGEX(账户,zlhy,1)=0 then
begin
TBUY(dt,手数,lmt,(mxclose+MINDIFF*10),账户,zlhy);
TBUYSHORT(kt,手数,lmt,(mxclose+MINDIFF*10),账户,zlhy);
end
//持有该品种多单时——买卖指令
if TSELLHOLDINGEX(账户,zlhy,1)=0 and TBUYHOLDINGEX(账户,zlhy,1)>0 then
begin
TSELL(kt,TBUYHOLDINGEX(账户,zlhy,1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
if TBUYHOLDINGEX(账户,zlhy,1)<手数 then TBUY(dt,(手数-TBUYHOLDINGEX(账户,zlhy,1)),lmt,(mxclose+MINDIFF*10),账户,zlhy);
end
//持有该品种空单时——买卖指令
if TSELLHOLDINGEX(账户,zlhy,1)>0 and TBUYHOLDINGEX(账户,zlhy,1)=0 then
begin
TSELLSHORT(dt,TBUYHOLDINGEX(账户,zlhy,1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
if TSELLHOLDINGEX(账户,zlhy,1)<手数 then TBUYSHORT(kt,(手数-TBUYHOLDINGEX(账户,zlhy,1)),lmt,(mxclose-MINDIFF*10),账户,zlhy);
end
//多空单子同时持有——买卖指令
if TSELLHOLDINGEX(账户,zlhy,1)>0 and TBUYHOLDINGEX(账户,zlhy,1)>0 then
begin
TSELL(kt,TBUYHOLDINGEX(账户,zlhy,1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
TSELLSHORT(dt,TSELLHOLDINGEX(账户,zlhy,1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
if TBUYHOLDINGEX(账户,zlhy,1)<手数 then TBUY(dt,(手数-TBUYHOLDINGEX(账户,zlhy,1)),lmt,(mxclose+MINDIFF*10),账户,zlhy);
if TSELLHOLDINGEX(账户,zlhy,1)<手数 then TBUYSHORT(kt,(手数-TSELLHOLDINGEX(账户,zlhy,1)),lmt,(mxclose-MINDIFF*10),账户,zlhy);
end [此贴子已经被作者于2010-10-14 14:40:33编辑过] - 金字塔客服:
不错 这个加精~~~感谢明心
- 用户回复:
交易指令部分好像还有点问题,稍后补充一下。不好意思。刚写好,就发上来了,还没有来得及完善呢。呵呵
- 网友回复:
感谢共享,支持加精
- 网友回复:
从交易指令开始的部分换成以下内容,就可以在图表上显示了。
buy(dt);sell(kt);buyshort(kt);sellshort(dt);
图表交易中好像不能指定品种交易的把。
[此贴子已经被作者于2010-10-14 23:57:58编辑过]
- 上一篇:[求助]
- 下一篇:没有了!
相关文章
-
没有相关内容