I think the MT4 - Money Flow Index Calculation is Wrong!

 

I think the MT4 - Money Flow Index Calculation is Wrong!

I tried to replicate this MT4 - MFI Indicator but there's something wrong when I tried to follow the author MFI formula.

I discovered that MT4 - MFI signal is a little bit different, they used "Current Volume" in "Previous Money Flow calculation(Previous Typical Price * Current Volume)" instead of (Previous Typical Price * Previous Volume).

Correct me if I'm wrong?

Here's my code of MFI, equivalent of MT4 - MFI:

for(int i=0; i<limit; i++)
   {    
      double now_mf = ((High[i] + Low[i] + Close[i])/3) * Volume[i];          // Current Money Flow or (Current Typical Price * Volume) Calculation
      double prev_mf = ((High[i+1] + Low[i+1] + Close[i+1])/3) * Volume[i];   // Previous Money Flow or (Previous Typical Price * Volume) Calculation
      double mf = (now_mf - prev_mf);
      if(mf > 0)
      {
         gains[i] = now_mf;
         loses[i] = 0.0;
      }
      else
      {
         loses[i] = MathAbs(now_mf);
         gains[i] = 0.0;
      }
      
   }


Here's image of Custom MFI and MT4 - MFI:

This image will prove that my code is correct and same as MT4 code. 


 
Musngi:

I think the MT4 - Money Flow Index Calculation is Wrong!

I tried to replicate this MT4 - MFI Indicator but there's something wrong when I tried to follow the author MFI formula.

I discovered that MT4 - MFI signal is a little bit different, they used "Current Volume" in "Previous Money Flow calculation(Previous Typical Price * Current Volume)" instead of Previous Volume.

Correct me if I'm wrong?

Here's my code of MFI, equivalent of MT4 - MFI:


Here's image of Custom MFI and MT4 - MFI:

This image will prove that my code is correct and same as MT4 code. 


You are using current volume in prev_mf calculation
 
Mladen Rakic:
You are using current volume in prev_mf calculation

Look in my uploaded image. My custom MFI give same signals, I mean same as MT4- MFI signals. It means MT4 - MFI code calculate in that way.

 

Lots of things are wrong in MT4's default tools. Have you checked how it is in MT5?

I can confirm same thing for Gann fans - fundamentally wrong in 4, (at least partially) fixed in 5.

 
Musngi:

Look in my uploaded image. My custom MFI give same signals, I mean same as MT4- MFI signals. It means MT4 - MFI code calculate in that way.

Compared the built in MFI with this code :

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrDodgerBlue
#property strict

input int inpPeriod = 14;
double mfi[],rmfi[];
//------------------------------------------------------------------
//
//------------------------------------------------------------------
int OnInit()
{
   IndicatorBuffers(2);
   SetIndexBuffer(0,mfi);  SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(1,rmfi);
      IndicatorShortName("MFI test ("+(string)inpPeriod+")");
   return(INIT_SUCCEEDED);
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
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[])
{
   int counted_bars=prev_calculated;
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
         int limit = MathMin(rates_total-counted_bars,rates_total-1);
         
   //
   //
   //
   //
   //
            
   for(int i=limit; i>=0; i--)
   {    
      rmfi[i] = (high[i]+low[i]+close[i])/3.0;
      double sump = 0;
      double sumn = 0;
      for (int k=0; k<inpPeriod && (i+k+1)<rates_total; k++)
      {
         if (rmfi[i+k]>rmfi[i+k+1]) sump += rmfi[i+k]*tick_volume[i+k];
         if (rmfi[i+k]<rmfi[i+k+1]) sumn += rmfi[i+k]*tick_volume[i+k];
      }
      mfi[i] = 100-100/(1+(sumn!=0 ? sump/sumn :0));
   }   
   return(rates_total);
}

and they are the same for each and every bar. Since the code is calculating the MFI correctly, it seems that there is no issue with the built in MFI