-
Notifications
You must be signed in to change notification settings - Fork 3
/
graph.py
91 lines (69 loc) · 2.57 KB
/
graph.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""Script to show visual representation of the datasets that have been logged.
"""
import os
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
# fileName = input('Dataset file name: ')
# csvPath = os.path.join('bot', 'logs', fileName)
csvPath = 'tmp.csv'
df = pd.read_csv(csvPath, sep='|')
rsiBuy = []
rsiSell = []
bollBuy = []
bollSell = []
signalBuy = []
signalSell = []
for i in range(len(df['Close'])):
# RSI
if df['RSI Decision'].iloc[i] == 0:
rsiBuy.append(np.nan)
rsiSell.append(np.nan)
elif df['RSI Decision'].iloc[i] == 1:
rsiBuy.append(df['Close'].iloc[i])
rsiSell.append(np.nan)
elif df['RSI Decision'].iloc[i] == -1:
rsiBuy.append(np.nan)
rsiSell.append(df['Close'].iloc[i])
# Bollinger
if df['Bollinger Decision'].iloc[i] == 0:
bollBuy.append(np.nan)
bollSell.append(np.nan)
elif df['Bollinger Decision'].iloc[i] == 1:
bollBuy.append(df['Close'].iloc[i])
bollSell.append(np.nan)
elif df['Bollinger Decision'].iloc[i] == -1:
bollBuy.append(np.nan)
bollSell.append(df['Close'].iloc[i])
# Buy/Sell Signals
if df['RSI Decision'].iloc[i] == 0 or df['Bollinger Decision'].iloc[i] == 0:
signalBuy.append(np.nan)
signalSell.append(np.nan)
elif df['RSI Decision'].iloc[i] == 1 and df['Bollinger Decision'].iloc[i] == 1:
signalBuy.append(df['Close'].iloc[i])
signalSell.append(np.nan)
elif df['RSI Decision'].iloc[i] == -1 and df['Bollinger Decision'].iloc[i] == -1:
signalBuy.append(np.nan)
signalSell.append(df['Close'].iloc[i])
plt.style.use('fivethirtyeight')
fig, ax = plt.subplots()
df['RSI Buy'] = np.array(rsiBuy)
df['RSI Sell'] = np.array(rsiSell)
df['Boll Buy'] = np.array(bollBuy)
df['Boll Sell'] = np.array(bollSell)
df['Signal Buy'] = np.array(signalBuy)
df['Signal Sell'] = np.array(signalSell)
ax.plot(df['Timestamp'], df['Close'], color='royalblue')
# Plot Bollinger
ax.fill_between(df['Timestamp'], df['Bollinger High'],
df['Bollinger Low'], color='grey', alpha=0.5)
plt.grid()
ax2 = ax.twinx()
ax.plot(df['Timestamp'], df['RSI Buy'], 'g.', markersize=4)
ax.plot(df['Timestamp'], df['RSI Sell'], 'r.', markersize=4)
ax.plot(df['Timestamp'], df['Boll Buy'], 'g*', markersize=4)
ax.plot(df['Timestamp'], df['Boll Sell'], 'r*', markersize=4)
ax.plot(df['Timestamp'], df['Signal Buy'], 'g^', markersize=10)
ax.plot(df['Timestamp'], df['Signal Sell'], 'r^', markersize=10)
ax2.plot(df['Timestamp'], df['RSI Value'], lw=.75, alpha=0.5, color='purple')
plt.show()