mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-12 19:23:55 +00:00
Add more indicators
This commit is contained in:
parent
64504e6777
commit
1c75bfdddd
|
@ -33,6 +33,20 @@ logger = logging.getLogger(__name__)
|
||||||
_CONF: Dict[str, Any] = {}
|
_CONF: Dict[str, Any] = {}
|
||||||
|
|
||||||
|
|
||||||
|
# Update the global variable TO_DISPLAY to select which indicator you want to display
|
||||||
|
TO_DISPLAY = {
|
||||||
|
'sma': False, # On Row 1
|
||||||
|
'ema': True, # On Row 1
|
||||||
|
|
||||||
|
'macd': True, # On Row 3
|
||||||
|
'rsi': False, # On Row 3
|
||||||
|
'fisher_rsi': False, # On Row 3
|
||||||
|
'mfi': False, # On Row 3
|
||||||
|
'slow': False, # On Row 3
|
||||||
|
'fast': False # On Row 3
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def plot_analyzed_dataframe(args: Namespace) -> None:
|
def plot_analyzed_dataframe(args: Namespace) -> None:
|
||||||
"""
|
"""
|
||||||
Calls analyze() and plots the returned dataframe
|
Calls analyze() and plots the returned dataframe
|
||||||
|
@ -88,7 +102,6 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
|
||||||
persistence.init(_CONF, engine)
|
persistence.init(_CONF, engine)
|
||||||
trades = Trade.query.filter(Trade.pair.is_(pair)).all()
|
trades = Trade.query.filter(Trade.pair.is_(pair)).all()
|
||||||
|
|
||||||
|
|
||||||
dataframes = analyze.tickerdata_to_dataframe(tickers)
|
dataframes = analyze.tickerdata_to_dataframe(tickers)
|
||||||
dataframe = dataframes[pair]
|
dataframe = dataframes[pair]
|
||||||
dataframe = analyze.populate_buy_trend(dataframe)
|
dataframe = analyze.populate_buy_trend(dataframe)
|
||||||
|
@ -97,15 +110,35 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
|
||||||
if len(dataframe.index) > 750:
|
if len(dataframe.index) > 750:
|
||||||
logger.warning('Ticker contained more than 750 candles, clipping.')
|
logger.warning('Ticker contained more than 750 candles, clipping.')
|
||||||
|
|
||||||
generate_graph(
|
fig = generate_graph(
|
||||||
pair=pair,
|
pair=pair,
|
||||||
trades=trades,
|
trades=trades,
|
||||||
data=dataframe.tail(750)
|
data=dataframe.tail(750)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
plot(fig, filename=os.path.join('user_data', 'freqtrade-plot.html'))
|
||||||
|
|
||||||
def generate_graph(pair, trades, data):
|
|
||||||
|
|
||||||
|
def generate_graph(pair, trades, data) -> None:
|
||||||
|
"""
|
||||||
|
Generate the graph from the data generated by Backtesting or from DB
|
||||||
|
:param pair: Pair to Display on the graph
|
||||||
|
:param trades: All trades created
|
||||||
|
:param data: Dataframe
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Define the graph
|
||||||
|
fig = tools.make_subplots(
|
||||||
|
rows=3,
|
||||||
|
cols=1,
|
||||||
|
shared_xaxes=True,
|
||||||
|
row_width=[1, 1, 4],
|
||||||
|
vertical_spacing=0.0001,
|
||||||
|
)
|
||||||
|
fig['layout'].update(title=pair)
|
||||||
|
|
||||||
|
# Common information
|
||||||
candles = go.Candlestick(
|
candles = go.Candlestick(
|
||||||
x=data.date,
|
x=data.date,
|
||||||
open=data.open,
|
open=data.open,
|
||||||
|
@ -167,51 +200,105 @@ def generate_graph(pair, trades, data):
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
bb_lower = go.Scatter(
|
|
||||||
x=data.date,
|
|
||||||
y=data.bb_lowerband,
|
|
||||||
name='BB lower',
|
|
||||||
line={'color': "transparent"},
|
|
||||||
)
|
|
||||||
bb_upper = go.Scatter(
|
|
||||||
x=data.date,
|
|
||||||
y=data.bb_upperband,
|
|
||||||
name='BB upper',
|
|
||||||
fill="tonexty",
|
|
||||||
fillcolor="rgba(0,176,246,0.2)",
|
|
||||||
line={'color': "transparent"},
|
|
||||||
)
|
|
||||||
macd = go.Scattergl(x=data['date'], y=data['macd'], name='MACD')
|
|
||||||
macdsignal = go.Scattergl(x=data['date'], y=data['macdsignal'], name='MACD signal')
|
|
||||||
volume = go.Bar(x=data['date'], y=data['volume'], name='Volume')
|
|
||||||
|
|
||||||
fig = tools.make_subplots(
|
|
||||||
rows=3,
|
|
||||||
cols=1,
|
|
||||||
shared_xaxes=True,
|
|
||||||
row_width=[1, 1, 4],
|
|
||||||
vertical_spacing=0.0001,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Row 1
|
# Row 1
|
||||||
|
|
||||||
fig.append_trace(candles, 1, 1)
|
fig.append_trace(candles, 1, 1)
|
||||||
fig.append_trace(bb_lower, 1, 1)
|
|
||||||
fig.append_trace(bb_upper, 1, 1)
|
if 'bb_lowerband' in data and 'bb_upperband' in data:
|
||||||
|
bb_lower = go.Scatter(
|
||||||
|
x=data.date,
|
||||||
|
y=data.bb_lowerband,
|
||||||
|
name='BB lower',
|
||||||
|
line={'color': "transparent"},
|
||||||
|
)
|
||||||
|
bb_upper = go.Scatter(
|
||||||
|
x=data.date,
|
||||||
|
y=data.bb_upperband,
|
||||||
|
name='BB upper',
|
||||||
|
fill="tonexty",
|
||||||
|
fillcolor="rgba(0,176,246,0.2)",
|
||||||
|
line={'color': "transparent"},
|
||||||
|
)
|
||||||
|
fig.append_trace(bb_lower, 1, 1)
|
||||||
|
fig.append_trace(bb_upper, 1, 1)
|
||||||
|
|
||||||
|
if TO_DISPLAY['sma'] and 'sma' in data:
|
||||||
|
sma = generate_scattergl(index='sma', name='SMA', data=data)
|
||||||
|
fig.append_trace(sma, 1, 1)
|
||||||
|
|
||||||
|
if TO_DISPLAY['ema'] and 'ema10' in data and 'ema50' in data:
|
||||||
|
ema10 = generate_scattergl(index='ema10', name='EMA10', data=data)
|
||||||
|
ema50 = generate_scattergl(index='ema50', name='EMA50', data=data)
|
||||||
|
fig.append_trace(ema10, 1, 1)
|
||||||
|
fig.append_trace(ema50, 1, 1)
|
||||||
|
|
||||||
fig.append_trace(buys, 1, 1)
|
fig.append_trace(buys, 1, 1)
|
||||||
fig.append_trace(sells, 1, 1)
|
fig.append_trace(sells, 1, 1)
|
||||||
fig.append_trace(volume, 2, 1)
|
|
||||||
fig.append_trace(macd, 3, 1)
|
|
||||||
fig.append_trace(macdsignal, 3, 1)
|
|
||||||
fig.append_trace(trade_buys, 1, 1)
|
fig.append_trace(trade_buys, 1, 1)
|
||||||
fig.append_trace(trade_sells, 1, 1)
|
fig.append_trace(trade_sells, 1, 1)
|
||||||
|
|
||||||
fig['layout'].update(title=pair)
|
|
||||||
fig['layout']['yaxis1'].update(title='Price')
|
fig['layout']['yaxis1'].update(title='Price')
|
||||||
fig['layout']['yaxis2'].update(title='Volume')
|
|
||||||
fig['layout']['yaxis3'].update(title='MACD')
|
|
||||||
|
|
||||||
plot(fig, filename=os.path.join('user_data', 'freqtrade-plot.html'))
|
# Row 2
|
||||||
|
volume = go.Bar(
|
||||||
|
x=data['date'],
|
||||||
|
y=data['volume'],
|
||||||
|
name='Volume'
|
||||||
|
)
|
||||||
|
fig.append_trace(volume, 2, 1)
|
||||||
|
fig['layout']['yaxis2'].update(title='Volume')
|
||||||
|
|
||||||
|
# Row 3 (On Row 3, we can only display one indicator)
|
||||||
|
if TO_DISPLAY['macd'] and 'macd' in data and 'macdsignal' in data:
|
||||||
|
macd = generate_scattergl(index='macd', name='MACD', data=data)
|
||||||
|
macdsignal = generate_scattergl(index='macdsignal', name='MACD Signal', data=data)
|
||||||
|
fig.append_trace(macd, 3, 1)
|
||||||
|
fig.append_trace(macdsignal, 3, 1)
|
||||||
|
fig['layout']['yaxis3'].update(title='MACD')
|
||||||
|
|
||||||
|
elif TO_DISPLAY['fast'] and 'fastd' in data and 'fastk' in data:
|
||||||
|
fastd = generate_scattergl(index='fastd', name='fastd', data=data)
|
||||||
|
fastk = generate_scattergl(index='fastk', name='fastk', data=data)
|
||||||
|
fig.append_trace(fastd, 3, 1)
|
||||||
|
fig.append_trace(fastk, 3, 1)
|
||||||
|
fig['layout']['yaxis3'].update(title='Stoch Fast')
|
||||||
|
|
||||||
|
elif TO_DISPLAY['slow'] and 'slowd' in data and 'slowk' in data:
|
||||||
|
slowd = generate_scattergl(index='slowd', name='slowd', data=data)
|
||||||
|
slowk = generate_scattergl(index='slowk', name='slowk', data=data)
|
||||||
|
fig.append_trace(slowd, 3, 1)
|
||||||
|
fig.append_trace(slowk, 3, 1)
|
||||||
|
fig['layout']['yaxis3'].update(title='Stoch Slow')
|
||||||
|
|
||||||
|
elif TO_DISPLAY['rsi'] and 'rsi' in data:
|
||||||
|
rsi = generate_scattergl(index='rsi', name='RSI', data=data)
|
||||||
|
fig.append_trace(rsi, 3, 1)
|
||||||
|
fig['layout']['yaxis3'].update(title='RSI')
|
||||||
|
|
||||||
|
elif TO_DISPLAY['mfi'] and 'mfi' in data:
|
||||||
|
mfi = generate_scattergl(index='mfi', name='MFI', data=data)
|
||||||
|
fig.append_trace(mfi, 3, 1)
|
||||||
|
fig['layout']['yaxis3'].update(title='MFI')
|
||||||
|
|
||||||
|
elif TO_DISPLAY['fisher_rsi'] and 'fisher_rsi' in data:
|
||||||
|
fisher_rsi = generate_scattergl(index='fisher_rsi', name='Fisher RSI', data=data)
|
||||||
|
fig.append_trace(fisher_rsi, 3, 1)
|
||||||
|
fig['layout']['yaxis3'].update(title='Fisher RSI')
|
||||||
|
|
||||||
|
return fig
|
||||||
|
|
||||||
|
|
||||||
|
def generate_scattergl(index, name, data) -> go.Scattergl:
|
||||||
|
"""
|
||||||
|
Generate a Scattergl element
|
||||||
|
:param index: code of the Indicator to generate
|
||||||
|
:param name: Name that will be display in the graph legend
|
||||||
|
:param data: Dataframe
|
||||||
|
:return: Scattergl
|
||||||
|
"""
|
||||||
|
return go.Scattergl(
|
||||||
|
x=data['date'],
|
||||||
|
y=data[index],
|
||||||
|
name=name
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def plot_parse_args(args: List[str]) -> Namespace:
|
def plot_parse_args(args: List[str]) -> Namespace:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user