//+------------------------------------------------------------------+ //| MI.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 "Mass Index" #include //--- indicator settings #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 1 #property indicator_type1 DRAW_LINE #property indicator_color1 clrDodgerBlue #property indicator_level1 27 #property indicator_level2 26.5 #property indicator_levelcolor clrDarkGray //--- input parametrs input int InpPeriodEMA=9; // First EMA period input int InpSecondPeriodEMA=9; // Second EMA period input int InpSumPeriod=25; // Mass period //--- indicator buffers double ExtHLBuffer[]; double ExtEHLBuffer[]; double ExtEEHLBuffer[]; double ExtMIBuffer[]; int ExtPeriodEMA; int ExtSecondPeriodEMA; int ExtSumPeriod; //+------------------------------------------------------------------+ //| MI initialization function | //+------------------------------------------------------------------+ void OnInit() { //--- check input variables if(InpPeriodEMA<=0) { ExtPeriodEMA=9; PrintFormat("Incorrect value for input variable InpPeriodEMA=%d. Indicator will use value=%d for calculations.", InpPeriodEMA,ExtPeriodEMA); } else ExtPeriodEMA=InpPeriodEMA; if(InpSecondPeriodEMA<=0) { ExtSecondPeriodEMA=9; PrintFormat("Incorrect value for input variable InpSecondPeriodEMA=%d. Indicator will use value=%d for calculations.", InpSecondPeriodEMA,ExtSecondPeriodEMA); } else ExtSecondPeriodEMA=InpSecondPeriodEMA; if(InpSumPeriod<=0) { ExtSumPeriod=25; PrintFormat("Incorrect value for input variable PeriodSum=%d. Indicator will use value=%d for calculations.", InpSumPeriod,ExtSumPeriod); } else ExtSumPeriod=InpSumPeriod; //--- define buffers SetIndexBuffer(0,ExtMIBuffer); SetIndexBuffer(1,ExtEHLBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(2,ExtEEHLBuffer,INDICATOR_CALCULATIONS); SetIndexBuffer(3,ExtHLBuffer,INDICATOR_CALCULATIONS); //--- number of digits of indicator value IndicatorSetInteger(INDICATOR_DIGITS,2); //--- name for DataWindow and indicator subwindow label IndicatorSetString(INDICATOR_SHORTNAME,"Mass Index("+string(ExtPeriodEMA)+","+string(ExtSecondPeriodEMA)+","+string(ExtSumPeriod)+")"); PlotIndexSetString(0,PLOT_LABEL,"MI("+string(ExtPeriodEMA)+","+string(ExtSecondPeriodEMA)+","+string(ExtSumPeriod)+")"); //--- indexes draw begin settings PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPeriodEMA+ExtSecondPeriodEMA+ExtSumPeriod-3); } //+------------------------------------------------------------------+ //| Mass 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[]) { int pos_mi=ExtSumPeriod+ExtPeriodEMA+ExtSecondPeriodEMA-3; if(rates_total=pos_mi) { for(int j=0; j