Last active
July 24, 2022 11:07
-
-
Save yongghongg/cd305d8e7fbbed06b84ea6786df5bae5 to your computer and use it in GitHub Desktop.
This file contains 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
# Stochastic | |
def Stochastic(df, window, smooth_window): | |
stochastic = pd.DataFrame() | |
stochastic['%K'] = ((df['Close'] - df['Low'].rolling(window).min()) \ | |
/ (df['High'].rolling(window).max() - df['Low'].rolling(window).min())) * 100 | |
stochastic['%D'] = stochastic['%K'].rolling(smooth_window).mean() | |
stochastic['%SD'] = stochastic['%D'].rolling(smooth_window).mean() | |
stochastic['UL'] = 80 | |
stochastic['DL'] = 20 | |
return stochastic | |
stochastic = Stochastic(df, 14, 3) | |
stochastic_plot = [ | |
mpf.make_addplot((stochastic[['%K', '%D', '%SD', 'UL', 'DL']]), ylim=[0, 100], panel=2, ylabel='Stoch') | |
] | |
mpf.plot(df, type='candle', volume=True, addplot=stochastic_plot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment