//+------------------------------------------------------------------+ //| MFI.mq5 | //| Copyright 2000-2025, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2000-2025, MetaQuotes Ltd." #property link "https://www.mql5.com" #property description "Money Flow Index" //--- indicator settings #property indicator_separate_window #property indicator_buffers 1 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrDodgerBlue #property indicator_maximum 100.0 #property indicator_minimum 0.0 #property indicator_level1 20.0 #property indicator_level2 80.0 #property indicator_levelcolor clrSilver #property indicator_levelstyle 2 #property indicator_levelwidth 1 //--- input parameters input int InpMFIPeriod=14; // Period input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes //--- indicator buffer double ExtMFIBuffer[]; int ExtMFIPeriod; //+------------------------------------------------------------------+ //| Money Flow Index initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- check for input value if(InpMFIPeriod<=0) { ExtMFIPeriod=14; Print("Parameter InpMFIPeriod has wrong value. Indicator will use value ",ExtMFIPeriod); } else ExtMFIPeriod=InpMFIPeriod; //--- indicator buffer SetIndexBuffer(0,ExtMFIBuffer); //--- name for DataWindow and indicator subwindow label IndicatorSetString(INDICATOR_SHORTNAME,"MFI("+string(ExtMFIPeriod)+")"); //--- set draw begin PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtMFIPeriod); //--- set indicator digits IndicatorSetInteger(INDICATOR_DIGITS,_Digits); } //+------------------------------------------------------------------+ //| Money Flow Index | //+------------------------------------------------------------------+ 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[]) { if(rates_totalprevious_tp) positive+=volume[index+1]*current_tp; if(current_tp