Created
August 18, 2019 05:10
-
-
Save yuyasugano/d8c9f491d1f006ab7dcce4f622513cda to your computer and use it in GitHub Desktop.
Matplotlib Ichimoku sample
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
def Ichimoku(df): | |
df1 = df.copy() | |
max_9 = df1.high.rolling(window=9).max() | |
min_9 = df1.high.rolling(window=9).min() | |
df1["tenkan"] = (max_9+min_9)/2 | |
df1["base"] = (df1.high.rolling(window=26).max()+df1.high.rolling(window=26).min())/2 | |
xdate = [x.date() for x in df1.index] | |
plt.figure(figsize=(15,5)) | |
plt.grid() | |
plt.plot(xdate, df1.close, color="b", lw=1, linestyle="dotted", label="original") | |
plt.plot(xdate, df1.tenkan, label="Conversion line") | |
plt.plot(xdate, df1.base, label="Base line") | |
senkou1 = ((df1.tenkan+df1.base)/2).iloc[:-26] | |
senkou2 = ((df1.high.rolling(window=52).max()+df1.high.rolling(window=52).min())/2).iloc[:-26] | |
plt.fill_between(xdate[26:], senkou1, senkou2, color="blue", alpha=0.2, label="Cloud") | |
plt.legend(loc=4) | |
plt.xlim(xdate[0], xdate[-1]) | |
Ichimoku(df) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment