diff --git a/src/algorithms/custom_bollinger_rsi.py b/src/algorithms/custom_bollinger_rsi.py index db2e9d6..aad84c9 100644 --- a/src/algorithms/custom_bollinger_rsi.py +++ b/src/algorithms/custom_bollinger_rsi.py @@ -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) diff --git a/src/algorithms/rsi.py b/src/algorithms/rsi.py index a373bab..9fd3e24 100644 --- a/src/algorithms/rsi.py +++ b/src/algorithms/rsi.py @@ -26,20 +26,31 @@ 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') @@ -47,12 +58,3 @@ def plot(self, prices, timestamps, **kwargs): 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() \ No newline at end of file