anandanand84 / technicalindicators

A javascript technical indicators written in typescript with pattern recognition right in the browser
MIT License
2.13k stars 550 forks source link

is ADX correct (difference with TradingView) #244

Open enriquepiatti opened 2 years ago

enriquepiatti commented 2 years ago

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.

marcusmota commented 2 years ago

see my comment here https://github.com/anandanand84/technicalindicators/issues/239, might work for you as well

jere-0 commented 2 years ago

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!