Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

Commit

Permalink
update plotting for custom_bollinger_rsi
Browse files Browse the repository at this point in the history
  • Loading branch information
CelestialCrafter committed Nov 17, 2023
1 parent fc59c88 commit e276f8a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 27 deletions.
24 changes: 11 additions & 13 deletions algorithms/custom_bollinger_rsi.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
from bollinger_bands import algorithm as bollinger_bands
from rsi import algorithm as rsi
from .bollinger_bands import algorithm as bollinger_bands
from .rsi import algorithm as rsi

def algorithm(prices, rsi_window=13, bollinger_window=30):
upper_band, lower_band, middle_band = bollinger_bands(prices, window_size=bollinger_window)
rsi_line = rsi(prices, window_size=rsi_window)
upper_band, lower_band, middle_band = bollinger_bands(prices, window_size=bollinger_window)
rsi_line = rsi(prices, window_size=rsi_window)

return upper_band, lower_band, middle_band, rsi_line
return upper_band, lower_band, middle_band, rsi_line

def signal(prices, data):
price = prices[-1]
upper_band, lower_band, middle_band , rsi_line = data

if price >= lower_band[-1] and 30 >= rsi_line[-1]:
return 'buy', 0.5

if price >= upper_band[-1] and rsi_line[-1] >= 70:
return 'sell', 1
price = prices[-1]
upper_band, lower_band, middle_band, rsi_line = data

if price >= lower_band[-1] and 30 >= rsi_line[-1]:
return 'buy', 0.5

if price >= upper_band[-1] and rsi_line[-1] >= 70:
return 'sell', 1
4 changes: 3 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"pair": "ETH/USD"
}
25 changes: 21 additions & 4 deletions plots/custom_bollinger_rsi.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,30 @@
import numpy as np
import matplotlib.pyplot as plt
from plots.bollinger_bands import plot as bollinger_bands
from matplotlib.gridspec import GridSpec
from algorithms.custom_bollinger_rsi import algorithm as custom_bollinger_rsi
from plots.rsi import plot as rsi
from plots.bollinger_bands import plot as bollinger_bands
import plots.colors as colors

def plot(prices):
plt.subplot(211)
bollinger_bands(prices)
gs = GridSpec(2, 2, figure=plt.gcf())

plt.subplot(gs[0, :])
indicies = np.arange(0, prices.shape[0])
plt.plot(indicies, prices, color=colors.mainline())

plt.subplot(212)
upper_band, lower_band, middle_band, rsi_line = custom_bollinger_rsi(prices)
sliced_prices = prices[:min(upper_band.shape[0], rsi_line.shape[0])]
indicies = np.arange(0, indicies.shape[0])

upper_condition = (prices >= upper_band) & (rsi_line >= 70)
lower_condition = (prices >= lower_band) & (30 >= rsi_line)
plt.scatter(indicies[upper_condition], sliced_prices[upper_condition], color=colors.upper())
plt.scatter(indicies[lower_condition], sliced_prices[lower_condition], color=colors.lower())

plt.subplot(gs[-1, :1])
rsi(prices)
plt.subplot(gs[-1, 1:2])
bollinger_bands(prices)

return plt
10 changes: 5 additions & 5 deletions plots/rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import plots.colors as colors

def plot(prices):
data = rsi(prices)
indicies = np.arange(0, data.shape[0])
rsi_line = rsi(prices)
indicies = np.arange(0, rsi_line.shape[0])

plt.plot(indicies, data, color=colors.mainline())
plt.plot(indicies, rsi_line, color=colors.mainline())

# Thresholds
upper = np.full(data.shape, 70)
lower = np.full(data.shape, 30)
upper = np.full(rsi_line.shape, 70)
lower = np.full(rsi_line.shape, 30)

plt.fill_between(indicies, upper, lower, color='grey', alpha=0.3)
plt.plot(indicies, upper, linestyle='dashed', color=colors.upper())
Expand Down
11 changes: 7 additions & 4 deletions views/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ def plot(algorithm):
return 'Invalid Algorithm', 404
import_module(f'plots.{algorithm}').plot(prices)

ax = plt.gca()
ax.tick_params(color=colors.outline(), labelcolor=colors.outline())
for spine in ax.spines.values():
spine.set_edgecolor(colors.outline())
axes = plt.gcf().get_axes()
for axis in axes:
axis.tick_params(color=colors.outline(), labelcolor=colors.outline())
for spine in axis.spines.values():
spine.set_edgecolor(colors.outline())

plt.tight_layout()

# Save plot into buffer instead of the FS
svg_buffer = io.StringIO()
Expand Down

0 comments on commit e276f8a

Please sign in to comment.