mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-12 19:23:55 +00:00
Add two params to select what indicators to display
This commit is contained in:
parent
662436acd2
commit
8edcef6d32
|
@ -5,12 +5,20 @@ Script to display when the bot will buy a specific pair
|
||||||
Mandatory Cli parameters:
|
Mandatory Cli parameters:
|
||||||
-p / --pair: pair to examine
|
-p / --pair: pair to examine
|
||||||
|
|
||||||
Optional Cli parameters
|
Option but recommended
|
||||||
-s / --strategy: strategy to use
|
-s / --strategy: strategy to use
|
||||||
|
|
||||||
|
|
||||||
|
Optional Cli parameters
|
||||||
-d / --datadir: path to pair backtest data
|
-d / --datadir: path to pair backtest data
|
||||||
--timerange: specify what timerange of data to use.
|
--timerange: specify what timerange of data to use.
|
||||||
-l / --live: Live, to download the latest ticker for the pair
|
-l / --live: Live, to download the latest ticker for the pair
|
||||||
-db / --db-url: Show trades stored in database
|
-db / --db-url: Show trades stored in database
|
||||||
|
|
||||||
|
|
||||||
|
Indicators recommended
|
||||||
|
Row 1: sma, ema3, ema5, ema10, ema50
|
||||||
|
Row 3: macd, rsi, fisher_rsi, mfi, slowd, slowk, fastd, fastk
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -33,20 +41,6 @@ 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
|
||||||
|
@ -59,6 +53,15 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
|
||||||
# Set the pair to audit
|
# Set the pair to audit
|
||||||
pair = args.pair
|
pair = args.pair
|
||||||
|
|
||||||
|
if pair is None:
|
||||||
|
logger.critical('Parameter --pair mandatory;. E.g --pair ETH/BTC')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
if '/' not in pair:
|
||||||
|
logger.critical('--pair format must be XXX/YYY')
|
||||||
|
exit()
|
||||||
|
|
||||||
|
|
||||||
# Set timerange to use
|
# Set timerange to use
|
||||||
timerange = Arguments.parse_timerange(args.timerange)
|
timerange = Arguments.parse_timerange(args.timerange)
|
||||||
|
|
||||||
|
@ -112,13 +115,14 @@ def plot_analyzed_dataframe(args: Namespace) -> None:
|
||||||
fig = generate_graph(
|
fig = generate_graph(
|
||||||
pair=pair,
|
pair=pair,
|
||||||
trades=trades,
|
trades=trades,
|
||||||
data=dataframe.tail(750)
|
data=dataframe.tail(750),
|
||||||
|
args=args
|
||||||
)
|
)
|
||||||
|
|
||||||
plot(fig, filename=os.path.join('user_data', 'freqtrade-plot.html'))
|
plot(fig, filename=os.path.join('user_data', 'freqtrade-plot.html'))
|
||||||
|
|
||||||
|
|
||||||
def generate_graph(pair, trades, data) -> None:
|
def generate_graph(pair, trades, data, args) -> tools.make_subplots:
|
||||||
"""
|
"""
|
||||||
Generate the graph from the data generated by Backtesting or from DB
|
Generate the graph from the data generated by Backtesting or from DB
|
||||||
:param pair: Pair to Display on the graph
|
:param pair: Pair to Display on the graph
|
||||||
|
@ -136,6 +140,9 @@ def generate_graph(pair, trades, data) -> None:
|
||||||
vertical_spacing=0.0001,
|
vertical_spacing=0.0001,
|
||||||
)
|
)
|
||||||
fig['layout'].update(title=pair)
|
fig['layout'].update(title=pair)
|
||||||
|
fig['layout']['yaxis1'].update(title='Price')
|
||||||
|
fig['layout']['yaxis2'].update(title='Volume')
|
||||||
|
fig['layout']['yaxis3'].update(title='Other')
|
||||||
|
|
||||||
# Common information
|
# Common information
|
||||||
candles = go.Candlestick(
|
candles = go.Candlestick(
|
||||||
|
@ -220,21 +227,11 @@ def generate_graph(pair, trades, data) -> None:
|
||||||
fig.append_trace(bb_lower, 1, 1)
|
fig.append_trace(bb_lower, 1, 1)
|
||||||
fig.append_trace(bb_upper, 1, 1)
|
fig.append_trace(bb_upper, 1, 1)
|
||||||
|
|
||||||
if TO_DISPLAY['sma'] and 'sma' in data:
|
fig = generate_row(fig=fig, row=1, raw_indicators=args.indicators1, data=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(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']['yaxis1'].update(title='Price')
|
|
||||||
|
|
||||||
# Row 2
|
# Row 2
|
||||||
volume = go.Bar(
|
volume = go.Bar(
|
||||||
|
@ -243,61 +240,33 @@ def generate_graph(pair, trades, data) -> None:
|
||||||
name='Volume'
|
name='Volume'
|
||||||
)
|
)
|
||||||
fig.append_trace(volume, 2, 1)
|
fig.append_trace(volume, 2, 1)
|
||||||
fig['layout']['yaxis2'].update(title='Volume')
|
|
||||||
|
|
||||||
# Row 3 (On Row 3, we can only display one indicator)
|
# Row 3
|
||||||
if TO_DISPLAY['macd'] and 'macd' in data and 'macdsignal' in data:
|
fig = generate_row(fig=fig, row=3, raw_indicators=args.indicators2, data=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
|
return fig
|
||||||
|
|
||||||
|
|
||||||
def generate_scattergl(index, name, data) -> go.Scattergl:
|
def generate_row(fig, row, raw_indicators, data) -> tools.make_subplots:
|
||||||
"""
|
"""
|
||||||
Generate a Scattergl element
|
Generator all the indicator selected by the user for a specific row
|
||||||
: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(
|
for indicator in raw_indicators.split(','):
|
||||||
x=data['date'],
|
if indicator in data:
|
||||||
y=data[index],
|
scattergl = go.Scattergl(
|
||||||
name=name
|
x=data['date'],
|
||||||
)
|
y=data[indicator],
|
||||||
|
name=indicator
|
||||||
|
)
|
||||||
|
fig.append_trace(scattergl, row, 1)
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
'Indicator "%s" ignored. Reason: This indicator is not found '
|
||||||
|
'in your strategy.',
|
||||||
|
indicator
|
||||||
|
)
|
||||||
|
|
||||||
|
return fig
|
||||||
|
|
||||||
|
|
||||||
def plot_parse_args(args: List[str]) -> Namespace:
|
def plot_parse_args(args: List[str]) -> Namespace:
|
||||||
|
@ -308,6 +277,24 @@ def plot_parse_args(args: List[str]) -> Namespace:
|
||||||
"""
|
"""
|
||||||
arguments = Arguments(args, 'Graph dataframe')
|
arguments = Arguments(args, 'Graph dataframe')
|
||||||
arguments.scripts_options()
|
arguments.scripts_options()
|
||||||
|
arguments.parser.add_argument(
|
||||||
|
'--indicators1',
|
||||||
|
help='Set indicators from your strategy you want in the first row of the graph. Separate '
|
||||||
|
'them with a coma. E.g: ema3,ema5 (default: %(default)s)',
|
||||||
|
type=str,
|
||||||
|
default='sma,ema3,ema5',
|
||||||
|
dest='indicators1',
|
||||||
|
)
|
||||||
|
|
||||||
|
arguments.parser.add_argument(
|
||||||
|
'--indicators2',
|
||||||
|
help='Set indicators from your strategy you want in the third row of the graph. Separate '
|
||||||
|
'them with a coma. E.g: fastd,fastk (default: %(default)s)',
|
||||||
|
type=str,
|
||||||
|
default='macd',
|
||||||
|
dest='indicators2',
|
||||||
|
)
|
||||||
|
|
||||||
arguments.common_args_parser()
|
arguments.common_args_parser()
|
||||||
arguments.optimizer_shared_options(arguments.parser)
|
arguments.optimizer_shared_options(arguments.parser)
|
||||||
arguments.backtesting_options(arguments.parser)
|
arguments.backtesting_options(arguments.parser)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user