Created
September 28, 2020 11:21
-
-
Save yuyasugano/173e78e37bd2e155f7c37d23eda28ec9 to your computer and use it in GitHub Desktop.
Trend indicator sample
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
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