MQL4 to MQL5 custom indicator transfer

 

Hi,

I'm trying to convert this custom indicator that I originally coded in MQL4 into a new MQL5 custom indicator. However, the IndicatorCounted() function that I previously used doesn't exist in MQL5... I read multiple posts regarding this subject but none of them seemed to be able to replace this function.. I read it has something to do with the prev_calculated constant but I'm not too sure how how the bar count is performed in MT5...


As a reference, here is the original OnCalculate function in MQL4:

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[])
  {
//---
   Counted_bars=IndicatorCounted();                          // Number of counted bars
   i=Bars-Counted_bars-1;                                    // Index of the first uncounted
   while(i>=0)                                               // Loop for uncounted bars
     {
      Buf_0[i]=Close[i] - Close[i+1];            // Value of 0 buffer on i bar
      i--;                                                   // Calculating index of the next bar
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }