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.
- Loading branch information
1 parent
b08ee68
commit 9a6d7e4
Showing
1 changed file
with
11 additions
and
49 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 |
---|---|---|
@@ -1,61 +1,23 @@ | ||
import json | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
from price import get_prices | ||
from algorithms.bollinger_bands import algorithm as boillinger_bands | ||
from algorithms.rsi import algorithm as rsi | ||
from algorithms.macd import algorithm as macd | ||
from plots.bollinger_bands import plot as boillinger_bands | ||
from plots.rsi import plot as rsi | ||
|
||
# @TODO split plotting off into another algorithm function. def plot(subplot, prices, data) | ||
config = json.load(open('config.json', 'r')) | ||
prices = get_prices(address=config['address'] if 'address' in config else None) | ||
|
||
prices = get_prices('ETH/USD', interval=1440) | ||
|
||
upper_band, lower_band, middle_band = boillinger_bands(prices) | ||
rsi_data = rsi(prices) | ||
macd, signal = macd(prices) | ||
|
||
bb_indicies = np.arange(0, upper_band.shape[0]) | ||
rsi_indicies = np.arange(0, rsi_data.shape[0]) | ||
macd_indicies = np.arange(0, macd.shape[0]) | ||
|
||
## Boillinger Bands | ||
# RSI | ||
plt.subplot(221) | ||
rsi(prices) | ||
|
||
bb_sliced_prices = prices[:upper_band.shape[0]] | ||
plt.fill_between(bb_indicies, upper_band, lower_band, color='grey', alpha=0.3) | ||
|
||
# Price/SMA | ||
plt.plot(bb_indicies, bb_sliced_prices, color='plum') | ||
plt.plot(bb_indicies, middle_band, color='mediumpurple') | ||
|
||
# Buy/Sell Signals | ||
bb_upper_condition = bb_sliced_prices >= upper_band | ||
bb_lower_condition = bb_sliced_prices <= lower_band | ||
|
||
plt.scatter(bb_indicies[bb_upper_condition], bb_sliced_prices[bb_upper_condition], color='lightcoral') | ||
plt.scatter(bb_indicies[bb_lower_condition], bb_sliced_prices[bb_lower_condition], color='darkturquoise') | ||
|
||
## RSI | ||
# Boillinger Bands | ||
plt.subplot(222) | ||
plt.plot(rsi_indicies, rsi_data, color='plum') | ||
|
||
# Thresholds | ||
rsi_upper = np.full(rsi_data.shape, 70) | ||
rsi_lower = np.full(rsi_data.shape, 30) | ||
|
||
plt.fill_between(rsi_indicies, rsi_upper, rsi_lower, color='grey', alpha=0.3) | ||
plt.plot(rsi_indicies, rsi_upper, linestyle='dashed', color='lightcoral') | ||
plt.plot(rsi_indicies, rsi_lower, linestyle='dashed', color='darkturquoise') | ||
boillinger_bands(prices) | ||
|
||
## MACD | ||
# Prices | ||
plt.subplot(223) | ||
|
||
macd_upper_condition = macd > signal | ||
macd_lower_condition = macd < signal | ||
|
||
plt.scatter(macd_indicies[macd_upper_condition], signal[macd_upper_condition], color='darkturquoise') | ||
plt.scatter(macd_indicies[macd_lower_condition], signal[macd_lower_condition], color='lightcoral') | ||
|
||
plt.plot(signal, color='plum') | ||
plt.plot(macd, color='mediumpurple') | ||
plt.plot(np.arange(0, prices.shape[0]), prices) | ||
|
||
plt.show() |