PLEASE help figure out why the array is out of range.

 

Hi Guys, I am a newbie but have managed to code quite a few things of various complexity (after a lot of pain!). The latest indicator I'm trying to code seems to be stuck on the first step. I'm sure it's something very easy but I can't see what I'm doing wrong. Here is the code:


#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window


//---- indicator parameters
extern int EMAPeriod=50;
extern double AngleTreshold=0.2;
extern int StartEMAShift=6;
extern int EndEMAShift=0;

//---- indicator buffers
double AngleUp[];
double AngleDn[];

int i, pos;
double haOpen,haHigh,haLow,haClose;
double ExtLowHigh[];
double ExtHighLow[];
double ExtOpen[];
double ExtClose[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
      IndicatorDigits(Digits);

//---
   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[])
  {
  
   double fEndMA, fStartMA;
   double fAngle, mFactor;
   int ShiftDif;
   string Sym;  
  
//---
   ArraySetAsSeries(AngleUp,false);
   ArraySetAsSeries(AngleDn,false);

   ArraySetAsSeries(ExtLowHigh,false);
   ArraySetAsSeries(ExtHighLow,false);
   ArraySetAsSeries(ExtOpen,false);
   ArraySetAsSeries(ExtClose,false);
   ArraySetAsSeries(open,false);
   ArraySetAsSeries(high,false);
   ArraySetAsSeries(low,false);
   ArraySetAsSeries(close,false);
//--- preliminary calculation
   if(prev_calculated>1)
      pos=prev_calculated-1;
   else
     {
      //--- set first candle
      if(open[0]<close[0])
        {
         ExtLowHigh[0]=low[0];
         ExtHighLow[0]=high[0];
        }
      else
        {
         ExtLowHigh[0]=high[0];
         ExtHighLow[0]=low[0];
        }
      ExtOpen[0]=open[0];
      ExtClose[0]=close[0];
      //---
      pos=1;
     }

It's stuck on the line "ExtLowHigh[0]=high[0];" with the error, array out of range. I sized the array using "ArraySetAsSeries" so I'm not sure why it's out of range here.

Can anyone PLEASE help?

 
vish4al:

Hi Guys, I am a newbie but have managed to code quite a few things of various complexity (after a lot of pain!). The latest indicator I'm trying to code seems to be stuck on the first step. I'm sure it's something very easy but I can't see what I'm doing wrong. Here is the code:


It's stuck on the line "ExtLowHigh[0]=high[0];" with the error, array out of range. I sized the array using "ArraySetAsSeries" so I'm not sure why it's out of range here.

Can anyone PLEASE help?

you have not sized the array.....

ArraySetAsSeries dictates array direction not it's size.

look at the documentation under Arrays

 
Paul Anscombe #:

you have not sized the array.....

ArraySetAsSeries dictates array direction not it's size.

look at the documentation under Arrays


Thanks, I used the ArrayResize command and it seems to be working now.


I was taking the code from the stock Heinki Ashi indicator and that doesn't seem to size the array. Which is why I thought ArraySetAsSeries dictates direction and size.


I guess when working with buffers the resizing is done another way as the only change I made was not using the buffers.


Thanks a lot for your help!

 
vish4al #:


Thanks, I used the ArrayResize command and it seems to be working now.

Thanks a lot for your help!

You’re welcome 
Reason: