Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLUS_DI gives different results #266

Open
konstantin-doncov opened this issue May 30, 2019 · 4 comments
Open

PLUS_DI gives different results #266

konstantin-doncov opened this issue May 30, 2019 · 4 comments

Comments

@konstantin-doncov
Copy link

konstantin-doncov commented May 30, 2019

Hello!
I use ta-lib in the freqtrade bot. When I plot indicators, It seems that PLUS_DI indicator in the ta-lib and DMI with ADX smoothing = 14 and DI length = 14 on the tradingview.com give different results.
E.g.:
ETHBTC 14 May 19, 01:00(UTC) PLUS_DI in tradingview.com: 5.549
ETHBTC 14 May 19, 01:00(UTC) PLUS_DI in ta-lib: 3.070

So, how can I get the ta-lib DMI indicator in the freqtrade strategy with the same settings as on the tradingview.com?

@hroff-1902
Copy link

hroff-1902 commented May 30, 2019

What are the values of the indicator in the nearest candles on tradingview? Isn't they are just shifted by 1 (or -1) candle?

@konstantin-doncov
Copy link
Author

@hroff-1902 I don't think so. Please look at the plots below:
PLUS_DI in ta-lib:
PLUS_DI
PLUS_DI in tradingview.com:
DMI

Also, plots very clearly shows that PLUS_DI in ta-lib does not cross the 10 mark before May 14 01:00, but DMI in tradingview.com crosses this mark at May 13 19:00.

@xmatthias
Copy link
Contributor

if you use ta-lib with freqtrade, make sure to apply the decimal patch (to the underlying C library) as otherwise it has some trouble with the small numbers BTC uses.

Also make sure you have enough history - iirc plus_di uses smoothening of TR, so with 14, 14 as parameters, you'll need 28 candles to get "good" results (but i'm not 100% sure on the formula). this would explain why it "seems" correct(er) a bit later

@zakcali
Copy link

zakcali commented Mar 27, 2023

this is a working python code
values are different from tradingview or investing, but timing of +di and -di crossovers are correct

adx, +di, -di embedded, reference from: https://medium.com/codex/does-combining-adx-and-rsi-create-a-better-profitable-trading-strategy-125a90c36ac

`import pandas as pd

def get_adx(high, low, close, lookback):

plus_dm = high.diff()
minus_dm = low.diff()
plus_dm[plus_dm < 0] = 0
minus_dm[minus_dm > 0] = 0
tr1 = pd.DataFrame(high - low)
tr2 = pd.DataFrame(abs(high - close.shift(1)))
tr3 = pd.DataFrame(abs(low - close.shift(1)))
frames = [tr1, tr2, tr3]
tr = pd.concat(frames, axis = 1, join = 'inner').max(axis = 1)
atr = tr.rolling(lookback).mean()
plus_di = 100 * (plus_dm.ewm(alpha = 1/lookback).mean() / atr)
minus_di = abs(100 * (minus_dm.ewm(alpha = 1/lookback).mean() / atr))
dx = (abs(plus_di - minus_di) / abs(plus_di + minus_di)) * 100
adx = ((dx.shift(1) * (lookback - 1)) + dx) / lookback
adx_smooth = adx.ewm(alpha = 1/lookback).mean()
return plus_di, minus_di, adx_smooth

`

df = pd.read_csv('1D/XU100-1D.csv')
tempor = get_adx (df["High"], df["Low"], df["Close"], 14)
df["PLUS_DI_14"] = tempor [0]
df["MINUS_DI_14"] = tempor [1]
df["ADX_14"] = tempor [2]
pd.set_option('display.max_rows', df.shape[0]+1)
print(df)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants