diff --git a/freqtrade/configuration/arguments.py b/freqtrade/configuration/arguments.py index 2c76afa8f..61c899f93 100644 --- a/freqtrade/configuration/arguments.py +++ b/freqtrade/configuration/arguments.py @@ -119,6 +119,7 @@ class Arguments(object): hyperopt_cmd.set_defaults(func=start_hyperopt) self._build_args(optionlist=ARGS_HYPEROPT, parser=hyperopt_cmd) + # Create userdir subcommand create_userdir_cmd = subparsers.add_parser('create-userdir', help="Create user-data directory.") create_userdir_cmd.set_defaults(func=start_create_userdir) @@ -139,3 +140,12 @@ class Arguments(object): ) download_data_cmd.set_defaults(func=start_download_data) self._build_args(optionlist=ARGS_DOWNLOAD_DATA, parser=download_data_cmd) + + # Add Plotting subcommand + from freqtrade.plot.plot_utils import start_plot_dataframe + plot_dataframe_cmd = subparsers.add_parser( + 'plot-dataframe', + help='Plot candles with indicators.' + ) + plot_dataframe_cmd.set_defaults(func=start_plot_dataframe) + self._build_args(optionlist=ARGS_PLOT_DATAFRAME, parser=plot_dataframe_cmd) diff --git a/freqtrade/plot/plot_utils.py b/freqtrade/plot/plot_utils.py new file mode 100644 index 000000000..2a06ca185 --- /dev/null +++ b/freqtrade/plot/plot_utils.py @@ -0,0 +1,15 @@ +from argparse import Namespace + +from freqtrade.state import RunMode +from freqtrade.utils import setup_utils_configuration + + +def start_plot_dataframe(args: Namespace) -> None: + """ + Plotting dataframe + """ + # Import here to avoid errors if plot-dependencies are not installed. + from freqtrade.plot.plotting import analyse_and_plot_pairs + config = setup_utils_configuration(args, RunMode.OTHER) + + analyse_and_plot_pairs(config) diff --git a/freqtrade/plot/plotting.py b/freqtrade/plot/plotting.py index 9dc6b9551..f50987972 100644 --- a/freqtrade/plot/plotting.py +++ b/freqtrade/plot/plotting.py @@ -1,13 +1,14 @@ import logging from pathlib import Path -from typing import Dict, List, Optional +from typing import Any, Dict, List, Optional import pandas as pd from freqtrade.configuration import TimeRange from freqtrade.data import history from freqtrade.data.btanalysis import (combine_tickers_with_mean, - create_cum_profit, load_trades) + create_cum_profit, + extract_trades_of_period, load_trades) from freqtrade.exchange import Exchange from freqtrade.resolvers import ExchangeResolver, StrategyResolver @@ -321,3 +322,44 @@ def store_plot_file(fig, filename: str, directory: Path, auto_open: bool = False plot(fig, filename=str(_filename), auto_open=auto_open) logger.info(f"Stored plot as {_filename}") + + +def analyse_and_plot_pairs(config: Dict[str, Any]): + """ + From configuration provided + - Initializes plot-script + -Get tickers data + -Generate Dafaframes populated with indicators and signals + -Load trades excecuted on same periods + -Generate Plotly plot objects + -Generate plot files + :return: None + """ + plot_elements = init_plotscript(config) + trades = plot_elements['trades'] + strategy = plot_elements["strategy"] + + pair_counter = 0 + for pair, data in plot_elements["tickers"].items(): + pair_counter += 1 + logger.info("analyse pair %s", pair) + tickers = {} + tickers[pair] = data + + dataframe = strategy.analyze_ticker(tickers[pair], {'pair': pair}) + + trades_pair = trades.loc[trades['pair'] == pair] + trades_pair = extract_trades_of_period(dataframe, trades_pair) + + fig = generate_candlestick_graph( + pair=pair, + data=dataframe, + trades=trades_pair, + indicators1=config["indicators1"].split(","), + indicators2=config["indicators2"].split(",") + ) + + store_plot_file(fig, filename=generate_plot_filename(pair, config['ticker_interval']), + directory=config['user_data_dir'] / "plot") + + logger.info('End of ploting process %s plots generated', pair_counter) diff --git a/freqtrade/utils.py b/freqtrade/utils.py index 56e60ec82..07daaf074 100644 --- a/freqtrade/utils.py +++ b/freqtrade/utils.py @@ -108,6 +108,3 @@ def start_download_data(args: Namespace) -> None: logger.info( f"Pairs [{','.join(pairs_not_available)}] not available " f"on exchange {config['exchange']['name']}.") - - # configuration.resolve_pairs_list() - print(config)