欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → [原创]主力跟踪交易(大部分品种都可以)

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有9438人关注过本帖树形打印复制链接

主题:[原创]主力跟踪交易(大部分品种都可以)

帅哥哟,离线,有人找我吗?
明心
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:274 积分:841 威望:0 精华:10 注册:2010/7/12 15:25:05
[原创]主力跟踪交易(大部分品种都可以)  发帖心情 Post By:2010/10/14 14:36:14    Post IP:218.91.209.155[只看该作者]

说明:这个是用RB作为代表的,只要是1——12合约的品种,只要直接用代码替换RB即可,如“CU”替换“RB”,其他的都不用动的。

具体后台交易的时候,最好监控相对应的品种指数,如这里监控RB指数。

 

input:账户(0,0,999999999999);
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编辑过]

[本帖被加为精华]
版主评定:好评,获得10个金币奖励好评,获得10个金币奖励
(理由:好文章)
 回到顶部
帅哥哟,离线,有人找我吗?
董小球
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信 大哥
等级:超级版主 帖子:2837 积分:13237 威望:0 精华:2 注册:2010/7/14 17:31:54
  发帖心情 Post By:2010/10/14 14:44:23    Post IP:58.246.57.26[只看该作者]

不错 这个加精~~~感谢明心


金字塔—专业程序化交易量化投资平台

客户服务部

-----------------------------------------------------------

欢迎您参加我公司的技术培训,具体培训需求请发邮件到

service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
明心
  3楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:274 积分:841 威望:0 精华:10 注册:2010/7/12 15:25:05
  发帖心情 Post By:2010/10/14 14:46:59    Post IP:218.91.209.155[只看该作者]

交易指令部分好像还有点问题,稍后补充一下。不好意思。刚写好,就发上来了,还没有来得及完善呢。呵呵

 回到顶部
帅哥哟,离线,有人找我吗?
fly
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:管理员 帖子:5082 积分:17642 威望:0 精华:6 注册:2010/7/15 9:05:58
  发帖心情 Post By:2010/10/14 15:05:57    Post IP:58.246.57.26[只看该作者]

感谢共享,支持加精


金字塔—专业程序化交易量化投资平台

客户服务部

-----------------------------------------------------------

欢迎您参加我公司的技术培训,具体培训需求请发邮件到

service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
明心
  5楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:274 积分:841 威望:0 精华:10 注册:2010/7/12 15:25:05
  发帖心情 Post By:2010/10/14 23:53:54    Post IP:121.232.100.90[只看该作者]

从交易指令开始的部分换成以下内容,就可以在图表上显示了。

buy(dt);sell(kt);buyshort(kt);sellshort(dt);

 

图表交易中好像不能指定品种交易的把。

[此贴子已经被作者于2010-10-14 23:57:58编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
明心
  6楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:274 积分:841 威望:0 精华:10 注册:2010/7/12 15:25:05
  发帖心情 Post By:2010/10/15 11:26:14    Post IP:218.91.209.155[只看该作者]

交易指令补充如下(跟在交易指令模块后面即可):

//-----------换合约开始-----------------//
//rb01
if rb01OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb01',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb01',1),lmt,(mxclose-MINDIFF*10),账户,'rb01');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb01',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb01',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb01',1),lmt,(mxclose+MINDIFF*10),账户,'rb01');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb01',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end


//rb02
if rb02OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb02',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb02',1),lmt,(mxclose-MINDIFF*10),账户,'rb02');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb02',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb02',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb02',1),lmt,(mxclose+MINDIFF*10),账户,'rb02');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb02',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   
//rb03
if rb03OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb03',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb03',1),lmt,(mxclose-MINDIFF*10),账户,'rb03');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb03',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb03',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb03',1),lmt,(mxclose+MINDIFF*10),账户,'rb03');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb03',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end

//rb04
if rb04OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb04',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb04',1),lmt,(mxclose-MINDIFF*10),账户,'rb04');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb04',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb04',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb04',1),lmt,(mxclose+MINDIFF*10),账户,'rb04');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb04',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   
   
 //rb05
if rb05OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb05',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb05',1),lmt,(mxclose-MINDIFF*10),账户,'rb05');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb05',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb05',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb05',1),lmt,(mxclose+MINDIFF*10),账户,'rb05');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb05',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
    
》》》》由于字数限制,下面部分请看下帖。 


 回到顶部
帅哥哟,离线,有人找我吗?
明心
  7楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:论坛游民 帖子:274 积分:841 威望:0 精华:10 注册:2010/7/12 15:25:05
  发帖心情 Post By:2010/10/15 11:26:27    Post IP:218.91.209.155[只看该作者]

//rb06
if rb06OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb06',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb06',1),lmt,(mxclose-MINDIFF*10),账户,'rb06');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb06',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb06',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb06',1),lmt,(mxclose+MINDIFF*10),账户,'rb06');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb06',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   

 //rb07
if rb07OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb07',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb07',1),lmt,(mxclose-MINDIFF*10),账户,'rb07');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb07',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb07',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb07',1),lmt,(mxclose+MINDIFF*10),账户,'rb07');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb07',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   
 //rb08
if rb08OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb08',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb08',1),lmt,(mxclose-MINDIFF*10),账户,'rb08');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb08',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb08',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb08',1),lmt,(mxclose+MINDIFF*10),账户,'rb08');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb08',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   
   
 //rb09
if rb09OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb09',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb09',1),lmt,(mxclose-MINDIFF*10),账户,'rb09');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb09',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb09',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb09',1),lmt,(mxclose+MINDIFF*10),账户,'rb09');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb09',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   
   
 //rb10
if rb10OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb10',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb10',1),lmt,(mxclose-MINDIFF*10),账户,'rb10');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb10',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb10',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb10',1),lmt,(mxclose+MINDIFF*10),账户,'rb10');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb10',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   
   
 //rb11
if rb11OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb11',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb11',1),lmt,(mxclose-MINDIFF*10),账户,'rb11');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb11',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb11',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb11',1),lmt,(mxclose+MINDIFF*10),账户,'rb11');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb11',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end
   
   
//rb12
if rb12OPENINT<>maxOPENINT then
   begin
        if TBUYHOLDINGEX(账户,'rb12',1)>0 then
           begin
                TSELL(close>0,TBUYHOLDINGEX(账户,'rb12',1),lmt,(mxclose-MINDIFF*10),账户,'rb12');
                TBUY(close>0,TBUYHOLDINGEX(账户,'rb12',1),lmt,(mxclose+MINDIFF*10),账户,zlhy);
           end
          
         if TSELLHOLDINGEX(账户,'rb12',1)>0 then
           begin
                TSELLshort(close>0,TSELLHOLDINGEX(账户,'rb12',1),lmt,(mxclose+MINDIFF*10),账户,'rb12');
                TBUYshort(close>0,TSELLHOLDINGEX(账户,'rb12',1),lmt,(mxclose-MINDIFF*10),账户,zlhy);
           end
    end


 回到顶部
帅哥哟,离线,有人找我吗?
QJ
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:66 积分:431 威望:0 精华:0 注册:2011/6/9 3:27:21
  发帖心情 Post By:2011/6/28 3:39:33    Post IP:123.119.101.228[只看该作者]

顶起


 回到顶部