Author: Andrey N. Bolkonsky
The Mean Deviation Index (MDI), also known as the Ergodic MDI, is a powerful tool for traders using MetaTrader 5. This double-smoothed indicator helps you gauge price momentum and trends by measuring the distance between the closing price and a smoothed moving average.
Essentially, the mean deviation gives you an insight into how much the price deviates from the average, allowing you to make more informed trading decisions.
- The smoothing process does introduce some lag, which becomes apparent at price reversal points. The mean deviation value reflects the distance between the current price and the r-period moving average.
- The sign of the mean deviation indicates the price's position relative to the r-period moving average: it’s positive when the price is below the moving average and negative when it’s above.
How to Use the MDI
- Ensure that WilliamBlau.mqh is placed in terminal_data_folder\MQL5\Include\
- Put Blau_MDI.mq5 in terminal_data_folder\MQL5\Indicators\

Mean Deviation Index by William Blau
Calculation of the MDI:
The mean deviation is calculated with the following formula:
md(price,r) = price - EMA(price,r)
Where:
- price - closing price;
- EMA(price,r) - the exponentially smoothed moving average over period r.
The Mean Deviation Index itself is derived from the formula:
MDI(price,r,s,u) = EMA(EMA(md(price,r),s),u) = EMA(EMA(price-EMA(price,r),s),u)
Where:
- price - closing price;
- EMA(price,r) - first EMA smoothing of period r;
- md(price,r) - mean deviation calculation;
- EMA(md(price,r),s) - second smoothing applied to mean deviation;
- EMA(EMA(md(price,r),s),u) - third smoothing applied to the result of the first smoothing.
Input Parameters
- r - period of the first EMA applied to price (default is r=20);
- s - period of the second EMA applied to mean deviation (default is s=5);
- u - period of the third EMA applied to the result of the smoothing (default is u=3);
- AppliedPrice - type of price used (default is PRICE_CLOSE).
Important Notes
- Ensure r>1;
- s>0 and u>0. If r, s, or u =1, smoothing is not applied;
- Minimum rates = (r + s + u - 3 + 1).
Understanding and utilizing the Mean Deviation Index can significantly enhance your trading strategy. By keeping an eye on price deviations, you can better navigate market trends and make more educated trading decisions.
Related Posts
- Unlocking MetaCOT 2: Your Ultimate CFTC Indicator Toolkit for MT4
- Unlocking the Power of Master Tools for MetaTrader 4
- Mastering the MACD Candle Indicator for MetaTrader 4
- Visualize Current Trends Across All Time Frames with This MetaTrader 4 Indicator
- Mastering the Ergodic Mean Deviation Index Oscillator for MetaTrader 5