Skip to content

Instantly share code, notes, and snippets.

View mouchh's full-sized avatar

Cyril Mouchel mouchh

  • Amiens, France
View GitHub Profile
@mouchh
mouchh / stochrsi.py
Last active July 31, 2021 18:11
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()
@mouchh
mouchh / stoch.py
Created November 29, 2020 16:44
Compute stochastic from OHLC dataframe which give the same value as Trading View Stoch(14, 3, 5)
# I was not able to retrieve same results as Trading View with talib STOCH 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/43000502332-stochastic-stoch/
# watchout on your params ;)
stoch = 100 * (dataframe['close'] - dataframe['low'].rolling(14).min()) / (dataframe['high'].rolling(14).max() - dataframe['low'].rolling(14).min())
dataframe['stoch_slowk'] = ta.SMA(stoch, 5)
dataframe['stoch_slowd'] = ta.SMA(dataframe['stoch_slowk'], 3)