Skip to content

Instantly share code, notes, and snippets.

@mouchh
Last active July 31, 2021 18:11
Show Gist options
  • Save mouchh/b236f6a3a75b6a216b10e6fc44cf090f to your computer and use it in GitHub Desktop.
Save mouchh/b236f6a3a75b6a216b10e6fc44cf090f to your computer and use it in GitHub Desktop.
Compute RSI stochastic from OHLC dataframe which give the same value as Trading View Stoch RSI(3, 3, 14, 14, close)
# I was not able to retrieve same results as Trading View with talib STOCHRSI function...
# I may misuse talib params but I found it easier to rewrite the computation, following Trading View doc
# https://www.tradingview.com/support/solutions/43000502333-stochastic-rsi-stoch-rsi/
# watchout on your params ;)
rsi = ta.RSI(dataframe)
stochrsi = 100 * (rsi - rsi.rolling(14).min()) / (rsi.rolling(14).max() - rsi.rolling(14).min())
dataframe['stochrsi_fastk'] = stochrsi.rolling(3).mean()
dataframe['stochrsi_fastd'] = dataframe['stochrsi_fastk'].rolling(3).mean()
@nikkoxgonzales
Copy link

This is so confusing as you are equating ta.RSI which is not a dataframe into using dataframe functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment