Average Directional Movement Index - Trend Indicators - MetaTrader 5
4. PDI = EMA( +DI )
NDI = EMA( -DI )
5. ADX = EMA( 100 * Abs( (PDI - NDI) / (PDI + NDI) )
'Average Directional Movement Index (ADX)' indicator by 'MetaQuotes' for MetaTrader 5 in the MQL5 Code Base
You |
My post |
---|---|
PDI = EMA( +DI ) NDI = EMA( -DI ) |
|
ADX = Abs(+DI - -DI) / (+DI + -DI) * 100 | ADX = EMA( 100 * Abs( (PDI - NDI) / (PDI + NDI) ) |
Your not, PDI ≠ +DI and ADX ≠ EMA( ADX )
The first value has nothing to be smoothed with, so the first EMA(value) equals the value itself. E.g. if you plot an EMA(PRICE_CLOSE, N) onto a chart you will see that the first EMA=PRICE_CLOSE.
So the very first value of EMA(+DI)=+DI and hence the very first ADX is not smoothed either. If not, how else would you calculate EMA(+DI) for the second bar in the history then?
I have finally got to the bottom of it, and dare say that MetaTrader calculate ADX incorrectly.
When EMA of PDI, NDI and DX is calculated for the second bar in history the preceding EMA value is set to zero. This contradicts the EMA formula
which assume the first EMA value to be equal the value itself.
This influences the entire ADX calculation.
William Roeder was right. I managed to get the same results for ADX, +DI and -DI, though I used Excel for calculations.
I'd swap names of variables from comments above: PDI and +DI, NDI and -DI. PDI and NDI are +DI and -DI from terminal, so they are better used as intermediary variables names in order not to make confusion. Like, PDI = +DM / TR * 100, whereas +DI = EMA (PDI) for N bars.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
I'm trying to figure out how ADX is calculated in MT. I have studied the documentation and the mql code of the indicator but am still observing something wrong.
The indicator start drawing on the chart from the 15th bar, but the data window shows values yet from the second bar.
Assume we have the following OHLC bar data:
Then the first value (starting from the second bar) should be calculated as follows: