Arrays 为什么在这段代码中会出现数组超出范围的错误? 初始问题

Arrays 为什么在这段代码中会出现数组超出范围的错误? 初始问题,arrays,mql4,Arrays,Mql4,我试图绘制指标“xxx.mq4”的RSI,如下所示: #property indicator_buffers 1 #property indicator_color1 Red #property indicator_width1 2 //---- buffers double ExtMapBufferCustomIndicator[]; double ExtMapBufferRSICustomIndicator[]; int i; string s="xxx"; //+-

我试图绘制指标“xxx.mq4”的RSI,如下所示:

#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2

//---- buffers
double ExtMapBufferCustomIndicator[];
double ExtMapBufferRSICustomIndicator[];
int i;
string s="xxx";

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBufferRSICustomIndicator);
   SetIndexLabel(0,"RSICustomIndicator");
   
   IndicatorShortName("RSI of xxx: RSICustomIndicator");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=15;
//   printf(limit);
//---- main loop
   for(i=0; i<limit; i++)
     {
      ExtMapBufferCustomIndicator[i]= iCustom(NULL,0,s,20,40,0,0);
     }
   for(i=0; i<limit; i++)
     {
      ExtMapBufferRSICustomIndicator[i]=iRSIOnArray(ExtMapBufferCustomIndicator,0,14,0);
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
注意:原指示器工作正常

即使通过简化代码,错误依然存在! 即使删除对外部代码的引用并用重新计算原始指示符来替换,也会出现相同的问题

所有建议均已收到

编辑2019-02-09 为了澄清并回答最初的两个响应者,此代码出现相同的错误:

//+------------------------------------------------------------------+
//|                                  Copyright © 2019, Andy Thompson |
//|                                   mailto:andydoc1@googlemail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2019, Andy Thompson"
#property link      "mailto:andydoc1@googlemail.com"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 2

//---- buffers
double intCalcxxx[];
double ExtMapBufferRSIxxx[];
int i;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBufferRSIxxx);
   SetIndexLabel(0,"RSIxxx");
   ArraySetAsSeries(intCalcxxx,true);
   IndicatorShortName("RSI of xxx: RSIxxx");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0)  return(-1);
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;
   if(counted_bars==0) limit-=15;
//   printf(limit);
//---- main loop
   for(i=0; i<1000; i++)
     {
     Print(i,", ",limit);
      intCalcxxx[i]=(34.38805726*MathPow(iClose("EURUSD",0,i),0.3155)*MathPow(iClose("EURJPY",0,i),0.1891)*MathPow(iClose("EURGBP",0,i),0.3056)*MathPow(iClose("EURSEK",0,i),0.0785)*MathPow(iClose("EURCHF",0,i),0.1113))/(50.14348112*MathPow(iClose("EURUSD",0,i),-0.576)*MathPow(iClose("USDJPY",0,i),0.136)*MathPow(iClose("GBPUSD",0,i),-0.119)*MathPow(iClose("USDCAD",0,i),0.091)*MathPow(iClose("USDSEK",0,i),0.042)*MathPow(iClose("USDCHF",0,i),0.036));
     }
   for(i=0; i<1000; i++)
     {
      ExtMapBufferRSIxxx[i]=iRSIOnArray(intCalcxxx,0,14,0);
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|版权所有©2019,安迪·汤普森|
//|邮寄地址:andydoc1@googlemail.com |
//+------------------------------------------------------------------+
#财产版权“版权所有©2019,安迪·汤普森”
#属性链接“mailto:andydoc1@googlemail.com"
#属性严格
#属性指示器\u单独\u窗口
#属性指示符\u缓冲区1
#属性指示器\u颜色1红色
#属性指示器\u宽度1 2
//----缓冲区
双intCalcxxx[];
双ExtMapBuffersXXX[];
int i;
//+------------------------------------------------------------------+
//|自定义指示器初始化功能|
//+------------------------------------------------------------------+
int init()
{
//----指标
SetIndexStyle(0,绘制线);
SetIndexBuffer(0,extMapBuffersXXX);
SetIndexLabel(0,“RSIxxx”);
ArraySetAsSeries(intCalcxxx,真);
指标短名称(“xxx的RSI:RSIxxx”);
//----
返回(0);
}
//+------------------------------------------------------------------+
//|自定义指示器去初始化功能|
//+------------------------------------------------------------------+
去离子剂()
{
//----
返回(0);
}
//+------------------------------------------------------------------+
//|自定义指标迭代函数|
//+------------------------------------------------------------------+
int start()
{
int counted_bar=指示器计数();
如果(计数的_条<0)返回(-1);
如果(计数的_条>0)计数的_条--;
int limit=条数-条数;
如果(计数的钢筋==0)极限-=15;
//printf(限制);
//----主回路

对于(i=0;i当然,您必须初始化数组,因为它的大小为0…这导致“数组超出范围”(已在
i==0
)。解决方案:

double intCalcxxx[1000];

…但仍然存在问题(指示器计算常量值),但至少没有运行时异常!

当然,您必须初始化数组,因为它的大小为0…这导致“数组超出范围”(已在
i==0
)。解决方案:

double intCalcxxx[1000];

…但仍然存在问题(指示器计算常量值),但至少没有运行时异常!

您只声明了一个缓冲区,但试图在代码中使用两个缓冲区。lol-有两个缓冲区:```双ExtMapBuffersCustomIndicator[];双ExtMapBuffersCustomIndicator[]“``错误消息是直截了当的:它发生在RSIxxx.mq4(自定义指示符)…在H1时间范围内…我“猜测”连接到“自定义参数”(
20,40
)…否,因为当我用外部指示符的重新计算替换对外部指示符的调用时,错误仍在继续,…正如我在结尾处解释的那样。您只声明了一个缓冲区和两个动态数组。您必须显式地将数组映射到一个缓冲区。您没有这样做。您只声明了一个缓冲区,但尝试使用两个缓冲区在您的code.lol中,有两个缓冲区:``双ExtMapBufferCustomIndicator[];双extmapbufferrsicustindicator[];``错误消息是直接的:它发生在RSIxxx.mq4(自定义指示符)…在H1时间范围内…我“猜测”连接到“自定义参数”(
20,40
)…否,因为当我用重新计算来替换对外部指示符的调用时,错误仍在继续,…正如我在结尾处解释的那样。您只声明了一个缓冲区和两个动态数组。您必须显式地将数组映射到缓冲区。您没有这样做。谢谢-我在停止将其设置为索引b时忽略了这一点uffer。现在来看看它为什么返回常数!谢谢-我在停止将它设置为索引缓冲区时忽略了这一点。现在来看看它为什么返回常数!