Error while passing array by reference in a function argument MT5 EA

 

 Hi guys,

I was developing a function to calculate the value of EMA as i pass the source array by reference. But when i call it , it gets a lot of errors, i searched for a solution, but yet nothing. So i would be grateful if you can help.

      double ma1 = EMAonArray(ma,symbol,tf,inputs[index_i].fastma,i);
      double ma2 = EMAOnArray(ma,symbol,tf,inputs[index_i].slowma,i);


double EMAonArray(double &price[],string  symbol,ENUM_TIMEFRAMES tf,int  period,int index1)
  {
   double buffer[];
   ArrayResize(buffer,Bars(symbol,tf));
   ArrayInitialize(buffer,0);
   double dSmoothFactor=2.0/(1.0+period);
   for(int i = index1+period; i>=index1; i--)
     {
      if(i==index1+period)
        {
         buffer[i]=price[i];
        }
      else
        {
         buffer[i]=price[i]*dSmoothFactor+buffer[i-1]*(1.0-dSmoothFactor);
        }
     }
   return buffer[index1];
  }
 
I was developing a function to calculate the value of EMA as i pass the source array by reference.

Did you see this?

https://www.mql5.com/en/code/77

MovingAverages
MovingAverages
  • www.mql5.com
The MovingAverages library is a part of Standard package of MetaTrader 5 client terminal. The library contains functions for calculation of different types of moving averages. Totally, there are 8 functions that can be divided into 2 groups of functions of the same type, each containing 4 of them. The first group contains functions that receive...
 
Anthony Garot:

Did you see this?

https://www.mql5.com/en/code/77

Thanks