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

Commit

Permalink
rsi sell/buy points && plot price fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fou3fou3 committed Dec 30, 2023
1 parent 1959925 commit 82c5bcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions algorithms/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import plots.colors as colors

class Algorithm:

def plot(prices, timestamps):
def __init__(self) -> None:
pass
def plot(self, prices, timestamps):
plt.plot(timestamps, prices, color=colors.primary())
return plt
11 changes: 11 additions & 0 deletions algorithms/rsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import numpy as np
import matplotlib.pyplot as plt
import plots.colors as colors
from matplotlib.gridspec import GridSpec

class Algorithm:

Expand All @@ -26,14 +27,24 @@ 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, :])
rsi_line = self.algorithm(prices, **kwargs)

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

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

plt.fill_between(timestamps, upper, lower, color='grey', alpha=0.3)
plt.plot(timestamps, upper, linestyle='dashed', color=colors.upper())
plt.plot(timestamps, lower, linestyle='dashed', color=colors.lower())

plt.subplot(gs[1, :])
plt.plot(timestamps, prices, color=colors.primary())
plt.scatter(timestamps[upper_condition], prices[upper_condition], color=colors.upper())
plt.scatter(timestamps[lower_condition], prices[lower_condition], color=colors.lower())

0 comments on commit 82c5bcd

Please sign in to comment.