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

About RSI question #69

Closed
homily opened this issue Jul 11, 2020 · 6 comments
Closed

About RSI question #69

homily opened this issue Jul 11, 2020 · 6 comments

Comments

@homily
Copy link

homily commented Jul 11, 2020

hi。
when i use the RSI calc,it different with Tradingview。
the tradingview use RMA calc

url:https://www.tradingview.com/support/solutions/43000502338-relative-strength-index-rsi/

Calculation
RSI = 100 – 100/ (1 + RS)
RS = Average Gain of n days UP  / Average Loss of n days DOWN
For a practical example, the built-in Pine Script function rsi(), could be replicated in long form as follows.

change = change(close)
gain = change >= 0 ? change : 0.0
loss = change < 0 ? (-1) * change : 0.0
avgGain = rma(gain, 14)
avgLoss = rma(loss, 14)
rs = avgGain / avgLoss
rsi = 100 - (100 / (1 + rs))
"rsi", above, is exactly equal to rsi(close, 14).

so, Maybe you can view or update the calc code. ^_^

@twopirllc twopirllc added the enhancement New feature or request label Jul 11, 2020
@twopirllc
Copy link
Owner

Hi @homily,

Currently rsi has at least 99% correlation with TA Lib, so it is not a high priority right now.

That being said, I do not mind adding a TradingView version, but it is more difficult to test against as they do not have an easily testable library. If you know of a better and quicker way to test and compare vs TradingView, let me know what needs to be modified so that it matches TradingView.

Differences in languages (Python and Pinescript in this case) and how they handle decimals/floats can easily cause minor differences in calculations. What is the current correlation between pandas-ta and TradingView's rsi?

Regards,
KJ

@homily
Copy link
Author

homily commented Jul 30, 2020

Yes, thank you very much.

I've been using your library and it's very convenient.

I think it is very necessary to add tradingview. After all, there are many open scripts written with pin script. If tradingview can be effectively supported, it will be greatly convenient for all users.

@twopirllc
Copy link
Owner

Heya @homily,

Thank you!

Also, thanks for your patience. Yes, I do like TradingView and some of my own TV indicators are also incorporated in Pandas TA. If think the differences you may be seeing are the may be the differences in data sources; TV's data source and your data source may not be the same. Computationally, they are the same.

Thanks,
KJ

@twopirllc twopirllc removed the enhancement New feature or request label Jul 30, 2020
@twopirllc
Copy link
Owner

@homily,

Revamped stoch added stochrsi. Both are inline with TradingView.
Use help(ta.stoch) and help(ta.stochrsi) for more info.

Thanks,
KJ

@ongunarisev
Copy link

ongunarisev commented Apr 13, 2021

Hello,

What are the default parameters to get the same RSI reading in Binance, TradingView and this library? I am pretty confused with various methods for calculation of RSI and I really appreciate and explanatory answer. Library version is '0.2.45b0'. I call them in the following manner to compare directly with Binance:

    bars_df['rsi7'] = ta.stochrsi(bars_df.close, length=7, rsi_length=14, k=3, d=3)
    bars_df['rsi14'] = ta.rsi(bars_df.close, length=14, rsi_length=14, k=3, d=3)
    bars_df['rsi24'] = ta.rsi(bars_df.close, length=24, rsi_length=14, k=3, d=3)

@twopirllc
Copy link
Owner

Hello @Vesnog,

Standard literature for RSI has a default length of 14 including most platforms as well as this library.

STOCHRSI is the result of applying STOCH to RSI or in otherwords STOCHRSI = STOCH(RSI). If you believe STOCHRSI has significance then use it, if not then do not include it. Same with any other indicator. Only you can make that determination.

You shouldn't have to call them that way. You are including kwargs in RSI that serve no purpose. Recall that you can use help(ta.rsi) or help(ta.stochrsi) to list the available args and kwargs.

Here are some ways of calling the indicators you listed above:

Standard

import pandas as pd
import pandas_ta as ta

bars_df = # ohlcv data
bars_df["stochrsi7"] = ta.stochrsi(bars_df.close, length=7)
bars_df["rsi14"] = ta.stochrsi(bars_df.close)
bars_df["rsi24"] = ta.stochrsi(bars_df.close, length=24)

Pandas TA DataFrame

import pandas as pd
import pandas_ta as ta

bars_df = # ohlcv data
bars_df.ta.stochrsi(length=7, append=True)
bars_df.ta.stochrsi(append=True)
bars_df.ta.stochrsi(length=24, append=True)

Pandas TA Strategy

import pandas as pd
import pandas_ta as ta

bars_df = # ohlcv data

# (1) Create the Strategy
RSIStrategies = ta.Strategy(
    name="RSI and STOCHRSI",
    ta=[
        {"kind": "stochrsi", "length": 7},
        {"kind": "rsi"},
        {"kind": "rsi", "length": 24},
    ]
)

# (2) Run the Strategy
bars_df.ta.strategy(RSIStrategies)

Hope this helps and makes sense!

Kind Regards,
KJ

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

3 participants