开拓者期货期权程序化系统交易论坛

标题: 这个公式编译通过也触发不了跟踪止损,有没有大神指点一下问题在哪里 [打印本页]

作者: baby9112    时间: 2018-12-22 17:13:00     标题: 这个公式编译通过也触发不了跟踪止损,有没有大神指点一下问题在哪里

            Params
        //此处添加参
      Numeric StartPer1(5);  //1级跟踪止盈,盈利10%启动
      Numeric StopPer1(20); //1级跟踪止盈,盈利回撤100%触发
      Numeric StartPer2(10); //2级跟踪止盈,盈利20%启动
      Numeric StopPer2(30);  //2级跟踪止盈,盈利回撤50%触发        
      Numeric StartPer3(30); //3级跟踪止盈,盈利30%启动
      Numeric StopPer3(30);  //3级跟踪止盈,盈利回撤30%触发
      Numeric StartPer4(50); //3级跟踪止盈,盈利50%启动
      Numeric StopPer4(15);  //3级跟踪止盈,盈利回撤15%触发        
      Numeric StopLoss(1); // 止损2%
     
Vars
        //此处添加变量
     NumericSeries HighestAfterEntry;        // 开仓后出现的最高价
     NumericSeries LowestAfterEntry;         // 开仓后出现的最低价
    //记录开仓后高低点
     if (BarsSinceEntry == 1)
        {
                HighestAfterEntry = High;
                LowestAfterEntry = Low;
        } Else If(BarsSinceEntry > 1)
        {
                HighestAfterEntry = Max(HighestAfterEntry[1],High[1]);
                LowestAfterEntry = Min(LowestAfterEntry[1],Low[1]);
        }
        Else
        {
                HighestAfterEntry = HighestAfterEntry[1];
                LowestAfterEntry = LowestAfterEntry[1];
        }
            Commentary("HighestAfterEntry="+Text(HighestAfterEntry));
            Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
   
      //1级跟踪止盈,盈利10%启动,盈利回撤100%触发
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer1) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer1)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer1));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer1) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer1)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer1));
        }

        //2级跟踪止盈,盈利20%启动,盈利回撤50%触发        
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer2) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer2)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer2));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer2) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer2)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer2));
        }
        
        //3级跟踪止盈,盈利30%启动,盈利回撤30%触发
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer3) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer3)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer3));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer3) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer3)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer3));
        }        
        
        //4级跟踪止盈,盈利50%启动,盈利回撤15%触发
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer4) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer4)
        {
            BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer4));
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer4) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer4)
        {
            Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer4));
        }        
        
        // 启动止损
        If(MarketPosition==-1 && BarsSinceLastEntry>0 && High>=LastEntryPrice*(1+StopLoss*0.01))
        {
                BuyToCover(0,Max(LastEntryPrice*(1+StopLoss*0.01),Open));
                Commentary(Text(StopLoss)+"%止损");
        }
        If(MarketPosition==1 && BarsSinceLastEntry>0 && Low<=LastEntryPrice*(1-StopLoss*0.01))
        {
                Sell(0,Min(LastEntryPrice*(1-StopLoss*0.01),Open));
                Commentary(Text(StopLoss)+"%止损");
        }
        End
作者: 小米    时间: 2018-12-26 15:21:54

可以使用commentary等注释语句,对信号条件的值进行注释输出,以人工对比判断到底是什么条件没有满足,从而没有按原想法出信号。
作者: Goldinvp    时间: 2018-12-27 21:06:11

(1)没有进场的指令。BarsinceEntry根本无法执行,因为没有Entry
(2)另外,这个止盈的分级没有任何意义。只要最低的条件符合,后面这些都没有用。




欢迎光临 开拓者期货期权程序化系统交易论坛 (http://bbs.tb18.net/) Powered by Discuz! X2