tmh402932 发表于 2016-4-15 14:40:31

小米 发表于 2016-4-13 13:51 static/image/common/back.gif
在这后面不应该是currentbar>Lcount+1?

您好,我这边写了一个策略,但是测的时候还是一直提示“交易讯号消失”,我看了下判断条件,好像没啥问题,实在看不出是哪里导致的问题,请帮忙看下,谢谢
Params
    Bool    bInitStatus(false);//初始化标志,修改初始仓位时需设置为True
    Numeric InitMyRealMp(0);//初始当前仓位,正数表示多单,负数表示空单
    Numeric FirstGrid(10);//第一笔交易的间距,最小跳动
    Numeric AddGrid(30);//加仓间距,最小跳动
    Numeric TotalGrids(10);//最大交易次数
    Numeric TrailingGrid(10);//移动止损间距,最小跳动
    Numeric EveryLots(1);//每次开仓手数
    Numeric OffSet(1);//委托价偏差,默认买卖价偏差1个滑点
    Numeric ExitOnCloseMins(15.00);//收盘平仓时间
Vars
    Numeric HighAfterlongEntry;
    Numeric  LowAfterShortEntry;
    Numeric    MyRealMp(0);
    Numeric   MinPoint;
    Numeric  TmpPrice;
    Numeric   TmpLots;
Begin
    MinPoint=MinMove*PriceScale;//当前商品最小变动量*当前商品的计数单位
    MyRealMp=GetGlobalVar(0); //获取MyRealMp全局变量值
    HighAfterlongEntry=GetGlobalVar(1);
    LowAfterShortEntry=GetGlobalVar(2);
    If(BarStatus==0 And (MyRealMp==InvalidNumeric||bInitStatus))     //当前bar为第一个bar且MyRealMp为无效值 ,那么初始当前仓位 0
    {MyRealMp=InitMyRealMp;}
    If(Date<>Date){               //当前Bar的日期 不等于 上一个 Bar的日期说明 隔夜了
                HighAfterlongEntry=High;     // 设置 HighAfterlongEntry的值为当前Bar的最高价
                LowAfterShortEntry=Low;                 // 设置 LowAfterShortEntry的值为当前Bar的最低价
                MyRealMp=0;
    }Else{
                HighAfterlongEntry=Max(HighAfterlongEntry,High);
                LowAfterShortEntry=Min(LowAfterShortEntry,Low);
        }
        if (Time<ExitOnCloseMins/100){                  //当前Bar的时间 小于 收盘时间               
                If(MyRealMp>0 And HighAfterlongEntry-Low>=TrailingGrid*MinPoint And(High-Low<TrailingGrid*MinPoint Or (High-Low>=TrailingGrid*MinPoint And Close>Open))){
                          PlotString("a","a");
                          TmpPrice=Max(HighAfterLongEntry-(TrailingGrid-OffSet)*MinPoint,Low);
                          TmpLots=Abs(MyRealMp*EveryLots);
                          Sell(TmpLots,TmpPrice);
                          MyRealMp=0;
                          LowAfterShortEntry=Low;
                 }else If(MyRealMp<0 And High-LowAfterShortEntry>=TrailingGrid*MinPoint And (High-Low<TrailingGrid*MinPoint Or (High-Low>=TrailingGrid*MinPoint And Close<Open))){
                          TmpPrice=Min(LowAfterShortEntry+(TrailingGrid+OffSet)*MinPoint,High);
                          TmpLots=Abs(MyRealMp*EveryLots);
                          BuyToCover(TmpLots,TmpPrice);
                          MyRealMp=0;
                          HighAfterLongEntry=0;
                 }
         If(MyRealMp==0 And High-LowAfterShortEntry>=FirstGrid*MinPoint){       //第一笔多单开仓
                           TmpPrice=Min(LowAfterShortEntry+(FirstGrid+OffSet)*MinPoint,High);
                           TmpLots=EveryLots;
                           Buy(TmpLots,TmpPrice);
                           MyRealMp=1;
                           HighAfterLongEntry=High;
          }Else If(MyRealMp>0 And MyRealMp<TotalGrids And High-LowAfterShortEntry>=(FirstGrid+MyRealMp*AddGrid)*MinPoint){        //多单加仓                          
                          TmpPrice=Min(LowAfterShortEntry+(FirstGrid+MyRealMp*AddGrid+OffSet)*MinPoint,High);
                           TmpLots=EveryLots;
                           Buy(TmpLots,TmpPrice);
                           MyRealMp=MyRealMp+1;
          }else If(MyRealMp==0 And HighAfterLongEntry-Low>=FirstGrid*MinPoint){   //第一笔空单开仓
                           TmpPrice=Max(HighAfterLongEntry-(FirstGrid-OffSet)*MinPoint,Low);
                           TmpLots=EveryLots;
                           SellShort(TmpLots,TmpPrice);
                           MyRealMp=-1;
                           LowAfterShortEntry=Low;
          }else If(MyRealMp<0 And -1*MyRealMp<TotalGrids And HighAfterLongEntry-Low>=(FirstGrid+Abs(MyRealMp*AddGrid))*MinPoint){    //空单加仓
                           PlotString("f","f");       
                           TmpPrice=Max(HighAfterLongEntry-(FirstGrid-Abs(MyRealMp*AddGrid)-OffSet)*MinPoint,Low);
                           TmpLots=EveryLots;
                           SellShort(TmpLots,TmpPrice);
                           MyRealMp=MyRealMp-1;
                   }
       }else If(Time>=ExitOnCloseMins/100){           //当前Bar的时间 大于等于 收盘时间
                  
                  
                   If(MyRealMp>0)
                   {
                           TmpLots=Abs(MyRealMp*EveryLots);
                           TmpPrice=Close;
                           Sell(0,TmpPrice);
                           MyRealMp=0;
                        }
                   If(MyRealMp<0)
                   {
                           TmpLots=Abs(MyRealMp*EveryLots);
                           TmpPrice=Close;
                           BuyToCover(0,TmpPrice);
                           MyRealMp=0;
                        }
           }
       SetGlobalVar(0,MyRealMp);
       SetGlobalVar(1,HighAfterLongEntry);
       SetGlobalVar(2,LowAfterShortEntry);
       Commentary("MyRealMp="+Text(MyRealMp));
       Commentary("HighAfterLLowAfterShortEntry="+Text(LowAfterShortEntry));
       End

小米 发表于 2016-4-15 15:02:12

tmh402932 发表于 2016-4-15 14:40 static/image/common/back.gif
您好,我这边写了一个策略,但是测的时候还是一直提示“交易讯号消失”,我看了下判断条件,好像没啥问题 ...

抱歉呀。工作人员的人力精力都有限,没法帮您一个个地策略找问题。
建议还是自己按我前面说的方法来自行排查,输出注释,定位问题。。

tmh402932 发表于 2016-4-15 15:31:19

小米 发表于 2016-4-15 15:02 static/image/common/back.gif
抱歉呀。工作人员的人力精力都有限,没法帮您一个个地策略找问题。
建议还是自己按我前面说的方法来自行 ...

好的,谢谢

sexycow 发表于 2017-6-16 17:33:57

mark
页: 1 2 [3]
查看完整版本: 新手随便写了一个策略,但提示“交易讯号消失,可能导致您的持仓不匹配 ”,求救