Исходная проблема
Я пытаюсь построить RSI индикатора, "xxx.mq4", следующим образом:
#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);
}
//+------------------------------------------------------------------+
, но я получаю следующую ошибку при запуске: "RSIxxx [инструмент], H1: массив вне диапазона в 'RSIxxx.mq4' (55,26)
Ссылка на эту строку:
ExtMapBufferCustomIndicator[i]= iCustom(NULL,0,s,20,40,0,0);
NB. Оригинальный индикатор работает нормально
Устойчивость к ошибкам даже при упрощении кода!
Даже при удалении ссылки на внешний код и замене его на пересчет исходного индикатора возникает такая же проблема
Всес благодарностью приняты предложения!
Редактировать 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);
}
//+------------------------------------------------------------------+
и код компилируется в MetaEditor в строгом режиме без предупреждений или ошибок, которые также учитывали бы точку зрения nicholishen Я полагаю