only buy when parabolic sar shows bullish trend

This commit is contained in:
Janne Sinivirta 2017-09-01 21:40:12 +03:00
parent 330b67b857
commit 072593c756

View File

@ -5,6 +5,8 @@ import arrow
import requests import requests
from pandas.io.json import json_normalize from pandas.io.json import json_normalize
from stockstats import StockDataFrame from stockstats import StockDataFrame
import talib.abstract as ta
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
@ -41,6 +43,8 @@ def get_ticker_dataframe(pair):
} for t in sorted(data['result'], key=lambda k: k['T']) if arrow.get(t['T']) > minimum_date] } for t in sorted(data['result'], key=lambda k: k['T']) if arrow.get(t['T']) > minimum_date]
dataframe = StockDataFrame(json_normalize(data)) dataframe = StockDataFrame(json_normalize(data))
dataframe['sar'] = ta.SAR(dataframe, 0.02, 0.2)
# calculate StochRSI # calculate StochRSI
window = 14 window = 14
rsi = dataframe['rsi_{}'.format(window)] rsi = dataframe['rsi_{}'.format(window)]
@ -66,7 +70,8 @@ def populate_trends(dataframe):
""" """
dataframe.loc[ dataframe.loc[
(dataframe['stochrsi'] < 0.20) (dataframe['stochrsi'] < 0.20)
& (dataframe['macd'] > dataframe['macds']), & (dataframe['macd'] > dataframe['macds'])
& (dataframe['close'] > dataframe['sar']),
'underpriced' 'underpriced'
] = 1 ] = 1
dataframe.loc[dataframe['underpriced'] == 1, 'buy'] = dataframe['close'] dataframe.loc[dataframe['underpriced'] == 1, 'buy'] = dataframe['close']
@ -110,8 +115,9 @@ def plot_dataframe(dataframe, pair):
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True) fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True)
fig.suptitle(pair, fontsize=14, fontweight='bold') fig.suptitle(pair, fontsize=14, fontweight='bold')
ax1.plot(dataframe.index.values, dataframe['close'], label='close') ax1.plot(dataframe.index.values, dataframe['close'], label='close')
ax1.plot(dataframe.index.values, dataframe['close_30_ema'], label='EMA(60)') # ax1.plot(dataframe.index.values, dataframe['close_30_ema'], label='EMA(60)')
ax1.plot(dataframe.index.values, dataframe['close_90_ema'], label='EMA(120)') # ax1.plot(dataframe.index.values, dataframe['close_90_ema'], label='EMA(120)')
ax1.plot(dataframe.index.values, dataframe['sar'], 'rx', label='SAR')
# ax1.plot(dataframe.index.values, dataframe['sell'], 'ro', label='sell') # ax1.plot(dataframe.index.values, dataframe['sell'], 'ro', label='sell')
ax1.plot(dataframe.index.values, dataframe['buy'], 'bo', label='buy') ax1.plot(dataframe.index.values, dataframe['buy'], 'bo', label='buy')
ax1.legend() ax1.legend()