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.
4. PDI = EMA( +DI ) NDI = EMA( -DI )
5. ADX = EMA( 100 * Abs( (PDI - NDI) / (PDI + NDI) )
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.