Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created August 18, 2019 05:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyasugano/d8c9f491d1f006ab7dcce4f622513cda to your computer and use it in GitHub Desktop.
Save yuyasugano/d8c9f491d1f006ab7dcce4f622513cda to your computer and use it in GitHub Desktop.
Matplotlib Ichimoku sample
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