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.
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.
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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:
Here's image of Custom MFI and MT4 - MFI:
This image will prove that my code is correct and same as MT4 code.