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

Commit

Permalink
Rsi plot fix on custom_bollinger_rsi
Browse files Browse the repository at this point in the history
Merge pull request #74 from auto-trading-temp-name/algorithms
  • Loading branch information
CelestialCrafter authored Jan 13, 2024
2 parents a334fec + 4cf2e70 commit 118fa38
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/algorithms/custom_bollinger_rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def plot(self, prices, timestamps, **kwargs):

plt.subplot(gs[-1, :])
rsi = RSI(window_size=self.rsi_window_size)
rsi.plot(prices, timestamps)
rsi.plot(prices, timestamps, custom_algorithm_plot=True)
plt.subplot(gs[-2, :])
Bollinger_Bands = BollingerBands(window_size=self.bollinger_bands_window_size)
Bollinger_Bands.plot(prices, timestamps)
36 changes: 19 additions & 17 deletions src/algorithms/rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,35 @@ def signal(self, _, data):

return 'no_action', 0

def plot(self, prices, timestamps, **kwargs):
gs = GridSpec(3, 1, figure=plt.gcf())

plt.subplot(gs[0, :])
def plot(self, prices, timestamps, custom_algorithm_plot=False,**kwargs):
rsi_line = self.algorithm(prices, **kwargs)

plt.plot(timestamps, rsi_line, color=colors.primary(), label='RSI')

# Thresholds
# Thresholds
upper = np.full(rsi_line.shape, self.high)
lower = np.full(rsi_line.shape, self.low)
sell_condition = rsi_line >= self.high
buy_condition = rsi_line <= self.low

if not custom_algorithm_plot:
gs = GridSpec(3, 1, figure=plt.gcf())
plt.subplot(gs[0, :])
plt.plot(timestamps, prices, color=colors.primary(), label='price')
plt.scatter(timestamps[sell_condition], prices[sell_condition], color=colors.sell(), label='Sell conditions')
plt.scatter(timestamps[buy_condition], prices[buy_condition], color=colors.buy(), label='Buy conditions')

plt.title("Time-signals")
plt.xlabel("Time")
plt.ylabel("Price")
plt.legend()

plt.subplot(gs[1, :])


plt.plot(timestamps, rsi_line, color=colors.primary(), label='RSI')

plt.fill_between(timestamps, upper, lower, color='grey', alpha=0.3)
plt.plot(timestamps, upper, linestyle='dashed', color=colors.sell(), label='RSI high band')
plt.plot(timestamps, lower, linestyle='dashed', color=colors.buy(), label='RSI low band')
plt.title("RSI Plots")
plt.xlabel("Time")
plt.ylabel("RSI LINE")
plt.legend()

plt.subplot(gs[1, :])
plt.plot(timestamps, prices, color=colors.primary(), label='price')
plt.scatter(timestamps[sell_condition], prices[sell_condition], color=colors.sell(), label='Sell conditions')
plt.scatter(timestamps[buy_condition], prices[buy_condition], color=colors.buy(), label='Buy conditions')
plt.title("Time-signals")
plt.xlabel("Time")
plt.ylabel("Price")
plt.legend()

0 comments on commit 118fa38

Please sign in to comment.