is ADX correct? (difference with TradingView) #315
-
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 trading-signals), but the result for ADX is not the same! This is the code used by TradingView (in PineScript):
plusDM and minusDM is the equivalent to |
Beta Was this translation helpful? Give feedback.
Replies: 14 comments 2 replies
-
One difference seems to be the smooth function used, TradingView is using "rma":
that gives some small difference in "plus" and "minus" from TradingView (corresponding to pdi and mdi from trading-signals). But the important difference in values I think is in the last formula for adx, are TradingView and trading-signals doing different things? |
Beta Was this translation helpful? Give feedback.
-
Hi @enriquepiatti. I think TradingView's ADX implementation is not standard compliant here. I have tested my ADX implementation and verified it with another implementation as you can see here: https://github.com/bennycode/trading-signals/blob/v2.0.1/src/ADX/ADX.test.ts#L36-L39 My implementation uses SMMA for smoothing. If it makes sense we can also add RMA (Relative Moving Average) as an option. Can you give me some input data and expected results for testing? |
Beta Was this translation helpful? Give feedback.
-
I think is not the only difference the SMMA vs RMA, here is the data for testing: close: high: Expected result (this is the ADX value from TradingView for the last item): 24.51 RMA implementation in PineScript (according to https://stackoverflow.com/questions/48055618/how-tradingview-pine-script-rma-function-works-internally):
|
Beta Was this translation helpful? Give feedback.
-
Thank you for providing sample data. On Trading View there are multiple implementations of ADX from different authors. Which one are you using? |
Beta Was this translation helpful? Give feedback.
-
I'm using official ADX from TradingView, is marked as "built in", Average Directional Index. |
Beta Was this translation helpful? Give feedback.
-
I couldn't replicate the same result from TradingView for RMA, not sure what I'm doing wrong, maybe you can see it.
|
Beta Was this translation helpful? Give feedback.
-
Can you reproduce the results from Tulip Indicators' ADX implementation? https://tulipindicators.org/adx |
Beta Was this translation helpful? Give feedback.
-
reproduce how? I don't know how to use Tulipan indicators, do they have an online version available? |
Beta Was this translation helpful? Give feedback.
-
You don't have to run Tulip Indicators. They have their test input and test output listed here: https://tulipindicators.org/adx I also have some other indicator implementations listed here: https://github.com/bennycode/trading-signals#alternatives Usually, I check the test data of other libraries to know if my library is compatible or consistent with their output. That's an alternative approach to testing with TradingView. |
Beta Was this translation helpful? Give feedback.
-
Hi @enriquepiatti, I have seen that you cross-posted your question: anandanand84/technicalindicators#244 I have done some research about ADX also and updated my ADX implementation so that you can use it with different moving average implementations for smoothing: trading-signals/src/ADX/ADX.test.ts Line 41 in 62ad238 Do you know to what RMA in TradingView is referring to? It could be "Relative Moving Average" but some people also think that it's a "Wilder's Moving Average": coin-unknown/Indicators#7 |
Beta Was this translation helpful? Give feedback.
-
I had the same problem, currently what I do is get 200 OHLCV and convert to "ATRcandles", then create a new ATR(14) and implement forEach with the 200 candles in adx.update().
|
Beta Was this translation helpful? Give feedback.
-
It looks like the values are almost compatible with Binance's DMI indicator. However, the results are slightly different in the 5th and 6th decimal place. I wonder if this is a Binance rounding mistake or a Big.js rounding mistake. 🤔 |
Beta Was this translation helpful? Give feedback.
-
@enriquepiatti today I noticed that the ADX return values of my lib are different from the calculations of Tulip Indicators (TI). I will update my implementation to match TI. Here is the TI test data for reference: |
Beta Was this translation helpful? Give feedback.
-
@enriquepiatti, @Fc299684 & @recidive: I have just released trading-signals v3.0.0 with a breaking change for ADX. The I also verified the implementation. By default ADX uses Wilder's Smoothed Moving Average to smoothen the DX values but you can change it if you like by providing another Moving Average class as second parameter to the ADX instantiation, e.g.: import {ADX, EMA} from 'trading-signals';
const adx = new ADX(5, EMA); My implementation is compatible with the Average Directional Movement Index from Tulip Indicators and returns the same results (given the same input). You can see this here: https://github.com/bennycode/trading-signals/blob/v3.0.0/src/ADX/ADX.test.ts Best, |
Beta Was this translation helpful? Give feedback.
@enriquepiatti, @Fc299684 & @recidive: I have just released trading-signals v3.0.0 with a breaking change for ADX.
The
getResult()
method of ADX now just returns a single value which is the index itself (adx). If you want to get the +DI and -DI you will have to check themdi
andpdi
members on the ADX instance. Make sure you only do this whenisStable
istrue
.I also verified the implementation. By default ADX uses Wilder's Smoothed Moving Average to smoothen the DX values but you can change it if you like by providing another Moving Average class as second parameter to the ADX instantiation, e.g.:
My implementation is…