如何计算条纹持续时间?

时间:2015-10-20 01:05:49

标签: algorithmic-trading forex mql5 technical-indicator

我已经制作了一个代码来计算 MQL5 中的条纹持续时间(ConnorsRSI)。但它不起作用。

MQL代码是:

/////////////////////////////////////////////////////////


int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[])
  {
//----+   
   //---- check for the presence of bars, sufficient for the calculation
   if (rates_total < (sdPer - 1) + begin)
    return(0);

//---- declaration of local variables 
   int first, bar, i, t;

//---- calculation of starting index first of the main loop
   if(prev_calculated==0) // check for the first start of the indicator
      first=sdPer-1+begin; // start index for all the bars
   else first=prev_calculated-1; // start index for the new bars

//---- main loop of the calculation
   for(bar = first; bar < rates_total - 1; bar++)
    {    
      t = 0;
      //---- avaliation loop for the current bar
      for(i = 0; i < sdPer; i++)

      if(price[bar] > price[bar - i])
      {
         if(t >= 1)
            t = t + 1;
         else t = 1;
      }

      else if(price[bar] < price[bar - i])
      {      
         if(t <= -1)
         t = t - 1;
         else t = -1;
      }

      else if(price[bar] == price[bar - i])
      {
         t = 0;
      }

//---- set the element of the indicator buffer with the value of SMA we have calculated
      ExtLineBuffer[bar]=t;// **streak duration**
    }
//----+     
   return(rates_total);
  }

////////////////////////////////////////////////////////////

我没有发现错误。怎么回事?

1 个答案:

答案 0 :(得分:1)

我已经测试了代码,它运行正常。请确保您正在做这些事情:

  1. 将指标设置为单独的窗口指示器:app_hello: path: /hello/foo defaults: { _controller: MdBundle:Hello:foo } app_hello2: path: /hello2/foo defaults: { _controller: MdBundle:Hello2:foo }
  2. 定义缓冲区和图。例如,像这样:

    # app/config/routing.yml
    MdBundle:
        resource: "@MdBundle/Resources/config/routing.yml"
    
  3. 指定索引缓冲区(#property indicator_separate_window):#property indicator_buffers 1 #property indicator_plots 1 #property indicator_color1 clrRed #property indicator_type1 DRAW_LINE #property indicator_style1 STYLE_SOLID