This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from auto-trading-temp-name/algorithms
custom_bollinger_rsi, and price plots
- Loading branch information
Showing
4 changed files
with
61 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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) | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
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): | ||
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()) | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters