Download MetaTrader 5
To add comments, please log in or register
Post web links to paid signals. Receive the partner's share!
billworld2
22
billworld2 2016.11.04 23:07 

An MQL4 function I've created and used before in prior MT4 versions is now yielding an "array out of range error" in my EA in latest version of MT4. I've searched around and can't find an answer. The error is referencing the line:

 Level = Levels[j]; 

after the word "Levels"

How do I fix this? 

 Thanks

 Bill 


//-----------------------------------
// RainbowTop() Function
//-----------------------------------
double RainbowTop(int BarsBack)
   {
   double   MA1 = NormalizeDouble(iMA(Symbol(), Period(), 8, 0, MODE_EMA, PRICE_CLOSE, BarsBack), Digits());
   double   MA2 = NormalizeDouble(iMA(Symbol(), Period(), 13, 0, MODE_EMA, PRICE_CLOSE, BarsBack), Digits());
   double   MA3 = NormalizeDouble(iMA(Symbol(), Period(), 21, 0, MODE_EMA, PRICE_CLOSE, BarsBack), Digits());
   double   MA4 = NormalizeDouble(iMA(Symbol(), Period(), 34, 0, MODE_EMA, PRICE_CLOSE, BarsBack), Digits());
   double   MA5 = NormalizeDouble(iMA(Symbol(), Period(), 55, 0, MODE_EMA, PRICE_CLOSE, BarsBack), Digits());

   double Levels[5];  
   Levels[0] = MA1;
   Levels[1] = MA2;
   Levels[2] = MA3;
   Levels[3] = MA4;
   Levels[4] = MA5;
  
   double TopLevel = 0;
   double Level = 0;
      
   for(int j=0; j<=ArraySize(Levels); j++)
      {
      Level = Levels[j];
      if (Level > TopLevel)      
         {
         TopLevel = Level;
         }
      }
   return(TopLevel);
   }


 

Fernando Carreiro
1520
Fernando Carreiro 2016.11.04 23:20  
billworld2: An MQL4 function I've created and used before in prior MT4 versions is now yielding an "array out of range error" in my EA in latest version of MT4. I've searched around and can't find an answer. The error is referencing the line:

 Level = Levels[j]; 

after the word "Levels"

How do I fix this?

...

for(int j=0; j<=ArraySize(Levels); j++)

...
It should be "j < ArraySize(Levels)" and not "<=".
billworld2
22
billworld2 2016.11.04 23:55  
Fernando Carreiro:
It should be "j < ArraySize(Levels)" and not "<=".
That works. Thanks Fernando!
/
To add comments, please log in or register