设为首页收藏本站

 找回密码
 注册
查看: 2476|回复: 1
打印 上一主题 下一主题

主力换月的代码 [复制链接]

Rank: 4

精华
0
UID
38084
积分
323
帖子
71
主题
26
阅读权限
50
注册时间
2011-5-6
最后登录
2022-1-26
跳转到指定楼层
1#
发表于 2012-7-19 00:56:20 |只看该作者 |倒序浏览
版主:我根据推迟开仓代码写了一个主力换月的代码,看看有没有问题 这个代码能不能解决满仓先平仓后开仓和主力换月呢?帮我看看?
Params
       Numeric Lots(1);        //开仓单手
       Numeric FastLength(5);
       Numeric SlowLength(20);
       Numeric DelayTicks(5);
Vars
        NumericSeries AvgValue1;
        NumericSeries AvgValue2;
        Numeric LastBarTime;
        Numeric TickCounter;
Begin
       AvgValue1 = AverageFC(Close,FastLength);
           AvgValue2 = AverageFC(Close,SlowLength);
       LastBarTime = GetGlobalVar(0);
           TickCounter = GetGlobalVar(1);
       If(BarStatus==2 && LastBarTime != Time)
        {
                           LastBarTime = Time;
               TickCounter = 0;
        }
                If(AvgValue1[1] > AvgValue2[1])//Data0是连续888,Data1是近期主力,Data2是换月主力
        {
               If(Data0.Vol==Data1.Vol&&Data1.MarketPosition==0 || BarStatus!=2)//如果Data1是主力没有仓位开仓
                           {
                              Data1.Buy(Lots,Data1.Open);
                           }else if(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0 || BarStatus!=2)//如果Data2是主力没有仓位开仓
                           {
                                          Data2.Buy(Lots,Data2.Open);
               }Else
                           {
                                  If(Data0.Vol==Data1.Vol&&Data1.MarketPosition!=1)//如果Data1是主力没有换月Data1交易
                              {
                              Data1.BuyToCover(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data1.Buy(Lots,Data1.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0)//如果Data1和Data2换月进行换仓交易
                                 {
                               Data1.BuyToCover(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                Data2.Buy(Lots,Data2.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition!=1)//如果Data2是主力已换月Data2交易
                                 {
                       Data2.BuyToCover(Lots,Data2.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                        Data2.Buy(Lots,Data2.Open);
                       }
                                        }
              }
          }Else If( AvgValue1[1] < AvgValue2[1])//Data0是连续888,Data1是近期主力,Data2是换月主力
      {
                           If(Data0.Vol==Data1.Vol&&Data1.MarketPosition==0 || BarStatus!=2)//如果Data1是主力没有仓位开仓
                           {
                                                          Data1.SellShort(Lots,Data1.Open);
                           }else if(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0 || BarStatus!=2)//如果Data2是主力没有仓位开仓
                           {
                                          Data2.SellShort(Lots,Data2.Open);
               }Else
                           {
                                  If(Data0.Vol==Data1.Vol&&Data1.MarketPosition!=-1)//如果Data1是主力没有换月Data1交易
                              {
                              Data1.Sell(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data1.SellShort(Lots,Data1.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0)//如果Data1和Data2换月进行换仓交易
                                 {
                               Data1.Sell(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data1.SellShort(Lots,Data1.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition!=1)//如果Data2是主力已换月Data2交易
                                 {
                               Data1.Sell(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data1.SellShort(Lots,Data1.Open);
                       }
                                 }
              }
        }      
      SetGlobalVar(0,LastBarTime);        
         SetGlobalVar(1,TickCounter);
End

Rank: 4

精华
0
UID
38084
积分
323
帖子
71
主题
26
阅读权限
50
注册时间
2011-5-6
最后登录
2022-1-26
2#
发表于 2012-7-19 01:02:51 |只看该作者
修正一下
Params
       Numeric Lots(1);        //开仓单手
       Numeric FastLength(5);
       Numeric SlowLength(20);
       Numeric DelayTicks(5);
Vars
        NumericSeries AvgValue1;
        NumericSeries AvgValue2;
        Numeric LastBarTime;
        Numeric TickCounter;
Begin
       AvgValue1 = AverageFC(Close,FastLength);
           AvgValue2 = AverageFC(Close,SlowLength);
       LastBarTime = GetGlobalVar(0);
           TickCounter = GetGlobalVar(1);
       If(BarStatus==2 && LastBarTime != Time)
        {
                           LastBarTime = Time;
               TickCounter = 0;
        }
                If(AvgValue1[1] > AvgValue2[1])//Data0是连续888,Data1是近期主力,Data2是换月主力
        {
               If(Data0.Vol==Data1.Vol&&Data1.MarketPosition==0 || BarStatus!=2)//如果Data1是主力没有仓位开仓
                           {
                              Data1.Buy(Lots,Data1.Open);
                           }else if(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0 || BarStatus!=2)//如果Data2是主力没有仓位开仓
                           {
                                          Data2.Buy(Lots,Data2.Open);
               }Else
                           {
                                  If(Data0.Vol==Data1.Vol&&Data1.MarketPosition!=1)//如果Data1是主力没有换月Data1交易
                              {
                              Data1.BuyToCover(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data1.Buy(Lots,Data1.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0)//如果Data1和Data2换月进行换仓交易
                                 {
                               Data1.BuyToCover(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                Data2.Buy(Lots,Data2.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition!=1)//如果Data2是主力已换月Data2交易
                                 {
                       Data2.BuyToCover(Lots,Data2.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                        Data2.Buy(Lots,Data2.Open);
                       }
                                        }
              }
          }Else If( AvgValue1[1] < AvgValue2[1])//Data0是连续888,Data1是近期主力,Data2是换月主力
      {
                           If(Data0.Vol==Data1.Vol&&Data1.MarketPosition==0 || BarStatus!=2)//如果Data1是主力没有仓位开仓
                           {
                                                          Data1.SellShort(Lots,Data1.Open);
                           }else if(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0 || BarStatus!=2)//如果Data2是主力没有仓位开仓
                           {
                                          Data2.SellShort(Lots,Data2.Open);
               }Else
                           {
                                  If(Data0.Vol==Data1.Vol&&Data1.MarketPosition!=-1)//如果Data1是主力没有换月Data1交易
                              {
                              Data1.Sell(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data1.SellShort(Lots,Data1.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition==0)//如果Data1和Data2换月进行换仓交易
                                 {
                               Data1.Sell(Lots,Data1.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data2.SellShort(Lots,Data2.Open);
                       }
                                 }Else If(Data0.Vol==Data2.Vol&&Data2.MarketPosition!=1)//如果Data2是主力已换月Data2交易
                                 {
                               Data2.Sell(Lots,Data2.Open);
                       If(TickCounter==0)
                       {
                                TickCounter = 1;
                                           }else If(TickCounter < DelayTicks)
                       {
                                TickCounter = TickCounter + 1;                        
                                           }else
                                           {
                                                           Data2.SellShort(Lots,Data2.Open);
                       }
                                 }
              }
        }      
      SetGlobalVar(0,LastBarTime);        
          SetGlobalVar(1,TickCounter);
End

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

bottom

静态版|手机版|联系我们|交易开拓者 ( 粤ICP备07044698   

GMT+8, 2024-5-18 14:44

Powered by Discuz! X2 LicensedChrome插件扩展

© 2011-2012 交易开拓者 Inc.

回顶部