import requests
import csv
import jhtalib as jhta
import matplotlib.pyplot as plt
# download csv content:
result = requests.get('https://raw.githubusercontent.com/joosthoeks/jhTAlib/master/example/data.csv')
decoded = result.content.decode('utf-8')
csv_reader = csv.reader(decoded.splitlines(), delimiter=',')
# save csv content to csv file:
with open('data.csv', 'w') as csv_file:
csv_writer = csv.writer(csv_file)
for row in csv_reader:
csv_writer.writerow(row)
# start example:
df = jhta.CSV2DF('data.csv')
x = df['datetime']
bbands = jhta.BBANDS(df, 20)
plt.figure(1)
plt.subplot(211)
plt.title('Time / Price')
plt.xlabel('Time')
plt.ylabel('Price')
plt.grid(True)
plt.plot(x, df['Close'], color='blue')
plt.plot(x, bbands['midband'], color='red')
plt.plot(x, bbands['upperband'], color='yellow')
plt.plot(x, bbands['lowerband'], color='yellow')
plt.legend(['Close', 'BBANDS midband', 'BBANDS upperband', 'BBANDS lowerband'], loc='upper left')
plt.show()