Attempt to access the data of an indicator and get its data into an array to check against later.

 

Hello, 

I'm trying to access the data of customer indicators I have "Aroon Up&Dn" and "MCAD" and get its Data in an array to do some checks on it later.

But I always get "Array out of range" error. 

Maybe that's because I'm attempting to access the data of an indicator buffer while its size has not been initialized yet. But I don't know what to do.

void OnStart()

  {

//---

   int flag = 0;

   double AroonUpBuffer[];

   double AroonDnBuffer[];

   double MCADbufer[]; 

   

   int counted_bars = IndicatorCounted();

   if(counted_bars > 0) counted_bars--;

   int CalculateBars = Bars - counted_bars;

   for(int i = CalculateBars; i >= 0; i--)

   {

      // Indicator calculations

      // Arron Up & Dn

       AroonDnBuffer[i] = iCustom(Symbol(), Period(), "Aroon_Up_Down", 0,i);

       AroonUpBuffer[i] = iCustom(Symbol(), Period(), "Aroon_Up_Down", 1,i);



       // MCAD indicator 

       MCADbufer[i] = iCustom(Symbol(), Period(), "MACD", 1,i);              

   

  }

  

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

  {

      printf("AroonDnBuffer[%d] = %d", j, AroonDnBuffer[j]); 

      printf("AroonUpBuffer[%d] = %d", j, AroonUpBuffer[j]); 

  }

}


Error occurs at the following line

AroonDnBuffer[i] = iCustom(Symbol(), Period(), "Aroon_Up_Down", 0,i);

"2021.05.16 13:26:12.709	2020.05.01 03:00:00  MyFirstEA GBPJPY,H1: array out of range in 'TradeFunctions.mqh' (80,21)
2021.05.16 13:26:12.709	2020.05.01 03:00:00  Testing pass stopped due to a critical error in the EA

 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
 
younis_traveller: I'm trying to access the data of customer indicators I have "Aroon Up&Dn" and "MCAD" and get its Data in an array to do some checks on it later.

But I always get "Array out of range" error. Maybe that's because I'm attempting to access the data of an indicator buffer while its size has not been initialized yet. But I don't know what to do.

Your code is completely mixed up and wrong! You are using the OnStart() event handler which is for Scripts, but then proceed to try to use code which is specific to creating new Indicators, while at the same time trying to access content for uninitialized dynamic arrays that have not yet been sized.

You are also mixing old MQL4 functions with new MQL4+ concepts! You are totally mixing apples and oranges!

So, either code an Indicator, and declare the Arrays as Indicator Buffers so that their sizes will be set properly ...
... or use a Script and properly size the arrays and don't use specialised functions that are meant to be used for creating new indicators.

 

Always lookup the documentation reference for the functions you use and look at the example code given. Don't just copy/paste code you find on the net without fully understanding how it all works.

If possible start with a book on coding MQL and follow the examples and learn things step by step.

Here are a few forum links about books to learn MQL: