首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么iCustom()返回我的指示符的默认值(2147483647)?

为什么iCustom()返回我的指示符的默认值(2147483647)?
EN

Stack Overflow用户
提问于 2019-08-23 18:51:34
回答 1查看 1.5K关注 0票数 0

我构建了自己的自定义指示器,它使用前面的X条数来计算图表的近似斜率和加速度。

当我将指示符附加到图表上时,它按预期工作,但当我试图使用iCustom()检索EA中的最新值时,它只返回2147483647。

我已经尝试过对iCustom() shift参数使用不同的值,但没有成功。

代码语言:javascript
运行
复制
double         SlopeBuffer[];
double         AccelerationBuffer[];

extern int delta;

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,SlopeBuffer);
   SetIndexBuffer(1,AccelerationBuffer);

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   int i, counted_bars;
   counted_bars = IndicatorCounted();
   i = Bars - counted_bars - delta; // Here I offset the initial bar by the delta(period)
                                    // so that the first bar has delta previous bars on the chart.

   while(i>=0){                     
      double Ex = 0; //intermediate calculation variables...
      double Ey = 0;
      double Exy = 0;
      double Exx = 0;
      for(int n=0;n<delta;n++){     // This for loop iterates over the previous delta bars
         Ex += n;                   // to calculate various sigma variables used to find the
         Ey += Close[i+delta-n-1];  // slope.
         Exy += n*Close[i+delta-n-1];
         Exx += n*n;
         }
      double slope = 100*(delta*Exy - Ex*Ey)/(delta*Exx - Ex*Ex); // final slope calculation.
      SlopeBuffer[i] = slope;                                     // add to the buffer.
      AccelerationBuffer[i] = (slope - SlopeBuffer[i+1]);         // calculate acceleration
   i--;                                                           // and adding to buffer.
   }

//--- return value of prev_calculated for next call
   return(rates_total);
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-08-24 00:31:59

我解决了这个问题。

这条线是罪魁祸首。

i = Bars - counted_bars - delta;

一旦指示符“赶上”了图表上所有已完成的条形图,i就等于1 - delta,这将是负值。其结果是while循环永远不会运行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57631610

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档