Created
July 31, 2021 18:49
-
-
Save nikkoxgonzales/cdf8e32e46fffb5c00685492bd16b992 to your computer and use it in GitHub Desktop.
TradingView Stochastic RSI implementation using python since TA-Lib fails to do this.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credits to this wrong code: https://gist.github.com/mouchh/b236f6a3a75b6a216b10e6fc44cf090f | |
import talib | |
import pandas as pd | |
k = 3 | |
d = 3 | |
period = 14 | |
rsi = talib.RSI(np_array_closes, period) | |
df = pd.DataFrame(rsi) | |
stochastic_rsi = 100 * (df - df.rolling(period).min()) / (df.rolling(period).max() - df.rolling(period).min()) | |
K = stochastic_rsi.rolling(k).mean() | |
D = K.rolling(d).mean().iloc[-1].iloc[0] | |
K = K.iloc[-1].iloc[0] | |
print(f"K: {K} | D: {D}") | |
# The more data you have the accurate this will be with the tradingview graphs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment