Insert iMA indicator

 

I need to convert this function from MQL4 to MQL5 I can't understand how to insert the two moving averages for the correlation calculation. The items Symbol1 and Symbol2 are variable, since the correlation is calculated on six Currency where Symbol1 is fixed and Symbol 2 is variable. How will I have to structure the handles and their CopyBuffers?

double Correlation(string symbol1, string symbol2, int period, ENUM_APPLIED_PRICE AppliedPrice= PRICE_CLOSE)
{
   int i=1;
   double xm= iMA(symbol1, 0, period, 0, MODE_SMA, AppliedPrice);
   double ym= iMA(symbol2, 0, period, 0, MODE_SMA, AppliedPrice);
   double sxx=0, syy=0, sxy=0, t1, t2;
   for(int k=i; k<i+period; k++)
   {
      t1= iClose(symbol1, 0, k)-xm;
      t2= iClose(symbol2, 0, k)-ym;
      sxx+= t1*t1;
      syy+= t2*t2;
      sxy+= t1*t2;
   }
   return sxx*syy<=0 ? 0 : 100.0*sxy/MathSqrt(sxx*syy);
}
 
Start by reading the manual, especially the examples. They all (including iCustom) return a handle (an int.) You get that in OnInit. In OnTick you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5

Creating an iMA indicator handle, getting indicator values.
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08

Also see my example for encapsulating calls
          Detailed explanation of iCustom - MQL4 programming forum 2017.05.23