anandanand84/technicalindicators

is ADX correct (difference with TradingView)

enriquepiatti opened this issue · 2 comments

I'm comparing the results from TradingView charts (with ADX built in indicator), same input period, same candles (this is ok because the SMA for example is returning same values in TradingView and with technicalindicators), but the result for ADX is not the same!
Does somebody know why is that?
Do you know some other chart with ADX indicator to compare with a 3rd reference?

This is the code used by TradingView (in PineScript):

up = change(high)
down = -change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = rma(tr, len)
plus = fixnan(100 * rma(plusDM, len) / truerange)
minus = fixnan(100 * rma(minusDM, len) / truerange)
sum = plus + minus
adx = 100 * rma(abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)

rma = Moving average used in RSI. It is the exponentially weighted moving average with alpha = 1 / length.

see my comment here #239, might work for you as well

I used the following page to develop my custom ADX indicator: https://school.stockcharts.com/doku.php?id=technical_indicators:average_directional_index_adx

Also, you can pull up a chart with the ADX indicator for free on any stock. Good luck!