ADX value from plugin vastly different from Tradingview, just me or did I mess up some entry?
See original GitHub issueHi,
So first off this problem persists across multiple plugins and code. I love the pandas_ta library thus was hoping we could find a solution here.
First off here is the difference in values:
Here is my code:
def each_copy(ticker):
ticker_data = pd.DataFrame.copy(df[df["ticker"]==ticker],deep=False)
ticker_data.set_index('date',inplace=True)
return ticker_data
test_data = each_copy("MRPL")
test_data["adx"] = ta.adx(high=test_data.high,low=test_data.low,close=test_data.close)["ADX_14"]
test_data["aDMP_14"] = ta.adx(high=test_data.high,low=test_data.low,close=test_data.close)["DMP_14"]
test_data["aDMN_14"] = ta.adx(high=test_data.high,low=test_data.low,close=test_data.close)["DMN_14"]
test_data.loc["2022-04-19 15:15:00+05:30":]
Data from the function ‘each copy’ is returned this way
After adding adx data
I hope this is enough, I did notice that the code on Tradingview is different from what we are using here. Could that be the reason? Does TV use some other formula for ADX?
I am not much of a coder thus relying on your help.
Please help and thank you.
Issue Analytics
- State:
- Created a year ago
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Average Directional Index (ADX) - TradingView
The Average Directional Index (ADX) is a specific indicator used by technical analysts and traders in order to determine the strength of a...
Read more >ADX and DI advanced — Indicator by ippp0031 - TradingView
Since i have no knowledge of programing i was wondering if would be possible to add columns that would indicate the difference of...
Read more >[PX] ADX Boxes — Indicator by paaax - TradingView
Hello guys, today I would like to share an indicator that I had in my mind for quite some time. I call it...
Read more >Page 5 Average Directional Index (ADX) — Technical Indicators
I have added 3 items to the RSI indicator which helps me to get more information at the same time. 1) ADX value...
Read more >Tradingview exit indicators. Scripts 25. trendanalysis. ADX ...
For 1) The entry-stop loss will be 2% away so set at $8. ... intend to stay clear of if you wish to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The reason adx value is different is while TradingView handles the initial value differently, pands-ta does not.
I faced this issue recently, and I don’t know about the very detail of adx indicators, but I figured out where the difference comes from by looking at the code.
As you might know, rma depends on the previous value to get the current value. How to set the first value of rma seems to vary but TradingView uses the average of values.
The below is the code block of adx function. The version(master, dev) does not matter, because both do not seem to handle the first value.
All of
dmp
,dmn
andadx
depend onma("rma", ...)
method.If you delve into the function deeper, it basically uses
pandas.DataFrame.ewm
method.It has
adjustbool, default True
parameter that you should pay attention to.Setting it to
True
acts as the following: $y_t = \frac{x_t + (1 - \alpha)x_{t-1} + (1 - \alpha)^2 x_{t-2} + … + (1 - \alpha)^t x_0}{1 + (1 - \alpha) + (1 - \alpha)^2 + … + (1 - \alpha)^t}$False
which is what we want (to sync with TradingView): $\begin{split}\begin{split} y_0 &= x_0 \ y_t &= (1 - \alpha) y_{t-1} + \alpha x_t, \end{split}\end{split}$It seems like it does not provide a way of handling $y_0 = x_0$ part, and I couldn’t find it either. (someone asked the question at stackoverflow)
To work around this… you should hack input values a bit to get desired result:
adx
is a bit more tricky. It requireslength
of bothdmp
anddmn
values (at least for TradingView). If your data starts from 06-19, the first vaue ofadx
will appear at 07-16 which is 27 days later assuming thelength
is set to 14.I’m not sure this is considered to be a bug or something, but I hope my explanation helps.
How can I implement this fix? Swap out Hakumaku’s def adx method for the one in adx.py ?