Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created September 28, 2020 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyasugano/173e78e37bd2e155f7c37d23eda28ec9 to your computer and use it in GitHub Desktop.
Save yuyasugano/173e78e37bd2e155f7c37d23eda28ec9 to your computer and use it in GitHub Desktop.
Trend indicator sample
import matplotlib.pyplot as plt
def OBV(df):
df["obv"] = np.where(df['Close'] > df['Close'].shift(1), df['Volume'],
np.where(df['Close'] < df['Close'].shift(1), -df['Volume'], 0)).cumsum()
xdate = [x.date() for x in df.index]
plt.figure(figsize=(15, 10))
# plot the original closing line
plt.subplot(211)
plt.plot(xdate, df.Close, label="close")
plt.xlim(xdate[0], xdate[-1])
plt.legend()
plt.grid()
# plot volume and OBV
plt.subplot(212)
plt.title("OBV")
# plt.bar(xdate, df.Volume, label="volume")
plt.plot(xdate, df.obv, label="obv")
plt.xlim(xdate[0], xdate[-1])
plt.legend()
plt.grid(True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment