diff --git a/en/develop/advanced-backtesting/index.html b/en/develop/advanced-backtesting/index.html index 346fdfab7..3d8f1c3c5 100644 --- a/en/develop/advanced-backtesting/index.html +++ b/en/develop/advanced-backtesting/index.html @@ -1164,6 +1164,15 @@ + + +
  • + + + Filtering Indicators Based on Entry or Exit Signals + + +
  • @@ -1644,6 +1653,15 @@ + + +
  • + + + Filtering Indicators Based on Entry or Exit Signals + + +
  • @@ -1844,6 +1862,18 @@ to distinguish the values at the entry and exit points of the trade.

    profit_ratio, profit_abs, exit_reason,initial_stop_loss_abs, initial_stop_loss_ratio, stop_loss_abs, stop_loss_ratio, min_rate, max_rate, is_open, enter_tag, leverage, is_short, open_timestamp, close_timestamp and orders

    +

    Filtering Indicators Based on Entry or Exit Signals

    +

    The --indicator-list option, by default, displays indicator values for both entry and exit signals. To filter the indicator values exclusively for entry signals, you can use the --entry-only argument. Similarly, to display indicator values only at exit signals, use the --exit-only argument.

    +

    Example: Display indicator values at entry signals:

    +
    freqtrade backtesting-analysis -c user_data/config.json --analysis-groups 0 --indicator-list chikou_span tenkan_sen --entry-only
    +
    +

    Example: Display indicator values at exit signals:

    +
    freqtrade backtesting-analysis -c user_data/config.json --analysis-groups 0 --indicator-list chikou_span tenkan_sen --exit-only
    +
    +
    +

    Note

    +

    When using these filters, the indicator names will not be suffixed with (entry) or (exit).

    +

    Filtering the trade output by date

    To show only trades between dates within your backtested timerange, supply the usual timerange option in YYYYMMDD-[YYYYMMDD] format:

    --timerange : Timerange to filter output trades, start date inclusive, end date exclusive. e.g. 20220101-20221231
    diff --git a/en/develop/search/search_index.json b/en/develop/search/search_index.json
    index d7face043..b6410e25d 100644
    --- a/en/develop/search/search_index.json
    +++ b/en/develop/search/search_index.json
    @@ -1 +1 @@
    -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":"

    Star Fork Download

    "},{"location":"#introduction","title":"Introduction","text":"

    Freqtrade is a free and open source crypto trading bot written in Python. It is designed to support all major exchanges and be controlled via Telegram or webUI. It contains backtesting, plotting and money management tools as well as strategy optimization by machine learning.

    DISCLAIMER

    This software is for educational purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.

    Always start by running a trading bot in Dry-run and do not engage money before you understand how it works and what profit/loss you should expect.

    We strongly recommend you to have basic coding skills and Python knowledge. Do not hesitate to read the source code and understand the mechanisms of this bot, algorithms and techniques implemented in it.

    "},{"location":"#features","title":"Features","text":"
    • Develop your Strategy: Write your strategy in python, using pandas. Example strategies to inspire you are available in the strategy repository.
    • Download market data: Download historical data of the exchange and the markets your may want to trade with.
    • Backtest: Test your strategy on downloaded historical data.
    • Optimize: Find the best parameters for your strategy using hyperoptimization which employs machining learning methods. You can optimize buy, sell, take profit (ROI), stop-loss and trailing stop-loss parameters for your strategy.
    • Select markets: Create your static list or use an automatic one based on top traded volumes and/or prices (not available during backtesting). You can also explicitly blacklist markets you don't want to trade.
    • Run: Test your strategy with simulated money (Dry-Run mode) or deploy it with real money (Live-Trade mode).
    • Run using Edge (optional module): The concept is to find the best historical trade expectancy by markets based on variation of the stop-loss and then allow/reject markets to trade. The sizing of the trade is based on a risk of a percentage of your capital.
    • Control/Monitor: Use Telegram or a WebUI (start/stop the bot, show profit/loss, daily summary, current open trades results, etc.).
    • Analyze: Further analysis can be performed on either Backtesting data or Freqtrade trading history (SQL database), including automated standard plots, and methods to load the data into interactive environments.
    "},{"location":"#supported-exchange-marketplaces","title":"Supported exchange marketplaces","text":"

    Please read the exchange specific notes to learn about eventual, special configurations needed for each exchange.

    • Binance
    • Bitmart
    • BingX
    • Bybit
    • Gate.io
    • HTX (Former Huobi)
    • Kraken
    • OKX (Former OKEX)
    • potentially many others through . (We cannot guarantee they will work)
    "},{"location":"#supported-futures-exchanges-experimental","title":"Supported Futures Exchanges (experimental)","text":"
    • Binance
    • Gate.io
    • OKX
    • Bybit

    Please make sure to read the exchange specific notes, as well as the trading with leverage documentation before diving in.

    "},{"location":"#community-tested","title":"Community tested","text":"

    Exchanges confirmed working by the community:

    • Bitvavo
    • Kucoin
    "},{"location":"#community-showcase","title":"Community showcase","text":"

    This section will highlight a few projects from members of the community.

    Note

    The projects below are for the most part not maintained by the freqtrade , therefore use your own caution before using them.

    • Example freqtrade strategies
    • FrequentHippo - Grafana dashboard with dry/live runs and backtests (by hippocritical).
    • Online pairlist generator (by Blood4rc).
    • Freqtrade Backtesting Project (by Blood4rc).
    • Freqtrade analysis notebook (by Froggleston).
    • TUI for freqtrade (by Froggleston).
    • Bot Academy (by stash86) - Blog about crypto bot projects.
    "},{"location":"#requirements","title":"Requirements","text":""},{"location":"#hardware-requirements","title":"Hardware requirements","text":"

    To run this bot we recommend you a linux cloud instance with a minimum of:

    • 2GB RAM
    • 1GB disk space
    • 2vCPU
    "},{"location":"#software-requirements","title":"Software requirements","text":"
    • Docker (Recommended)

    Alternatively

    • Python 3.9+
    • pip (pip3)
    • git
    • TA-Lib
    • virtualenv (Recommended)
    "},{"location":"#support","title":"Support","text":""},{"location":"#help-discord","title":"Help / Discord","text":"

    For any questions not covered by the documentation or for further information about the bot, or to simply engage with like-minded individuals, we encourage you to join the Freqtrade discord server.

    "},{"location":"#ready-to-try","title":"Ready to try?","text":"

    Begin by reading the installation guide for docker (recommended), or for installation without docker.

    "},{"location":"advanced-backtesting/","title":"Advanced Backtesting Analysis","text":""},{"location":"advanced-backtesting/#analyze-the-buyentry-and-sellexit-tags","title":"Analyze the buy/entry and sell/exit tags","text":"

    It can be helpful to understand how a strategy behaves according to the buy/entry tags used to mark up different buy conditions. You might want to see more complex statistics about each buy and sell condition above those provided by the default backtesting output. You may also want to determine indicator values on the signal candle that resulted in a trade opening.

    Note

    The following buy reason analysis is only available for backtesting, not hyperopt.

    We need to run backtesting with the --export option set to signals to enable the exporting of signals and trades:

    freqtrade backtesting -c <config.json> --timeframe <tf> --strategy <strategy_name> --timerange=<timerange> --export=signals\n

    This will tell freqtrade to output a pickled dictionary of strategy, pairs and corresponding DataFrame of the candles that resulted in entry and exit signals. Depending on how many entries your strategy makes, this file may get quite large, so periodically check your user_data/backtest_results folder to delete old exports.

    Before running your next backtest, make sure you either delete your old backtest results or run backtesting with the --cache none option to make sure no cached results are used.

    If all goes well, you should now see a backtest-result-{timestamp}_signals.pkl and backtest-result-{timestamp}_exited.pkl files in the user_data/backtest_results folder.

    To analyze the entry/exit tags, we now need to use the freqtrade backtesting-analysis command with --analysis-groups option provided with space-separated arguments:

    freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 1 2 3 4 5\n

    This command will read from the last backtesting results. The --analysis-groups option is used to specify the various tabular outputs showing the profit of each group or trade, ranging from the simplest (0) to the most detailed per pair, per buy and per sell tag (4):

    • 0: overall winrate and profit summary by enter_tag
    • 1: profit summaries grouped by enter_tag
    • 2: profit summaries grouped by enter_tag and exit_tag
    • 3: profit summaries grouped by pair and enter_tag
    • 4: profit summaries grouped by pair, enter_ and exit_tag (this can get quite large)
    • 5: profit summaries grouped by exit_tag

    More options are available by running with the -h option.

    "},{"location":"advanced-backtesting/#using-export-filename","title":"Using export-filename","text":"

    Normally, backtesting-analysis uses the latest backtest results, but if you wanted to go back to a previous backtest output, you need to supply the --export-filename option. You can supply the same parameter to backtest-analysis with the name of the final backtest output file. This allows you to keep historical versions of backtest results and re-analyse them at a later date:

    freqtrade backtesting -c <config.json> --timeframe <tf> --strategy <strategy_name> --timerange=<timerange> --export=signals --export-filename=/tmp/mystrat_backtest.json\n

    You should see some output similar to below in the logs with the name of the timestamped filename that was exported:

    2022-06-14 16:28:32,698 - freqtrade.misc - INFO - dumping json to \"/tmp/mystrat_backtest-2022-06-14_16-28-32.json\"\n

    You can then use that filename in backtesting-analysis:

    freqtrade backtesting-analysis -c <config.json> --export-filename=/tmp/mystrat_backtest-2022-06-14_16-28-32.json\n
    "},{"location":"advanced-backtesting/#tuning-the-buy-tags-and-sell-tags-to-display","title":"Tuning the buy tags and sell tags to display","text":"

    To show only certain buy and sell tags in the displayed output, use the following two options:

    --enter-reason-list : Space-separated list of enter signals to analyse. Default: \"all\"\n--exit-reason-list : Space-separated list of exit signals to analyse. Default: \"all\"\n

    For example:

    freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss\n
    "},{"location":"advanced-backtesting/#outputting-signal-candle-indicators","title":"Outputting signal candle indicators","text":"

    The real power of freqtrade backtesting-analysis comes from the ability to print out the indicator values present on signal candles to allow fine-grained investigation and tuning of buy signal indicators. To print out a column for a given set of indicators, use the --indicator-list option:

    freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss --indicator-list rsi rsi_1h bb_lowerband ema_9 macd macdsignal\n

    The indicators have to be present in your strategy's main DataFrame (either for your main timeframe or for informative timeframes) otherwise they will simply be ignored in the script output.

    Indicator List

    The indicator values will be displayed for both entry and exit points. If --indicator-list all is specified, only the indicators at the entry point will be shown to avoid excessively large lists, which could occur depending on the strategy.

    There are a range of candle and trade-related fields that are included in the analysis so are automatically accessible by including them on the indicator-list, and these include:

    • open_date : trade open datetime
    • close_date : trade close datetime
    • min_rate : minimum price seen throughout the position
    • max_rate : maximum price seen throughout the position
    • open : signal candle open price
    • close : signal candle close price
    • high : signal candle high price
    • low : signal candle low price
    • volume : signal candle volume
    • profit_ratio : trade profit ratio
    • profit_abs : absolute profit return of the trade
    "},{"location":"advanced-backtesting/#sample-output-for-indicator-values","title":"Sample Output for Indicator Values","text":"
    freqtrade backtesting-analysis -c user_data/config.json --analysis-groups 0 --indicator-list chikou_span tenkan_sen \n

    In this example, we aim to display the chikou_span and tenkan_sen indicator values at both the entry and exit points of trades.

    A sample output for indicators might look like this:

    pair open_date enter_reason exit_reason chikou_span (entry) tenkan_sen (entry) chikou_span (exit) tenkan_sen (exit) DOGE/USDT 2024-07-06 00:35:00+00:00 exit_signal 0.105 0.106 0.105 0.107 BTC/USDT 2024-08-05 14:20:00+00:00 roi 54643.440 51696.400 54386.000 52072.010

    As shown in the table, chikou_span (entry) represents the indicator value at the time of trade entry, while chikou_span (exit) reflects its value at the time of exit. This detailed view of indicator values enhances the analysis.

    The (entry) and (exit) suffixes are added to indicators to distinguish the values at the entry and exit points of the trade.

    Trade-wide Indicators

    Certain trade-wide indicators do not have the (entry) or (exit) suffix. These indicators include: pair, stake_amount, max_stake_amount, amount, open_date, close_date, open_rate, close_rate, fee_open, fee_close, trade_duration, profit_ratio, profit_abs, exit_reason,initial_stop_loss_abs, initial_stop_loss_ratio, stop_loss_abs, stop_loss_ratio, min_rate, max_rate, is_open, enter_tag, leverage, is_short, open_timestamp, close_timestamp and orders

    "},{"location":"advanced-backtesting/#filtering-the-trade-output-by-date","title":"Filtering the trade output by date","text":"

    To show only trades between dates within your backtested timerange, supply the usual timerange option in YYYYMMDD-[YYYYMMDD] format:

    --timerange : Timerange to filter output trades, start date inclusive, end date exclusive. e.g. 20220101-20221231\n

    For example, if your backtest timerange was 20220101-20221231 but you only want to output trades in January:

    freqtrade backtesting-analysis -c <config.json> --timerange 20220101-20220201\n
    "},{"location":"advanced-backtesting/#printing-out-rejected-signals","title":"Printing out rejected signals","text":"

    Use the --rejected-signals option to print out rejected signals.

    freqtrade backtesting-analysis -c <config.json> --rejected-signals\n
    "},{"location":"advanced-backtesting/#writing-tables-to-csv","title":"Writing tables to CSV","text":"

    Some of the tabular outputs can become large, so printing them out to the terminal is not preferable. Use the --analysis-to-csv option to disable printing out of tables to standard out and write them to CSV files.

    freqtrade backtesting-analysis -c <config.json> --analysis-to-csv\n

    By default this will write one file per output table you specified in the backtesting-analysis command, e.g.

    freqtrade backtesting-analysis -c <config.json> --analysis-to-csv --rejected-signals --analysis-groups 0 1\n

    This will write to user_data/backtest_results:

    • rejected_signals.csv
    • group_0.csv
    • group_1.csv

    To override where the files will be written, also specify the --analysis-csv-path option.

    freqtrade backtesting-analysis -c <config.json> --analysis-to-csv --analysis-csv-path another/data/path/\n
    "},{"location":"advanced-hyperopt/","title":"Advanced Hyperopt","text":"

    This page explains some advanced Hyperopt topics that may require higher coding skills and Python knowledge than creation of an ordinal hyperoptimization class.

    "},{"location":"advanced-hyperopt/#creating-and-using-a-custom-loss-function","title":"Creating and using a custom loss function","text":"

    To use a custom loss function class, make sure that the function hyperopt_loss_function is defined in your custom hyperopt loss class. For the sample below, you then need to add the command line parameter --hyperopt-loss SuperDuperHyperOptLoss to your hyperopt call so this function is being used.

    A sample of this can be found below, which is identical to the Default Hyperopt loss implementation. A full sample can be found in userdata/hyperopts.

    from datetime import datetime\nfrom typing import Any, Dict\n\nfrom pandas import DataFrame\n\nfrom freqtrade.constants import Config\nfrom freqtrade.optimize.hyperopt import IHyperOptLoss\n\nTARGET_TRADES = 600\nEXPECTED_MAX_PROFIT = 3.0\nMAX_ACCEPTED_TRADE_DURATION = 300\n\nclass SuperDuperHyperOptLoss(IHyperOptLoss):\n    \"\"\"\n    Defines the default loss function for hyperopt\n    \"\"\"\n\n    @staticmethod\n    def hyperopt_loss_function(\n        *,\n        results: DataFrame,\n        trade_count: int,\n        min_date: datetime,\n        max_date: datetime,\n        config: Config,\n        processed: Dict[str, DataFrame],\n        backtest_stats: Dict[str, Any],\n        **kwargs,\n    ) -> float:\n        \"\"\"\n        Objective function, returns smaller number for better results\n        This is the legacy algorithm (used until now in freqtrade).\n        Weights are distributed as follows:\n        * 0.4 to trade duration\n        * 0.25: Avoiding trade loss\n        * 1.0 to total profit, compared to the expected value (`EXPECTED_MAX_PROFIT`) defined above\n        \"\"\"\n        total_profit = results['profit_ratio'].sum()\n        trade_duration = results['trade_duration'].mean()\n\n        trade_loss = 1 - 0.25 * exp(-(trade_count - TARGET_TRADES) ** 2 / 10 ** 5.8)\n        profit_loss = max(0, 1 - total_profit / EXPECTED_MAX_PROFIT)\n        duration_loss = 0.4 * min(trade_duration / MAX_ACCEPTED_TRADE_DURATION, 1)\n        result = trade_loss + profit_loss + duration_loss\n        return result\n

    Currently, the arguments are:

    • results: DataFrame containing the resulting trades. The following columns are available in results (corresponds to the output-file of backtesting when used with --export trades): pair, profit_ratio, profit_abs, open_date, open_rate, fee_open, close_date, close_rate, fee_close, amount, trade_duration, is_open, exit_reason, stake_amount, min_rate, max_rate, stop_loss_ratio, stop_loss_abs
    • trade_count: Amount of trades (identical to len(results))
    • min_date: Start date of the timerange used
    • min_date: End date of the timerange used
    • config: Config object used (Note: Not all strategy-related parameters will be updated here if they are part of a hyperopt space).
    • processed: Dict of Dataframes with the pair as keys containing the data used for backtesting.
    • backtest_stats: Backtesting statistics using the same format as the backtesting file \"strategy\" substructure. Available fields can be seen in generate_strategy_stats() in optimize_reports.py.

    This function needs to return a floating point number (float). Smaller numbers will be interpreted as better results. The parameters and balancing for this is up to you.

    Note

    This function is called once per epoch - so please make sure to have this as optimized as possible to not slow hyperopt down unnecessarily.

    *args and **kwargs

    Please keep the arguments *args and **kwargs in the interface to allow us to extend this interface in the future.

    "},{"location":"advanced-hyperopt/#overriding-pre-defined-spaces","title":"Overriding pre-defined spaces","text":"

    To override a pre-defined space (roi_space, generate_roi_table, stoploss_space, trailing_space, max_open_trades_space), define a nested class called Hyperopt and define the required spaces as follows:

    from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal\n\nclass MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        # Define a custom stoploss space.\n        def stoploss_space():\n            return [SKDecimal(-0.05, -0.01, decimals=3, name='stoploss')]\n\n        # Define custom ROI space\n        def roi_space() -> List[Dimension]:\n            return [\n                Integer(10, 120, name='roi_t1'),\n                Integer(10, 60, name='roi_t2'),\n                Integer(10, 40, name='roi_t3'),\n                SKDecimal(0.01, 0.04, decimals=3, name='roi_p1'),\n                SKDecimal(0.01, 0.07, decimals=3, name='roi_p2'),\n                SKDecimal(0.01, 0.20, decimals=3, name='roi_p3'),\n            ]\n\n        def generate_roi_table(params: Dict) -> Dict[int, float]:\n\n            roi_table = {}\n            roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']\n            roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']\n            roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']\n            roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0\n\n            return roi_table\n\n        def trailing_space() -> List[Dimension]:\n            # All parameters here are mandatory, you can only modify their type or the range.\n            return [\n                # Fixed to true, if optimizing trailing_stop we assume to use trailing stop at all times.\n                Categorical([True], name='trailing_stop'),\n\n                SKDecimal(0.01, 0.35, decimals=3, name='trailing_stop_positive'),\n                # 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',\n                # so this intermediate parameter is used as the value of the difference between\n                # them. The value of the 'trailing_stop_positive_offset' is constructed in the\n                # generate_trailing_params() method.\n                # This is similar to the hyperspace dimensions used for constructing the ROI tables.\n                SKDecimal(0.001, 0.1, decimals=3, name='trailing_stop_positive_offset_p1'),\n\n                Categorical([True, False], name='trailing_only_offset_is_reached'),\n        ]\n\n        # Define a custom max_open_trades space\n        def max_open_trades_space(self) -> List[Dimension]:\n            return [\n                Integer(-1, 10, name='max_open_trades'),\n            ]\n

    Note

    All overrides are optional and can be mixed/matched as necessary.

    "},{"location":"advanced-hyperopt/#dynamic-parameters","title":"Dynamic parameters","text":"

    Parameters can also be defined dynamically, but must be available to the instance once the bot_start() callback has been called.

    class MyAwesomeStrategy(IStrategy):\n\n    def bot_start(self, **kwargs) -> None:\n        self.buy_adx = IntParameter(20, 30, default=30, optimize=True)\n\n    # ...\n

    Warning

    Parameters created this way will not show up in the list-strategies parameter count.

    "},{"location":"advanced-hyperopt/#overriding-base-estimator","title":"Overriding Base estimator","text":"

    You can define your own estimator for Hyperopt by implementing generate_estimator() in the Hyperopt subclass.

    class MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        def generate_estimator(dimensions: List['Dimension'], **kwargs):\n            return \"RF\"\n

    Possible values are either one of \"GP\", \"RF\", \"ET\", \"GBRT\" (Details can be found in the scikit-optimize documentation), or \"an instance of a class that inherits from RegressorMixin (from sklearn) and where the predict method has an optional return_std argument, which returns std(Y | x) along with E[Y | x]\".

    Some research will be necessary to find additional Regressors.

    Example for ExtraTreesRegressor (\"ET\") with additional parameters:

    class MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        def generate_estimator(dimensions: List['Dimension'], **kwargs):\n            from skopt.learning import ExtraTreesRegressor\n            # Corresponds to \"ET\" - but allows additional parameters.\n            return ExtraTreesRegressor(n_estimators=100)\n

    The dimensions parameter is the list of skopt.space.Dimension objects corresponding to the parameters to be optimized. It can be used to create isotropic kernels for the skopt.learning.GaussianProcessRegressor estimator. Here's an example:

    class MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        def generate_estimator(dimensions: List['Dimension'], **kwargs):\n            from skopt.utils import cook_estimator\n            from skopt.learning.gaussian_process.kernels import (Matern, ConstantKernel)\n            kernel_bounds = (0.0001, 10000)\n            kernel = (\n                ConstantKernel(1.0, kernel_bounds) * \n                Matern(length_scale=np.ones(len(dimensions)), length_scale_bounds=[kernel_bounds for d in dimensions], nu=2.5)\n            )\n            kernel += (\n                ConstantKernel(1.0, kernel_bounds) * \n                Matern(length_scale=np.ones(len(dimensions)), length_scale_bounds=[kernel_bounds for d in dimensions], nu=1.5)\n            )\n\n            return cook_estimator(\"GP\", space=dimensions, kernel=kernel, n_restarts_optimizer=2)\n

    Note

    While custom estimators can be provided, it's up to you as User to do research on possible parameters and analyze / understand which ones should be used. If you're unsure about this, best use one of the Defaults (\"ET\" has proven to be the most versatile) without further parameters.

    "},{"location":"advanced-hyperopt/#space-options","title":"Space options","text":"

    For the additional spaces, scikit-optimize (in combination with Freqtrade) provides the following space types:

    • Categorical - Pick from a list of categories (e.g. Categorical(['a', 'b', 'c'], name=\"cat\"))
    • Integer - Pick from a range of whole numbers (e.g. Integer(1, 10, name='rsi'))
    • SKDecimal - Pick from a range of decimal numbers with limited precision (e.g. SKDecimal(0.1, 0.5, decimals=3, name='adx')). Available only with freqtrade.
    • Real - Pick from a range of decimal numbers with full precision (e.g. Real(0.1, 0.5, name='adx')

    You can import all of these from freqtrade.optimize.space, although Categorical, Integer and Real are only aliases for their corresponding scikit-optimize Spaces. SKDecimal is provided by freqtrade for faster optimizations.

    from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal, Real  # noqa\n

    SKDecimal vs. Real

    We recommend to use SKDecimal instead of the Real space in almost all cases. While the Real space provides full accuracy (up to ~16 decimal places) - this precision is rarely needed, and leads to unnecessary long hyperopt times.

    Assuming the definition of a rather small space (SKDecimal(0.10, 0.15, decimals=2, name='xxx')) - SKDecimal will have 5 possibilities ([0.10, 0.11, 0.12, 0.13, 0.14, 0.15]).

    A corresponding real space Real(0.10, 0.15 name='xxx') on the other hand has an almost unlimited number of possibilities ([0.10, 0.010000000001, 0.010000000002, ... 0.014999999999, 0.01500000000]).

    "},{"location":"advanced-orderflow/","title":"Orderflow data","text":"

    This guide walks you through utilizing public trade data for advanced orderflow analysis in Freqtrade.

    Experimental Feature

    The orderflow feature is currently in beta and may be subject to changes in future releases. Please report any issues or feedback on the Freqtrade GitHub repository.

    Performance

    Orderflow requires raw trades data. This data is rather large, and can cause a slow initial startup, when freqtrade needs to download the trades data for the last X candles. Additionally, enabling this feature will cause increased memory usage. Please ensure to have sufficient resources available.

    "},{"location":"advanced-orderflow/#getting-started","title":"Getting Started","text":""},{"location":"advanced-orderflow/#enable-public-trades","title":"Enable Public Trades","text":"

    In your config.json file, set the use_public_trades option to true under the exchange section.

    \"exchange\": {\n   ...\n   \"use_public_trades\": true,\n}\n
    "},{"location":"advanced-orderflow/#configure-orderflow-processing","title":"Configure Orderflow Processing","text":"

    Define your desired settings for orderflow processing within the orderflow section of config.json. Here, you can adjust factors like:

    • cache_size: How many previous orderflow candles are saved into cache instead of calculated every new candle
    • max_candles: Filter how many candles would you like to get trades data for.
    • scale: This controls the price bin size for the footprint chart.
    • stacked_imbalance_range: Defines the minimum consecutive imbalanced price levels required for consideration.
    • imbalance_volume: Filters out imbalances with volume below this threshold.
    • imbalance_ratio: Filters out imbalances with a ratio (difference between ask and bid volume) lower than this value.
    \"orderflow\": {\n    \"cache_size\": 1000, \n    \"max_candles\": 1500, \n    \"scale\": 0.5, \n    \"stacked_imbalance_range\": 3, //  needs at least this amount of imbalance next to each other\n    \"imbalance_volume\": 1, //  filters out below\n    \"imbalance_ratio\": 3 //  filters out ratio lower than\n  },\n
    "},{"location":"advanced-orderflow/#downloading-trade-data-for-backtesting","title":"Downloading Trade Data for Backtesting","text":"

    To download historical trade data for backtesting, use the --dl-trades flag with the freqtrade download-data command.

    freqtrade download-data -p BTC/USDT:USDT --timerange 20230101- --trading-mode futures --timeframes 5m --dl-trades\n

    Data availability

    Not all exchanges provide public trade data. For supported exchanges, freqtrade will warn you if public trade data is not available if you start downloading data with the --dl-trades flag.

    "},{"location":"advanced-orderflow/#accessing-orderflow-data","title":"Accessing Orderflow Data","text":"

    Once activated, several new columns become available in your dataframe:

    dataframe[\"trades\"] # Contains information about each individual trade.\ndataframe[\"orderflow\"] # Represents a footprint chart dict (see below)\ndataframe[\"imbalances\"] # Contains information about imbalances in the order flow.\ndataframe[\"bid\"] # Total bid volume \ndataframe[\"ask\"] # Total ask volume\ndataframe[\"delta\"] # Difference between ask and bid volume.\ndataframe[\"min_delta\"] # Minimum delta within the candle\ndataframe[\"max_delta\"] # Maximum delta within the candle\ndataframe[\"total_trades\"] # Total number of trades\ndataframe[\"stacked_imbalances_bid\"] # Price level of stacked bid imbalance \ndataframe[\"stacked_imbalances_ask\"] # Price level of stacked ask imbalance  \n

    You can access these columns in your strategy code for further analysis. Here's an example:

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    # Calculating cumulative delta\n    dataframe[\"cum_delta\"] = cumulative_delta(dataframe[\"delta\"])\n    # Accessing total trades\n    total_trades = dataframe[\"total_trades\"]\n    ...\n\ndef cumulative_delta(delta: Series):\n    cumdelta = delta.cumsum()\n    return cumdelta\n
    "},{"location":"advanced-orderflow/#footprint-chart-dataframeorderflow","title":"Footprint chart (dataframe[\"orderflow\"])","text":"

    This column provides a detailed breakdown of buy and sell orders at different price levels, offering valuable insights into order flow dynamics. The scale parameter in your configuration determines the price bin size for this representation

    The orderflow column contains a dict with the following structure:

    {\n    \"price\": {\n        \"bid_amount\": 0.0,\n        \"ask_amount\": 0.0,\n        \"bid\": 0,\n        \"ask\": 0,\n        \"delta\": 0.0,\n        \"total_volume\": 0.0,\n        \"total_trades\": 0\n    }\n}\n
    "},{"location":"advanced-orderflow/#orderflow-column-explanation","title":"Orderflow column explanation","text":"
    • key: Price bin - binned at scale intervals
    • bid_amount: Total volume bought at each price level.
    • ask_amount: Total volume sold at each price level.
    • bid: Number of buy orders at each price level.
    • ask: Number of sell orders at each price level.
    • delta: Difference between ask and bid volume at each price level.
    • total_volume: Total volume (ask amount + bid amount) at each price level.
    • total_trades: Total number of trades (ask + bid) at each price level.

    By leveraging these features, you can gain valuable insights into market sentiment and potential trading opportunities based on order flow analysis.

    "},{"location":"advanced-orderflow/#raw-trades-data-dataframetrades","title":"Raw trades data (dataframe[\"trades\"])","text":"

    List with the individual trades that occurred during the candle. This data can be used for more granular analysis of order flow dynamics.

    Each individual entry contains a dict with the following keys:

    • timestamp: Timestamp of the trade.
    • date: Date of the trade.
    • price: Price of the trade.
    • amount: Volume of the trade.
    • side: Buy or sell.
    • id: Unique identifier for the trade.
    • cost: Total cost of the trade (price * amount).
    "},{"location":"advanced-orderflow/#imbalances-dataframeimbalances","title":"Imbalances (dataframe[\"imbalances\"])","text":"

    This column provides a dict with information about imbalances in the order flow. An imbalance occurs when there is a significant difference between the ask and bid volume at a given price level.

    Each row looks as follows - with price as index, and the corresponding bid and ask imbalance values as columns

    {\n    \"price\": {\n        \"bid_imbalance\": False,\n        \"ask_imbalance\": False\n    }\n}\n
    "},{"location":"advanced-setup/","title":"Advanced Post-installation Tasks","text":"

    This page explains some advanced tasks and configuration options that can be performed after the bot installation and may be uselful in some environments.

    If you do not know what things mentioned here mean, you probably do not need it.

    "},{"location":"advanced-setup/#running-multiple-instances-of-freqtrade","title":"Running multiple instances of Freqtrade","text":"

    This section will show you how to run multiple bots at the same time, on the same machine.

    "},{"location":"advanced-setup/#things-to-consider","title":"Things to consider","text":"
    • Use different database files.
    • Use different Telegram bots (requires multiple different configuration files; applies only when Telegram is enabled).
    • Use different ports (applies only when Freqtrade REST API webserver is enabled).
    "},{"location":"advanced-setup/#different-database-files","title":"Different database files","text":"

    In order to keep track of your trades, profits, etc., freqtrade is using a SQLite database where it stores various types of information such as the trades you performed in the past and the current position(s) you are holding at any time. This allows you to keep track of your profits, but most importantly, keep track of ongoing activity if the bot process would be restarted or would be terminated unexpectedly.

    Freqtrade will, by default, use separate database files for dry-run and live bots (this assumes no database-url is given in either configuration nor via command line argument). For live trading mode, the default database will be tradesv3.sqlite and for dry-run it will be tradesv3.dryrun.sqlite.

    The optional argument to the trade command used to specify the path of these files is --db-url, which requires a valid SQLAlchemy url. So when you are starting a bot with only the config and strategy arguments in dry-run mode, the following 2 commands would have the same outcome.

    freqtrade trade -c MyConfig.json -s MyStrategy\n# is equivalent to\nfreqtrade trade -c MyConfig.json -s MyStrategy --db-url sqlite:///tradesv3.dryrun.sqlite\n

    It means that if you are running the trade command in two different terminals, for example to test your strategy both for trades in USDT and in another instance for trades in BTC, you will have to run them with different databases.

    If you specify the URL of a database which does not exist, freqtrade will create one with the name you specified. So to test your custom strategy with BTC and USDT stake currencies, you could use the following commands (in 2 separate terminals):

    # Terminal 1:\nfreqtrade trade -c MyConfigBTC.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesBTC.dryrun.sqlite\n# Terminal 2:\nfreqtrade trade -c MyConfigUSDT.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesUSDT.dryrun.sqlite\n

    Conversely, if you wish to do the same thing in production mode, you will also have to create at least one new database (in addition to the default one) and specify the path to the \"live\" databases, for example:

    # Terminal 1:\nfreqtrade trade -c MyConfigBTC.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesBTC.live.sqlite\n# Terminal 2:\nfreqtrade trade -c MyConfigUSDT.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesUSDT.live.sqlite\n

    For more information regarding usage of the sqlite databases, for example to manually enter or remove trades, please refer to the SQL Cheatsheet.

    "},{"location":"advanced-setup/#multiple-instances-using-docker","title":"Multiple instances using docker","text":"

    To run multiple instances of freqtrade using docker you will need to edit the docker-compose.yml file and add all the instances you want as separate services. Remember, you can separate your configuration into multiple files, so it's a good idea to think about making them modular, then if you need to edit something common to all bots, you can do that in a single config file.

    ---\nversion: '3'\nservices:\n  freqtrade1:\n    image: freqtradeorg/freqtrade:stable\n    # image: freqtradeorg/freqtrade:develop\n    # Use plotting image\n    # image: freqtradeorg/freqtrade:develop_plot\n    # Build step - only needed when additional dependencies are needed\n    # build:\n    #   context: .\n    #   dockerfile: \"./docker/Dockerfile.custom\"\n    restart: always\n    container_name: freqtrade1\n    volumes:\n      - \"./user_data:/freqtrade/user_data\"\n    # Expose api on port 8080 (localhost only)\n    # Please read the https://www.freqtrade.io/en/latest/rest-api/ documentation\n    # before enabling this.\n     ports:\n     - \"127.0.0.1:8080:8080\"\n    # Default command used when running `docker compose up`\n    command: >\n      trade\n      --logfile /freqtrade/user_data/logs/freqtrade1.log\n      --db-url sqlite:////freqtrade/user_data/tradesv3_freqtrade1.sqlite\n      --config /freqtrade/user_data/config.json\n      --config /freqtrade/user_data/config.freqtrade1.json\n      --strategy SampleStrategy\n\n  freqtrade2:\n    image: freqtradeorg/freqtrade:stable\n    # image: freqtradeorg/freqtrade:develop\n    # Use plotting image\n    # image: freqtradeorg/freqtrade:develop_plot\n    # Build step - only needed when additional dependencies are needed\n    # build:\n    #   context: .\n    #   dockerfile: \"./docker/Dockerfile.custom\"\n    restart: always\n    container_name: freqtrade2\n    volumes:\n      - \"./user_data:/freqtrade/user_data\"\n    # Expose api on port 8080 (localhost only)\n    # Please read the https://www.freqtrade.io/en/latest/rest-api/ documentation\n    # before enabling this.\n    ports:\n      - \"127.0.0.1:8081:8080\"\n    # Default command used when running `docker compose up`\n    command: >\n      trade\n      --logfile /freqtrade/user_data/logs/freqtrade2.log\n      --db-url sqlite:////freqtrade/user_data/tradesv3_freqtrade2.sqlite\n      --config /freqtrade/user_data/config.json\n      --config /freqtrade/user_data/config.freqtrade2.json\n      --strategy SampleStrategy\n

    You can use whatever naming convention you want, freqtrade1 and 2 are arbitrary. Note, that you will need to use different database files, port mappings and telegram configurations for each instance, as mentioned above.

    "},{"location":"advanced-setup/#use-a-different-database-system","title":"Use a different database system","text":"

    Freqtrade is using SQLAlchemy, which supports multiple different database systems. As such, a multitude of database systems should be supported. Freqtrade does not depend or install any additional database driver. Please refer to the SQLAlchemy docs on installation instructions for the respective database systems.

    The following systems have been tested and are known to work with freqtrade:

    • sqlite (default)
    • PostgreSQL
    • MariaDB

    Warning

    By using one of the below database systems, you acknowledge that you know how to manage such a system. The freqtrade team will not provide any support with setup or maintenance (or backups) of the below database systems.

    "},{"location":"advanced-setup/#postgresql","title":"PostgreSQL","text":"

    Installation: pip install psycopg2-binary

    Usage: ... --db-url postgresql+psycopg2://<username>:<password>@localhost:5432/<database>

    Freqtrade will automatically create the tables necessary upon startup.

    If you're running different instances of Freqtrade, you must either setup one database per Instance or use different users / schemas for your connections.

    "},{"location":"advanced-setup/#mariadb-mysql","title":"MariaDB / MySQL","text":"

    Freqtrade supports MariaDB by using SQLAlchemy, which supports multiple different database systems.

    Installation: pip install pymysql

    Usage: ... --db-url mysql+pymysql://<username>:<password>@localhost:3306/<database>

    "},{"location":"advanced-setup/#configure-the-bot-running-as-a-systemd-service","title":"Configure the bot running as a systemd service","text":"

    Copy the freqtrade.service file to your systemd user directory (usually ~/.config/systemd/user) and update WorkingDirectory and ExecStart to match your setup.

    Note

    Certain systems (like Raspbian) don't load service unit files from the user directory. In this case, copy freqtrade.service into /etc/systemd/user/ (requires superuser permissions).

    After that you can start the daemon with:

    systemctl --user start freqtrade\n

    For this to be persistent (run when user is logged out) you'll need to enable linger for your freqtrade user.

    sudo loginctl enable-linger \"$USER\"\n

    If you run the bot as a service, you can use systemd service manager as a software watchdog monitoring freqtrade bot state and restarting it in the case of failures. If the internals.sd_notify parameter is set to true in the configuration or the --sd-notify command line option is used, the bot will send keep-alive ping messages to systemd using the sd_notify (systemd notifications) protocol and will also tell systemd its current state (Running or Stopped) when it changes.

    The freqtrade.service.watchdog file contains an example of the service unit configuration file which uses systemd as the watchdog.

    Note

    The sd_notify communication between the bot and the systemd service manager will not work if the bot runs in a Docker container.

    "},{"location":"advanced-setup/#advanced-logging","title":"Advanced Logging","text":"

    On many Linux systems the bot can be configured to send its log messages to syslog or journald system services. Logging to a remote syslog server is also available on Windows. The special values for the --logfile command line option can be used for this.

    "},{"location":"advanced-setup/#logging-to-syslog","title":"Logging to syslog","text":"

    To send Freqtrade log messages to a local or remote syslog service use the --logfile command line option with the value in the following format:

    • --logfile syslog:<syslog_address> -- send log messages to syslog service using the <syslog_address> as the syslog address.

    The syslog address can be either a Unix domain socket (socket filename) or a UDP socket specification, consisting of IP address and UDP port, separated by the : character.

    So, the following are the examples of possible usages:

    • --logfile syslog:/dev/log -- log to syslog (rsyslog) using the /dev/log socket, suitable for most systems.
    • --logfile syslog -- same as above, the shortcut for /dev/log.
    • --logfile syslog:/var/run/syslog -- log to syslog (rsyslog) using the /var/run/syslog socket. Use this on MacOS.
    • --logfile syslog:localhost:514 -- log to local syslog using UDP socket, if it listens on port 514.
    • --logfile syslog:<ip>:514 -- log to remote syslog at IP address and port 514. This may be used on Windows for remote logging to an external syslog server.

    Log messages are send to syslog with the user facility. So you can see them with the following commands:

    • tail -f /var/log/user, or
    • install a comprehensive graphical viewer (for instance, 'Log File Viewer' for Ubuntu).

    On many systems syslog (rsyslog) fetches data from journald (and vice versa), so both --logfile syslog or --logfile journald can be used and the messages be viewed with both journalctl and a syslog viewer utility. You can combine this in any way which suites you better.

    For rsyslog the messages from the bot can be redirected into a separate dedicated log file. To achieve this, add

    if $programname startswith \"freqtrade\" then -/var/log/freqtrade.log\n

    to one of the rsyslog configuration files, for example at the end of the /etc/rsyslog.d/50-default.conf.

    For syslog (rsyslog), the reduction mode can be switched on. This will reduce the number of repeating messages. For instance, multiple bot Heartbeat messages will be reduced to a single message when nothing else happens with the bot. To achieve this, set in /etc/rsyslog.conf:

    # Filter duplicated messages\n$RepeatedMsgReduction on\n
    "},{"location":"advanced-setup/#logging-to-journald","title":"Logging to journald","text":"

    This needs the cysystemd python package installed as dependency (pip install cysystemd), which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows.

    To send Freqtrade log messages to journald system service use the --logfile command line option with the value in the following format:

    • --logfile journald -- send log messages to journald.

    Log messages are send to journald with the user facility. So you can see them with the following commands:

    • journalctl -f -- shows Freqtrade log messages sent to journald along with other log messages fetched by journald.
    • journalctl -f -u freqtrade.service -- this command can be used when the bot is run as a systemd service.

    There are many other options in the journalctl utility to filter the messages, see manual pages for this utility.

    On many systems syslog (rsyslog) fetches data from journald (and vice versa), so both --logfile syslog or --logfile journald can be used and the messages be viewed with both journalctl and a syslog viewer utility. You can combine this in any way which suites you better.

    "},{"location":"backtesting/","title":"Backtesting","text":"

    This page explains how to validate your strategy performance by using Backtesting.

    Backtesting requires historic data to be available. To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    "},{"location":"backtesting/#backtesting-command-reference","title":"Backtesting command reference","text":"
    usage: freqtrade backtesting [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                             [-d PATH] [--userdir PATH] [-s NAME]\n                             [--strategy-path PATH] [-i TIMEFRAME]\n                             [--timerange TIMERANGE]\n                             [--data-format-ohlcv {json,jsongz,hdf5}]\n                             [--max-open-trades INT]\n                             [--stake-amount STAKE_AMOUNT] [--fee FLOAT]\n                             [-p PAIRS [PAIRS ...]] [--eps] [--dmmp]\n                             [--enable-protections]\n                             [--dry-run-wallet DRY_RUN_WALLET]\n                             [--timeframe-detail TIMEFRAME_DETAIL]\n                             [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]\n                             [--export {none,trades,signals}]\n                             [--export-filename PATH]\n                             [--breakdown {day,week,month} [{day,week,month} ...]]\n                             [--cache {none,day,week,month}]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --max-open-trades INT\n                        Override the value of the `max_open_trades`\n                        configuration setting.\n  --stake-amount STAKE_AMOUNT\n                        Override the value of the `stake_amount` configuration\n                        setting.\n  --fee FLOAT           Specify fee ratio. Will be applied twice (on trade\n                        entry and exit).\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --eps, --enable-position-stacking\n                        Allow buying the same pair multiple times (position\n                        stacking).\n  --dmmp, --disable-max-market-positions\n                        Disable applying `max_open_trades` during backtest\n                        (same as setting `max_open_trades` to a very high\n                        number).\n  --enable-protections, --enableprotections\n                        Enable protections for backtesting.Will slow\n                        backtesting down by a considerable amount, but will\n                        include configured protections\n  --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET\n                        Starting balance, used for backtesting / hyperopt and\n                        dry-runs.\n  --timeframe-detail TIMEFRAME_DETAIL\n                        Specify detail timeframe for backtesting (`1m`, `5m`,\n                        `30m`, `1h`, `1d`).\n  --strategy-list STRATEGY_LIST [STRATEGY_LIST ...]\n                        Provide a space-separated list of strategies to\n                        backtest. Please note that timeframe needs to be set\n                        either in config or via command line. When using this\n                        together with `--export trades`, the strategy-name is\n                        injected into the filename (so `backtest-data.json`\n                        becomes `backtest-data-SampleStrategy.json`\n  --export {none,trades,signals}\n                        Export backtest results (default: trades).\n  --export-filename PATH, --backtest-filename PATH\n                        Use this filename for backtest results.Requires\n                        `--export` to be set as well. Example: `--export-filen\n                        ame=user_data/backtest_results/backtest_today.json`\n  --breakdown {day,week,month} [{day,week,month} ...]\n                        Show backtesting breakdown per [day, week, month].\n  --cache {none,day,week,month}\n                        Load a cached backtest result no older than specified\n                        age (default: day).\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n
    "},{"location":"backtesting/#test-your-strategy-with-backtesting","title":"Test your strategy with Backtesting","text":"

    Now you have good Entry and exit strategies and some historic data, you want to test it against real data. This is what we call backtesting.

    Backtesting will use the crypto-currencies (pairs) from your config file and load historical candle (OHLCV) data from user_data/data/<exchange> by default. If no data is available for the exchange / pair / timeframe combination, backtesting will ask you to download them first using freqtrade download-data. For details on downloading, please refer to the Data Downloading section in the documentation.

    The result of backtesting will confirm if your bot has better odds of making a profit than a loss.

    All profit calculations include fees, and freqtrade will use the exchange's default fees for the calculation.

    Using dynamic pairlists for backtesting

    Using dynamic pairlists is possible (not all of the handlers are allowed to be used in backtest mode), however it relies on the current market conditions - which will not reflect the historic status of the pairlist. Also, when using pairlists other than StaticPairlist, reproducibility of backtesting-results cannot be guaranteed. Please read the pairlists documentation for more information.

    To achieve reproducible results, best generate a pairlist via the test-pairlist command and use that as static pairlist.

    Note

    By default, Freqtrade will export backtesting results to user_data/backtest_results. The exported trades can be used for further analysis or can be used by the plotting sub-command (freqtrade plot-dataframe) in the scripts directory.

    "},{"location":"backtesting/#starting-balance","title":"Starting balance","text":"

    Backtesting will require a starting balance, which can be provided as --dry-run-wallet <balance> or --starting-balance <balance> command line argument, or via dry_run_wallet configuration setting. This amount must be higher than stake_amount, otherwise the bot will not be able to simulate any trade.

    "},{"location":"backtesting/#dynamic-stake-amount","title":"Dynamic stake amount","text":"

    Backtesting supports dynamic stake amount by configuring stake_amount as \"unlimited\", which will split the starting balance into max_open_trades pieces. Profits from early trades will result in subsequent higher stake amounts, resulting in compounding of profits over the backtesting period.

    "},{"location":"backtesting/#example-backtesting-commands","title":"Example backtesting commands","text":"

    With 5 min candle (OHLCV) data (per default)

    freqtrade backtesting --strategy AwesomeStrategy\n

    Where --strategy AwesomeStrategy / -s AwesomeStrategy refers to the class name of the strategy, which is within a python file in the user_data/strategies directory.

    With 1 min candle (OHLCV) data

    freqtrade backtesting --strategy AwesomeStrategy --timeframe 1m\n

    Providing a custom starting balance of 1000 (in stake currency)

    freqtrade backtesting --strategy AwesomeStrategy --dry-run-wallet 1000\n

    Using a different on-disk historical candle (OHLCV) data source

    Assume you downloaded the history data from the Binance exchange and kept it in the user_data/data/binance-20180101 directory. You can then use this data for backtesting as follows:

    freqtrade backtesting --strategy AwesomeStrategy --datadir user_data/data/binance-20180101 \n

    Comparing multiple Strategies

    freqtrade backtesting --strategy-list SampleStrategy1 AwesomeStrategy --timeframe 5m\n

    Where SampleStrategy1 and AwesomeStrategy refer to class names of strategies.

    Prevent exporting trades to file

    freqtrade backtesting --strategy backtesting --export none --config config.json \n

    Only use this if you're sure you'll not want to plot or analyze your results further.

    Exporting trades to file specifying a custom filename

    freqtrade backtesting --strategy backtesting --export trades --export-filename=backtest_samplestrategy.json\n

    Please also read about the strategy startup period.

    Supplying custom fee value

    Sometimes your account has certain fee rebates (fee reductions starting with a certain account size or monthly volume), which are not visible to ccxt. To account for this in backtesting, you can use the --fee command line option to supply this value to backtesting. This fee must be a ratio, and will be applied twice (once for trade entry, and once for trade exit).

    For example, if the commission fee per order is 0.1% (i.e., 0.001 written as ratio), then you would run backtesting as the following:

    freqtrade backtesting --fee 0.001\n

    Note

    Only supply this option (or the corresponding configuration parameter) if you want to experiment with different fee values. By default, Backtesting fetches the default fee from the exchange pair/market info.

    Running backtest with smaller test-set by using timerange

    Use the --timerange argument to change how much of the test-set you want to use.

    For example, running backtesting with the --timerange=20190501- option will use all available data starting with May 1st, 2019 from your input data.

    freqtrade backtesting --timerange=20190501-\n

    You can also specify particular date ranges.

    The full timerange specification:

    • Use data until 2018/01/31: --timerange=-20180131
    • Use data since 2018/01/31: --timerange=20180131-
    • Use data since 2018/01/31 till 2018/03/01 : --timerange=20180131-20180301
    • Use data between POSIX / epoch timestamps 1527595200 1527618600: --timerange=1527595200-1527618600
    "},{"location":"backtesting/#understand-the-backtesting-result","title":"Understand the backtesting result","text":"

    The most important in the backtesting is to understand the result.

    A backtesting result will look like that:

    ================================================ BACKTESTING REPORT =================================================\n| Pair     | Trades |   Avg Profit % |   Tot Profit BTC |   Tot Profit % | Avg Duration |  Wins Draws Loss   Win%  |\n|----------+--------+----------------+------------------+----------------+--------------+--------------------------|\n| ADA/BTC  |     35 |          -0.11 |      -0.00019428 |          -1.94 | 4:35:00      |    14     0    21   40.0 |\n| ARK/BTC  |     11 |          -0.41 |      -0.00022647 |          -2.26 | 2:03:00      |     3     0     8   27.3 |\n| BTS/BTC  |     32 |           0.31 |       0.00048938 |           4.89 | 5:05:00      |    18     0    14   56.2 |\n| DASH/BTC |     13 |          -0.08 |      -0.00005343 |          -0.53 | 4:39:00      |     6     0     7   46.2 |\n| ENG/BTC  |     18 |           1.36 |       0.00122807 |          12.27 | 2:50:00      |     8     0    10   44.4 |\n| EOS/BTC  |     36 |           0.08 |       0.00015304 |           1.53 | 3:34:00      |    16     0    20   44.4 |\n| ETC/BTC  |     26 |           0.37 |       0.00047576 |           4.75 | 6:14:00      |    11     0    15   42.3 |\n| ETH/BTC  |     33 |           0.30 |       0.00049856 |           4.98 | 7:31:00      |    16     0    17   48.5 |\n| IOTA/BTC |     32 |           0.03 |       0.00005444 |           0.54 | 3:12:00      |    14     0    18   43.8 |\n| LSK/BTC  |     15 |           1.75 |       0.00131413 |          13.13 | 2:58:00      |     6     0     9   40.0 |\n| LTC/BTC  |     32 |          -0.04 |      -0.00006886 |          -0.69 | 4:49:00      |    11     0    21   34.4 |\n| NANO/BTC |     17 |           1.26 |       0.00107058 |          10.70 | 1:55:00      |    10     0     7   58.5 |\n| NEO/BTC  |     23 |           0.82 |       0.00094936 |           9.48 | 2:59:00      |    10     0    13   43.5 |\n| REQ/BTC  |      9 |           1.17 |       0.00052734 |           5.27 | 3:47:00      |     4     0     5   44.4 |\n| XLM/BTC  |     16 |           1.22 |       0.00097800 |           9.77 | 3:15:00      |     7     0     9   43.8 |\n| XMR/BTC  |     23 |          -0.18 |      -0.00020696 |          -2.07 | 5:30:00      |    12     0    11   52.2 |\n| XRP/BTC  |     35 |           0.66 |       0.00114897 |          11.48 | 3:49:00      |    12     0    23   34.3 |\n| ZEC/BTC  |     22 |          -0.46 |      -0.00050971 |          -5.09 | 2:22:00      |     7     0    15   31.8 |\n| TOTAL    |    429 |           0.36 |       0.00762792 |          76.20 | 4:12:00      |   186     0   243   43.4 |\n============================================= LEFT OPEN TRADES REPORT =============================================\n| Pair     |  Trades |   Avg Profit % |   Tot Profit BTC |   Tot Profit % | Avg Duration   |  Win Draw Loss Win% |\n|----------+---------+----------------+------------------+----------------+----------------+---------------------|\n| ADA/BTC  |       1 |           0.89 |       0.00004434 |           0.44 | 6:00:00        |    1    0    0  100 |\n| LTC/BTC  |       1 |           0.68 |       0.00003421 |           0.34 | 2:00:00        |    1    0    0  100 |\n| TOTAL    |       2 |           0.78 |       0.00007855 |           0.78 | 4:00:00        |    2    0    0  100 |\n==================== EXIT REASON STATS ====================\n| Exit Reason        |   Exits |  Wins |  Draws |  Losses |\n|--------------------+---------+-------+--------+---------|\n| trailing_stop_loss |     205 |   150 |      0 |      55 |\n| stop_loss          |     166 |     0 |      0 |     166 |\n| exit_signal        |      56 |    36 |      0 |      20 |\n| force_exit         |       2 |     0 |      0 |       2 |\n\n================== SUMMARY METRICS ==================\n| Metric                      | Value               |\n|-----------------------------+---------------------|\n| Backtesting from            | 2019-01-01 00:00:00 |\n| Backtesting to              | 2019-05-01 00:00:00 |\n| Trading Mode                | Spot                |\n| Max open trades             | 3                   |\n|                             |                     |\n| Total/Daily Avg Trades      | 429 / 3.575         |\n| Starting balance            | 0.01000000 BTC      |\n| Final balance               | 0.01762792 BTC      |\n| Absolute profit             | 0.00762792 BTC      |\n| Total profit %              | 76.2%               |\n| CAGR %                      | 460.87%             |\n| Sortino                     | 1.88                |\n| Sharpe                      | 2.97                |\n| Calmar                      | 6.29                |\n| Profit factor               | 1.11                |\n| Expectancy (Ratio)          | -0.15 (-0.05)       |\n| Avg. stake amount           | 0.001      BTC      |\n| Total trade volume          | 0.429      BTC      |\n|                             |                     |\n| Long / Short                | 352 / 77            |\n| Total profit Long %         | 1250.58%            |\n| Total profit Short %        | -15.02%             |\n| Absolute profit Long        | 0.00838792 BTC      |\n| Absolute profit Short       | -0.00076 BTC        |\n|                             |                     |\n| Best Pair                   | LSK/BTC 26.26%      |\n| Worst Pair                  | ZEC/BTC -10.18%     |\n| Best Trade                  | LSK/BTC 4.25%       |\n| Worst Trade                 | ZEC/BTC -10.25%     |\n| Best day                    | 0.00076 BTC         |\n| Worst day                   | -0.00036 BTC        |\n| Days win/draw/lose          | 12 / 82 / 25        |\n| Avg. Duration Winners       | 4:23:00             |\n| Avg. Duration Loser         | 6:55:00             |\n| Max Consecutive Wins / Loss | 3 / 4               |\n| Rejected Entry signals      | 3089                |\n| Entry/Exit Timeouts         | 0 / 0               |\n| Canceled Trade Entries      | 34                  |\n| Canceled Entry Orders       | 123                 |\n| Replaced Entry Orders       | 89                  |\n|                             |                     |\n| Min balance                 | 0.00945123 BTC      |\n| Max balance                 | 0.01846651 BTC      |\n| Max % of account underwater | 25.19%              |\n| Absolute Drawdown (Account) | 13.33%              |\n| Drawdown                    | 0.0015 BTC          |\n| Drawdown high               | 0.0013 BTC          |\n| Drawdown low                | -0.0002 BTC         |\n| Drawdown Start              | 2019-02-15 14:10:00 |\n| Drawdown End                | 2019-04-11 18:15:00 |\n| Market change               | -5.88%              |\n=====================================================\n
    "},{"location":"backtesting/#backtesting-report-table","title":"Backtesting report table","text":"

    The 1st table contains all trades the bot made, including \"left open trades\".

    The last line will give you the overall performance of your strategy, here:

    | TOTAL    |    429 |           0.36 |         152.41 |       0.00762792 |          76.20 | 4:12:00      |   186     0   243   43.4 |\n

    The bot has made 429 trades for an average duration of 4:12:00, with a performance of 76.20% (profit), that means it has earned a total of 0.00762792 BTC starting with a capital of 0.01 BTC.

    The column Avg Profit % shows the average profit for all trades made. The column Tot Profit % shows instead the total profit % in relation to the starting balance. In the above results, we have a starting balance of 0.01 BTC and an absolute profit of 0.00762792 BTC - so the Tot Profit % will be (0.00762792 / 0.01) * 100 ~= 76.2%.

    Your strategy performance is influenced by your entry strategy, your exit strategy, and also by the minimal_roi and stop_loss you have set.

    For example, if your minimal_roi is only \"0\": 0.01 you cannot expect the bot to make more profit than 1% (because it will exit every time a trade reaches 1%).

    \"minimal_roi\": {\n    \"0\":  0.01\n},\n

    On the other hand, if you set a too high minimal_roi like \"0\": 0.55 (55%), there is almost no chance that the bot will ever reach this profit. Hence, keep in mind that your performance is an integral mix of all different elements of the strategy, your configuration, and the crypto-currency pairs you have set up.

    "},{"location":"backtesting/#exit-reasons-table","title":"Exit reasons table","text":"

    The 2nd table contains a recap of exit reasons. This table can tell you which area needs some additional work (e.g. all or many of the exit_signal trades are losses, so you should work on improving the exit signal, or consider disabling it).

    "},{"location":"backtesting/#left-open-trades-table","title":"Left open trades table","text":"

    The 3rd table contains all trades the bot had to force_exit at the end of the backtesting period to present you the full picture. This is necessary to simulate realistic behavior, since the backtest period has to end at some point, while realistically, you could leave the bot running forever. These trades are also included in the first table, but are also shown separately in this table for clarity.

    "},{"location":"backtesting/#summary-metrics","title":"Summary metrics","text":"

    The last element of the backtest report is the summary metrics table. It contains some useful key metrics about performance of your strategy on backtesting data.

    ================== SUMMARY METRICS ==================\n| Metric                      | Value               |\n|-----------------------------+---------------------|\n| Backtesting from            | 2019-01-01 00:00:00 |\n| Backtesting to              | 2019-05-01 00:00:00 |\n| Trading Mode                | Spot                |\n| Max open trades             | 3                   |\n|                             |                     |\n| Total/Daily Avg Trades      | 429 / 3.575         |\n| Starting balance            | 0.01000000 BTC      |\n| Final balance               | 0.01762792 BTC      |\n| Absolute profit             | 0.00762792 BTC      |\n| Total profit %              | 76.2%               |\n| CAGR %                      | 460.87%             |\n| Sortino                     | 1.88                |\n| Sharpe                      | 2.97                |\n| Calmar                      | 6.29                |\n| Profit factor               | 1.11                |\n| Expectancy (Ratio)          | -0.15 (-0.05)       |\n| Avg. stake amount           | 0.001      BTC      |\n| Total trade volume          | 0.429      BTC      |\n|                             |                     |\n| Long / Short                | 352 / 77            |\n| Total profit Long %         | 1250.58%            |\n| Total profit Short %        | -15.02%             |\n| Absolute profit Long        | 0.00838792 BTC      |\n| Absolute profit Short       | -0.00076 BTC        |\n|                             |                     |\n| Best Pair                   | LSK/BTC 26.26%      |\n| Worst Pair                  | ZEC/BTC -10.18%     |\n| Best Trade                  | LSK/BTC 4.25%       |\n| Worst Trade                 | ZEC/BTC -10.25%     |\n| Best day                    | 0.00076 BTC         |\n| Worst day                   | -0.00036 BTC        |\n| Days win/draw/lose          | 12 / 82 / 25        |\n| Avg. Duration Winners       | 4:23:00             |\n| Avg. Duration Loser         | 6:55:00             |\n| Max Consecutive Wins / Loss | 3 / 4               |\n| Rejected Entry signals      | 3089                |\n| Entry/Exit Timeouts         | 0 / 0               |\n| Canceled Trade Entries      | 34                  |\n| Canceled Entry Orders       | 123                 |\n| Replaced Entry Orders       | 89                  |\n|                             |                     |\n| Min balance                 | 0.00945123 BTC      |\n| Max balance                 | 0.01846651 BTC      |\n| Max % of account underwater | 25.19%              |\n| Absolute Drawdown (Account) | 13.33%              |\n| Drawdown                    | 0.0015 BTC          |\n| Drawdown high               | 0.0013 BTC          |\n| Drawdown low                | -0.0002 BTC         |\n| Drawdown Start              | 2019-02-15 14:10:00 |\n| Drawdown End                | 2019-04-11 18:15:00 |\n| Market change               | -5.88%              |\n=====================================================\n
    • Backtesting from / Backtesting to: Backtesting range (usually defined with the --timerange option).
    • Max open trades: Setting of max_open_trades (or --max-open-trades) - or number of pairs in the pairlist (whatever is lower).
    • Trading Mode: Spot or Futures trading.
    • Total/Daily Avg Trades: Identical to the total trades of the backtest output table / Total trades divided by the backtesting duration in days (this will give you information about how many trades to expect from the strategy).
    • Starting balance: Start balance - as given by dry-run-wallet (config or command line).
    • Final balance: Final balance - starting balance + absolute profit.
    • Absolute profit: Profit made in stake currency.
    • Total profit %: Total profit. Aligned to the TOTAL row's Tot Profit % from the first table. Calculated as (End capital \u2212 Starting capital) / Starting capital.
    • CAGR %: Compound annual growth rate.
    • Sortino: Annualized Sortino ratio.
    • Sharpe: Annualized Sharpe ratio.
    • Calmar: Annualized Calmar ratio.
    • Profit factor: profit / loss.
    • Avg. stake amount: Average stake amount, either stake_amount or the average when using dynamic stake amount.
    • Total trade volume: Volume generated on the exchange to reach the above profit.
    • Best Pair / Worst Pair: Best and worst performing pair, and it's corresponding Tot Profit %.
    • Best Trade / Worst Trade: Biggest single winning trade and biggest single losing trade.
    • Best day / Worst day: Best and worst day based on daily profit.
    • Days win/draw/lose: Winning / Losing days (draws are usually days without closed trade).
    • Avg. Duration Winners / Avg. Duration Loser: Average durations for winning and losing trades.
    • Max Consecutive Wins / Loss: Maximum consecutive wins/losses in a row.
    • Rejected Entry signals: Trade entry signals that could not be acted upon due to max_open_trades being reached.
    • Entry/Exit Timeouts: Entry/exit orders which did not fill (only applicable if custom pricing is used).
    • Canceled Trade Entries: Number of trades that have been canceled by user request via adjust_entry_price.
    • Canceled Entry Orders: Number of entry orders that have been canceled by user request via adjust_entry_price.
    • Replaced Entry Orders: Number of entry orders that have been replaced by user request via adjust_entry_price.
    • Min balance / Max balance: Lowest and Highest Wallet balance during the backtest period.
    • Max % of account underwater: Maximum percentage your account has decreased from the top since the simulation started. Calculated as the maximum of (Max Balance - Current Balance) / (Max Balance).
    • Absolute Drawdown (Account): Maximum Account Drawdown experienced. Calculated as (Absolute Drawdown) / (DrawdownHigh + startingBalance).
    • Drawdown: Maximum, absolute drawdown experienced. Difference between Drawdown High and Subsequent Low point.
    • Drawdown high / Drawdown low: Profit at the beginning and end of the largest drawdown period. A negative low value means initial capital lost.
    • Drawdown Start / Drawdown End: Start and end datetime for this largest drawdown (can also be visualized via the plot-dataframe sub-command).
    • Market change: Change of the market during the backtest period. Calculated as average of all pairs changes from the first to the last candle using the \"close\" column.
    • Long / Short: Split long/short values (Only shown when short trades were made).
    • Total profit Long % / Absolute profit Long: Profit long trades only (Only shown when short trades were made).
    • Total profit Short % / Absolute profit Short: Profit short trades only (Only shown when short trades were made).
    "},{"location":"backtesting/#daily-weekly-monthly-breakdown","title":"Daily / Weekly / Monthly breakdown","text":"

    You can get an overview over daily / weekly or monthly results by using the --breakdown <> switch.

    To visualize daily and weekly breakdowns, you can use the following:

    freqtrade backtesting --strategy MyAwesomeStrategy --breakdown day week\n
    ======================== DAY BREAKDOWN =========================\n|        Day |   Tot Profit USDT |   Wins |   Draws |   Losses |\n|------------+-------------------+--------+---------+----------|\n| 03/07/2021 |           200.0   |      2 |       0 |        0 |\n| 04/07/2021 |           -50.31  |      0 |       0 |        2 |\n| 05/07/2021 |           220.611 |      3 |       2 |        0 |\n| 06/07/2021 |           150.974 |      3 |       0 |        2 |\n| 07/07/2021 |           -70.193 |      1 |       0 |        2 |\n| 08/07/2021 |           212.413 |      2 |       0 |        3 |\n

    The output will show a table containing the realized absolute Profit (in stake currency) for the given timeperiod, as well as wins, draws and losses that materialized (closed) on this day. Below that there will be a second table for the summarized values of weeks indicated by the date of the closing Sunday. The same would apply to a monthly breakdown indicated by the last day of the month.

    "},{"location":"backtesting/#backtest-result-caching","title":"Backtest result caching","text":"

    To save time, by default backtest will reuse a cached result from within the last day when the backtested strategy and config match that of a previous backtest. To force a new backtest despite existing result for an identical run specify --cache none parameter.

    Warning

    Caching is automatically disabled for open-ended timeranges (--timerange 20210101-), as freqtrade cannot ensure reliably that the underlying data didn't change. It can also use cached results where it shouldn't if the original backtest had missing data at the end, which was fixed by downloading more data. In this instance, please use --cache none once to force a fresh backtest.

    "},{"location":"backtesting/#further-backtest-result-analysis","title":"Further backtest-result analysis","text":"

    To further analyze your backtest results, freqtrade will export the trades to file by default. You can then load the trades to perform further analysis as shown in the data analysis backtesting section.

    "},{"location":"backtesting/#assumptions-made-by-backtesting","title":"Assumptions made by backtesting","text":"

    Since backtesting lacks some detailed information about what happens within a candle, it needs to take a few assumptions:

    • Exchange trading limits are respected
    • Entries happen at open-price unless a custom price logic has been specified
    • All orders are filled at the requested price (no slippage) as long as the price is within the candle's high/low range
    • Exit-signal exits happen at open-price of the consecutive candle
    • Exits free their trade slot for a new trade with a different pair
    • Exit-signal is favored over Stoploss, because exit-signals are assumed to trigger on candle's open
    • ROI
      • Exits are compared to high - but the ROI value is used (e.g. ROI = 2%, high=5% - so the exit will be at 2%)
      • Exits are never \"below the candle\", so a ROI of 2% may result in a exit at 2.4% if low was at 2.4% profit
      • ROI entries which came into effect on the triggering candle (e.g. 120: 0.02 for 1h candles, from 60: 0.05) will use the candle's open as exit rate
      • Force-exits caused by <N>=-1 ROI entries use low as exit value, unless N falls on the candle open (e.g. 120: -1 for 1h candles)
    • Stoploss exits happen exactly at stoploss price, even if low was lower, but the loss will be 2 * fees higher than the stoploss price
    • Stoploss is evaluated before ROI within one candle. So you can often see more trades with the stoploss exit reason comparing to the results obtained with the same strategy in the Dry Run/Live Trade modes
    • Low happens before high for stoploss, protecting capital first
    • Trailing stoploss
      • Trailing Stoploss is only adjusted if it's below the candle's low (otherwise it would be triggered)
      • On trade entry candles that trigger trailing stoploss, the \"minimum offset\" (stop_positive_offset) is assumed (instead of high) - and the stop is calculated from this point. This rule is NOT applicable to custom-stoploss scenarios, since there's no information about the stoploss logic available.
      • High happens first - adjusting stoploss
      • Low uses the adjusted stoploss (so exits with large high-low difference are backtested correctly)
      • ROI applies before trailing-stop, ensuring profits are \"top-capped\" at ROI if both ROI and trailing stop applies
    • Exit-reason does not explain if a trade was positive or negative, just what triggered the exit (this can look odd if negative ROI values are used)
    • Evaluation sequence (if multiple signals happen on the same candle)
      • Exit-signal
      • Stoploss
      • ROI
      • Trailing stoploss

    Taking these assumptions, backtesting tries to mirror real trading as closely as possible. However, backtesting will never replace running a strategy in dry-run mode. Also, keep in mind that past results don't guarantee future success.

    In addition to the above assumptions, strategy authors should carefully read the Common Mistakes section, to avoid using data in backtesting which is not available in real market conditions.

    "},{"location":"backtesting/#trading-limits-in-backtesting","title":"Trading limits in backtesting","text":"

    Exchanges have certain trading limits, like minimum (and maximum) base currency, or minimum/maximum stake (quote) currency. These limits are usually listed in the exchange documentation as \"trading rules\" or similar and can be quite different between different pairs.

    Backtesting (as well as live and dry-run) does honor these limits, and will ensure that a stoploss can be placed below this value - so the value will be slightly higher than what the exchange specifies. Freqtrade has however no information about historic limits.

    This can lead to situations where trading-limits are inflated by using a historic price, resulting in minimum amounts > 50$.

    For example:

    BTC minimum tradable amount is 0.001. BTC trades at 22.000$ today (0.001 BTC is related to this) - but the backtesting period includes prices as high as 50.000$. Today's minimum would be 0.001 * 22_000 - or 22$. However the limit could also be 50$ - based on 0.001 * 50_000 in some historic setting.

    "},{"location":"backtesting/#trading-precision-limits","title":"Trading precision limits","text":"

    Most exchanges pose precision limits on both price and amounts, so you cannot buy 1.0020401 of a pair, or at a price of 1.24567123123. Instead, these prices and amounts will be rounded or truncated (based on the exchange definition) to the defined trading precision. The above values may for example be rounded to an amount of 1.002, and a price of 1.24567.

    These precision values are based on current exchange limits (as described in the above section), as historic precision limits are not available.

    "},{"location":"backtesting/#improved-backtest-accuracy","title":"Improved backtest accuracy","text":"

    One big limitation of backtesting is it's inability to know how prices moved intra-candle (was high before close, or vice-versa?). So assuming you run backtesting with a 1h timeframe, there will be 4 prices for that candle (Open, High, Low, Close).

    While backtesting does take some assumptions (read above) about this - this can never be perfect, and will always be biased in one way or the other. To mitigate this, freqtrade can use a lower (faster) timeframe to simulate intra-candle movements.

    To utilize this, you can append --timeframe-detail 5m to your regular backtesting command.

    freqtrade backtesting --strategy AwesomeStrategy --timeframe 1h --timeframe-detail 5m\n

    This will load 1h data as well as 5m data for the timeframe. The strategy will be analyzed with the 1h timeframe, and Entry orders will only be placed at the main timeframe, however Order fills and exit signals will be evaluated at the 5m candle, simulating intra-candle movements.

    All callback functions (custom_exit(), custom_stoploss(), ... ) will be running for each 5m candle once the trade is opened (so 12 times in the above example of 1h timeframe, and 5m detailed timeframe).

    --timeframe-detail must be smaller than the original timeframe, otherwise backtesting will fail to start.

    Obviously this will require more memory (5m data is bigger than 1h data), and will also impact runtime (depending on the amount of trades and trade durations). Also, data must be available / downloaded already.

    Tip

    You can use this function as the last part of strategy development, to ensure your strategy is not exploiting one of the backtesting assumptions. Strategies that perform similarly well with this mode have a good chance to perform well in dry/live modes too (although only forward-testing (dry-mode) can really confirm a strategy).

    "},{"location":"backtesting/#backtesting-multiple-strategies","title":"Backtesting multiple strategies","text":"

    To compare multiple strategies, a list of Strategies can be provided to backtesting.

    This is limited to 1 timeframe value per run. However, data is only loaded once from disk so if you have multiple strategies you'd like to compare, this will give a nice runtime boost.

    All listed Strategies need to be in the same directory, unless also --recursive-strategy-search is specified, where sub-directories within the strategy directory are also considered.

    freqtrade backtesting --timerange 20180401-20180410 --timeframe 5m --strategy-list Strategy001 Strategy002 --export trades\n

    This will save the results to user_data/backtest_results/backtest-result-<datetime>.json, including results for both Strategy001 and Strategy002. There will be an additional table comparing win/losses of the different strategies (identical to the \"Total\" row in the first table). Detailed output for all strategies one after the other will be available, so make sure to scroll up to see the details per strategy.

    ================================================== STRATEGY SUMMARY ===================================================================\n| Strategy    |  Trades |   Avg Profit % |   Tot Profit BTC |   Tot Profit % | Avg Duration   |  Wins |  Draws | Losses | Drawdown % |\n|-------------+---------+----------------+------------------+----------------+----------------+-------+--------+--------+------------|\n| Strategy1   |     429 |           0.36 |       0.00762792 |          76.20 | 4:12:00        |   186 |      0 |    243 |       45.2 |\n| Strategy2   |    1487 |          -0.13 |      -0.00988917 |         -98.79 | 4:43:00        |   662 |      0 |    825 |     241.68 |\n
    "},{"location":"backtesting/#next-step","title":"Next step","text":"

    Great, your strategy is profitable. What if the bot can give your the optimal parameters to use for your strategy? Your next step is to learn how to find optimal parameters with Hyperopt

    "},{"location":"bot-basics/","title":"Freqtrade basics","text":"

    This page provides you some basic concepts on how Freqtrade works and operates.

    "},{"location":"bot-basics/#freqtrade-terminology","title":"Freqtrade terminology","text":"
    • Strategy: Your trading strategy, telling the bot what to do.
    • Trade: Open position.
    • Open Order: Order which is currently placed on the exchange, and is not yet complete.
    • Pair: Tradable pair, usually in the format of Base/Quote (e.g. XRP/USDT for spot, XRP/USDT:USDT for futures).
    • Timeframe: Candle length to use (e.g. \"5m\", \"1h\", ...).
    • Indicators: Technical indicators (SMA, EMA, RSI, ...).
    • Limit order: Limit orders which execute at the defined limit price or better.
    • Market order: Guaranteed to fill, may move price depending on the order size.
    • Current Profit: Currently pending (unrealized) profit for this trade. This is mainly used throughout the bot and UI.
    • Realized Profit: Already realized profit. Only relevant in combination with partial exits - which also explains the calculation logic for this.
    • Total Profit: Combined realized and unrealized profit. The relative number (%) is calculated against the total investment in this trade.
    "},{"location":"bot-basics/#fee-handling","title":"Fee handling","text":"

    All profit calculations of Freqtrade include fees. For Backtesting / Hyperopt / Dry-run modes, the exchange default fee is used (lowest tier on the exchange). For live operations, fees are used as applied by the exchange (this includes BNB rebates etc.).

    "},{"location":"bot-basics/#pair-naming","title":"Pair naming","text":"

    Freqtrade follows the ccxt naming convention for currencies. Using the wrong naming convention in the wrong market will usually result in the bot not recognizing the pair, usually resulting in errors like \"this pair is not available\".

    "},{"location":"bot-basics/#spot-pair-naming","title":"Spot pair naming","text":"

    For spot pairs, naming will be base/quote (e.g. ETH/USDT).

    "},{"location":"bot-basics/#futures-pair-naming","title":"Futures pair naming","text":"

    For futures pairs, naming will be base/quote:settle (e.g. ETH/USDT:USDT).

    "},{"location":"bot-basics/#bot-execution-logic","title":"Bot execution logic","text":"

    Starting freqtrade in dry-run or live mode (using freqtrade trade) will start the bot and start the bot iteration loop. This will also run the bot_start() callback.

    By default, the bot loop runs every few seconds (internals.process_throttle_secs) and performs the following actions:

    • Fetch open trades from persistence.
    • Calculate current list of tradable pairs.
    • Download OHLCV data for the pairlist including all informative pairs This step is only executed once per Candle to avoid unnecessary network traffic.
    • Call bot_loop_start() strategy callback.
    • Analyze strategy per pair.
      • Call populate_indicators()
      • Call populate_entry_trend()
      • Call populate_exit_trend()
    • Update trades open order state from exchange.
      • Call order_filled() strategy callback for filled orders.
      • Check timeouts for open orders.
        • Calls check_entry_timeout() strategy callback for open entry orders.
        • Calls check_exit_timeout() strategy callback for open exit orders.
        • Calls adjust_entry_price() strategy callback for open entry orders.
    • Verifies existing positions and eventually places exit orders.
      • Considers stoploss, ROI and exit-signal, custom_exit() and custom_stoploss().
      • Determine exit-price based on exit_pricing configuration setting or by using the custom_exit_price() callback.
      • Before a exit order is placed, confirm_trade_exit() strategy callback is called.
    • Check position adjustments for open trades if enabled by calling adjust_trade_position() and place additional order if required.
    • Check if trade-slots are still available (if max_open_trades is reached).
    • Verifies entry signal trying to enter new positions.
      • Determine entry-price based on entry_pricing configuration setting, or by using the custom_entry_price() callback.
      • In Margin and Futures mode, leverage() strategy callback is called to determine the desired leverage.
      • Determine stake size by calling the custom_stake_amount() callback.
      • Before an entry order is placed, confirm_trade_entry() strategy callback is called.

    This loop will be repeated again and again until the bot is stopped.

    "},{"location":"bot-basics/#backtesting-hyperopt-execution-logic","title":"Backtesting / Hyperopt execution logic","text":"

    backtesting or hyperopt do only part of the above logic, since most of the trading operations are fully simulated.

    • Load historic data for configured pairlist.
    • Calls bot_start() once.
    • Calculate indicators (calls populate_indicators() once per pair).
    • Calculate entry / exit signals (calls populate_entry_trend() and populate_exit_trend() once per pair).
    • Loops per candle simulating entry and exit points.
      • Calls bot_loop_start() strategy callback.
      • Check for Order timeouts, either via the unfilledtimeout configuration, or via check_entry_timeout() / check_exit_timeout() strategy callbacks.
      • Calls adjust_entry_price() strategy callback for open entry orders.
      • Check for trade entry signals (enter_long / enter_short columns).
      • Confirm trade entry / exits (calls confirm_trade_entry() and confirm_trade_exit() if implemented in the strategy).
      • Call custom_entry_price() (if implemented in the strategy) to determine entry price (Prices are moved to be within the opening candle).
      • In Margin and Futures mode, leverage() strategy callback is called to determine the desired leverage.
      • Determine stake size by calling the custom_stake_amount() callback.
      • Check position adjustments for open trades if enabled and call adjust_trade_position() to determine if an additional order is requested.
      • Call order_filled() strategy callback for filled entry orders.
      • Call custom_stoploss() and custom_exit() to find custom exit points.
      • For exits based on exit-signal, custom-exit and partial exits: Call custom_exit_price() to determine exit price (Prices are moved to be within the closing candle).
      • Call order_filled() strategy callback for filled exit orders.
    • Generate backtest report output

    Note

    Both Backtesting and Hyperopt include exchange default Fees in the calculation. Custom fees can be passed to backtesting / hyperopt by specifying the --fee argument.

    Callback call frequency

    Backtesting will call each callback at max. once per candle (--timeframe-detail modifies this behavior to once per detailed candle). Most callbacks will be called once per iteration in live (usually every ~5s) - which can cause backtesting mismatches.

    "},{"location":"bot-usage/","title":"Start the bot","text":"

    This page explains the different parameters of the bot and how to run it.

    Note

    If you've used setup.sh, don't forget to activate your virtual environment (source .venv/bin/activate) before running freqtrade commands.

    Up-to-date clock

    The clock on the system running the bot must be accurate, synchronized to a NTP server frequently enough to avoid problems with communication to the exchanges.

    "},{"location":"bot-usage/#bot-commands","title":"Bot commands","text":"
    usage: freqtrade [-h] [-V]\n                 {trade,create-userdir,new-config,show-config,new-strategy,download-data,convert-data,convert-trade-data,trades-to-ohlcv,list-data,backtesting,backtesting-show,backtesting-analysis,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-markets,list-pairs,list-strategies,list-freqaimodels,list-timeframes,show-trades,test-pairlist,convert-db,install-ui,plot-dataframe,plot-profit,webserver,strategy-updater,lookahead-analysis,recursive-analysis}\n                 ...\n\nFree, open source crypto trading bot\n\npositional arguments:\n  {trade,create-userdir,new-config,show-config,new-strategy,download-data,convert-data,convert-trade-data,trades-to-ohlcv,list-data,backtesting,backtesting-show,backtesting-analysis,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-markets,list-pairs,list-strategies,list-freqaimodels,list-timeframes,show-trades,test-pairlist,convert-db,install-ui,plot-dataframe,plot-profit,webserver,strategy-updater,lookahead-analysis,recursive-analysis}\n    trade               Trade module.\n    create-userdir      Create user-data directory.\n    new-config          Create new config\n    show-config         Show resolved config\n    new-strategy        Create new strategy\n    download-data       Download backtesting data.\n    convert-data        Convert candle (OHLCV) data from one format to\n                        another.\n    convert-trade-data  Convert trade data from one format to another.\n    trades-to-ohlcv     Convert trade data to OHLCV data.\n    list-data           List downloaded data.\n    backtesting         Backtesting module.\n    backtesting-show    Show past Backtest results\n    backtesting-analysis\n                        Backtest Analysis module.\n    edge                Edge module.\n    hyperopt            Hyperopt module.\n    hyperopt-list       List Hyperopt results\n    hyperopt-show       Show details of Hyperopt results\n    list-exchanges      Print available exchanges.\n    list-markets        Print markets on exchange.\n    list-pairs          Print pairs on exchange.\n    list-strategies     Print available strategies.\n    list-freqaimodels   Print available freqAI models.\n    list-timeframes     Print available timeframes for the exchange.\n    show-trades         Show trades.\n    test-pairlist       Test your pairlist configuration.\n    convert-db          Migrate database to different system\n    install-ui          Install FreqUI\n    plot-dataframe      Plot candles with indicators.\n    plot-profit         Generate plot showing profits.\n    webserver           Webserver module.\n    strategy-updater    updates outdated strategy files to the current version\n    lookahead-analysis  Check for potential look ahead bias.\n    recursive-analysis  Check for potential recursive formula issue.\n\noptions:\n  -h, --help            show this help message and exit\n  -V, --version         show program's version number and exit\n
    "},{"location":"bot-usage/#bot-trading-commands","title":"Bot trading commands","text":"
    usage: freqtrade trade [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                       [--userdir PATH] [-s NAME] [--strategy-path PATH]\n                       [--db-url PATH] [--sd-notify] [--dry-run]\n                       [--dry-run-wallet DRY_RUN_WALLET]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --sd-notify           Notify systemd service manager.\n  --dry-run             Enforce dry-run for trading (removes Exchange secrets\n                        and simulates trades).\n  --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET\n                        Starting balance, used for backtesting / hyperopt and\n                        dry-runs.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n
    "},{"location":"bot-usage/#how-to-specify-which-configuration-file-be-used","title":"How to specify which configuration file be used?","text":"

    The bot allows you to select which configuration file you want to use by means of the -c/--config command line option:

    freqtrade trade -c path/far/far/away/config.json\n

    Per default, the bot loads the config.json configuration file from the current working directory.

    "},{"location":"bot-usage/#how-to-use-multiple-configuration-files","title":"How to use multiple configuration files?","text":"

    The bot allows you to use multiple configuration files by specifying multiple -c/--config options in the command line. Configuration parameters defined in the latter configuration files override parameters with the same name defined in the previous configuration files specified in the command line earlier.

    For example, you can make a separate configuration file with your key and secret for the Exchange you use for trading, specify default configuration file with empty key and secret values while running in the Dry Mode (which does not actually require them):

    freqtrade trade -c ./config.json\n

    and specify both configuration files when running in the normal Live Trade Mode:

    freqtrade trade -c ./config.json -c path/to/secrets/keys.config.json\n

    This could help you hide your private Exchange key and Exchange secret on you local machine by setting appropriate file permissions for the file which contains actual secrets and, additionally, prevent unintended disclosure of sensitive private data when you publish examples of your configuration in the project issues or in the Internet.

    See more details on this technique with examples in the documentation page on configuration.

    "},{"location":"bot-usage/#where-to-store-custom-data","title":"Where to store custom data","text":"

    Freqtrade allows the creation of a user-data directory using freqtrade create-userdir --userdir someDirectory. This directory will look as follows:

    user_data/\n\u251c\u2500\u2500 backtest_results\n\u251c\u2500\u2500 data\n\u251c\u2500\u2500 hyperopts\n\u251c\u2500\u2500 hyperopt_results\n\u251c\u2500\u2500 plot\n\u2514\u2500\u2500 strategies\n

    You can add the entry \"user_data_dir\" setting to your configuration, to always point your bot to this directory. Alternatively, pass in --userdir to every command. The bot will fail to start if the directory does not exist, but will create necessary subdirectories.

    This directory should contain your custom strategies, custom hyperopts and hyperopt loss functions, backtesting historical data (downloaded using either backtesting command or the download script) and plot outputs.

    It is recommended to use version control to keep track of changes to your strategies.

    "},{"location":"bot-usage/#how-to-use-strategy","title":"How to use --strategy?","text":"

    This parameter will allow you to load your custom strategy class. To test the bot installation, you can use the SampleStrategy installed by the create-userdir subcommand (usually user_data/strategy/sample_strategy.py).

    The bot will search your strategy file within user_data/strategies. To use other directories, please read the next section about --strategy-path.

    To load a strategy, simply pass the class name (e.g.: CustomStrategy) in this parameter.

    Example: In user_data/strategies you have a file my_awesome_strategy.py which has a strategy class called AwesomeStrategy to load it:

    freqtrade trade --strategy AwesomeStrategy\n

    If the bot does not find your strategy file, it will display in an error message the reason (File not found, or errors in your code).

    Learn more about strategy file in Strategy Customization.

    "},{"location":"bot-usage/#how-to-use-strategy-path","title":"How to use --strategy-path?","text":"

    This parameter allows you to add an additional strategy lookup path, which gets checked before the default locations (The passed path must be a directory!):

    freqtrade trade --strategy AwesomeStrategy --strategy-path /some/directory\n
    "},{"location":"bot-usage/#how-to-install-a-strategy","title":"How to install a strategy?","text":"

    This is very simple. Copy paste your strategy file into the directory user_data/strategies or use --strategy-path. And voila, the bot is ready to use it.

    "},{"location":"bot-usage/#how-to-use-db-url","title":"How to use --db-url?","text":"

    When you run the bot in Dry-run mode, per default no transactions are stored in a database. If you want to store your bot actions in a DB using --db-url. This can also be used to specify a custom database in production mode. Example command:

    freqtrade trade -c config.json --db-url sqlite:///tradesv3.dry_run.sqlite\n
    "},{"location":"bot-usage/#next-step","title":"Next step","text":"

    The optimal strategy of the bot will change with time depending of the market trends. The next step is to Strategy Customization.

    "},{"location":"configuration/","title":"Configure the bot","text":"

    Freqtrade has many configurable features and possibilities. By default, these settings are configured via the configuration file (see below).

    "},{"location":"configuration/#the-freqtrade-configuration-file","title":"The Freqtrade configuration file","text":"

    The bot uses a set of configuration parameters during its operation that all together conform to the bot configuration. It normally reads its configuration from a file (Freqtrade configuration file).

    Per default, the bot loads the configuration from the config.json file, located in the current working directory.

    You can specify a different configuration file used by the bot with the -c/--config command-line option.

    If you used the Quick start method for installing the bot, the installation script should have already created the default configuration file (config.json) for you.

    If the default configuration file is not created we recommend to use freqtrade new-config --config user_data/config.json to generate a basic configuration file.

    The Freqtrade configuration file is to be written in JSON format.

    Additionally to the standard JSON syntax, you may use one-line // ... and multi-line /* ... */ comments in your configuration files and trailing commas in the lists of parameters.

    Do not worry if you are not familiar with JSON format -- simply open the configuration file with an editor of your choice, make some changes to the parameters you need, save your changes and, finally, restart the bot or, if it was previously stopped, run it again with the changes you made to the configuration. The bot validates the syntax of the configuration file at startup and will warn you if you made any errors editing it, pointing out problematic lines.

    "},{"location":"configuration/#environment-variables","title":"Environment variables","text":"

    Set options in the Freqtrade configuration via environment variables. This takes priority over the corresponding value in configuration or strategy.

    Environment variables must be prefixed with FREQTRADE__ to be loaded to the freqtrade configuration.

    __ serves as level separator, so the format used should correspond to FREQTRADE__{section}__{key}. As such - an environment variable defined as export FREQTRADE__STAKE_AMOUNT=200 would result in {stake_amount: 200}.

    A more complex example might be export FREQTRADE__EXCHANGE__KEY=<yourExchangeKey> to keep your exchange key secret. This will move the value to the exchange.key section of the configuration. Using this scheme, all configuration settings will also be available as environment variables.

    Please note that Environment variables will overwrite corresponding settings in your configuration, but command line Arguments will always win.

    Common example:

    FREQTRADE__TELEGRAM__CHAT_ID=<telegramchatid>\nFREQTRADE__TELEGRAM__TOKEN=<telegramToken>\nFREQTRADE__EXCHANGE__KEY=<yourExchangeKey>\nFREQTRADE__EXCHANGE__SECRET=<yourExchangeSecret>\n

    Note

    Environment variables detected are logged at startup - so if you can't find why a value is not what you think it should be based on the configuration, make sure it's not loaded from an environment variable.

    Validate combined result

    You can use the show-config subcommand to see the final, combined configuration.

    Loading sequence

    Environment variables are loaded after the initial configuration. As such, you cannot provide the path to the configuration through environment variables. Please use --config path/to/config.json for that. This also applies to user_dir to some degree. while the user directory can be set through environment variables - the configuration will not be loaded from that location.

    "},{"location":"configuration/#multiple-configuration-files","title":"Multiple configuration files","text":"

    Multiple configuration files can be specified and used by the bot or the bot can read its configuration parameters from the process standard input stream.

    You can specify additional configuration files in add_config_files. Files specified in this parameter will be loaded and merged with the initial config file. The files are resolved relative to the initial configuration file. This is similar to using multiple --config parameters, but simpler in usage as you don't have to specify all files for all commands.

    Validate combined result

    You can use the show-config subcommand to see the final, combined configuration.

    Use multiple configuration files to keep secrets secret

    You can use a 2nd configuration file containing your secrets. That way you can share your \"primary\" configuration file, while still keeping your API keys for yourself. The 2nd file should only specify what you intend to override. If a key is in more than one of the configurations, then the \"last specified configuration\" wins (in the above example, config-private.json).

    For one-off commands, you can also use the below syntax by specifying multiple \"--config\" parameters.

    freqtrade trade --config user_data/config1.json --config user_data/config-private.json <...>\n

    The below is equivalent to the example above - but having 2 configuration files in the configuration, for easier reuse.

    user_data/config.json
    \"add_config_files\": [\n    \"config1.json\",\n    \"config-private.json\"\n]\n
    freqtrade trade --config user_data/config.json <...>\n
    config collision handling

    If the same configuration setting takes place in both config.json and config-import.json, then the parent configuration wins. In the below case, max_open_trades would be 3 after the merging - as the reusable \"import\" configuration has this key overwritten.

    user_data/config.json
    {\n    \"max_open_trades\": 3,\n    \"stake_currency\": \"USDT\",\n    \"add_config_files\": [\n        \"config-import.json\"\n    ]\n}\n
    user_data/config-import.json
    {\n    \"max_open_trades\": 10,\n    \"stake_amount\": \"unlimited\",\n}\n

    Resulting combined configuration:

    Result
    {\n    \"max_open_trades\": 3,\n    \"stake_currency\": \"USDT\",\n    \"stake_amount\": \"unlimited\"\n}\n

    If multiple files are in the add_config_files section, then they will be assumed to be at identical levels, having the last occurrence override the earlier config (unless a parent already defined such a key).

    "},{"location":"configuration/#editor-autocomplete-and-validation","title":"Editor autocomplete and validation","text":"

    If you are using an editor that supports JSON schema, you can use the schema provided by Freqtrade to get autocompletion and validation of your configuration file by adding the following line to the top of your configuration file:

    {\n    \"$schema\": \"https://schema.freqtrade.io/schema.json\",\n}\n
    Develop version

    The develop schema is available as https://schema.freqtrade.io/schema_dev.json - though we recommend to stick to the stable version for the best experience.

    "},{"location":"configuration/#configuration-parameters","title":"Configuration parameters","text":"

    The table below will list all configuration parameters available.

    Freqtrade can also load many options via command line (CLI) arguments (check out the commands --help output for details).

    "},{"location":"configuration/#configuration-option-prevalence","title":"Configuration option prevalence","text":"

    The prevalence for all Options is as follows:

    • CLI arguments override any other option
    • Environment Variables
    • Configuration files are used in sequence (the last file wins) and override Strategy configurations.
    • Strategy configurations are only used if they are not set via configuration or command-line arguments. These options are marked with Strategy Override in the below table.
    "},{"location":"configuration/#parameters-table","title":"Parameters table","text":"

    Mandatory parameters are marked as Required, which means that they are required to be set in one of the possible ways.

    Parameter Description max_open_trades Required. Number of open trades your bot is allowed to have. Only one open trade per pair is possible, so the length of your pairlist is another limitation that can apply. If -1 then it is ignored (i.e. potentially unlimited open trades, limited by the pairlist). More information below. Strategy Override. Datatype: Positive integer or -1. stake_currency Required. Crypto-currency used for trading. Datatype: String stake_amount Required. Amount of crypto-currency your bot will use for each trade. Set it to \"unlimited\" to allow the bot to use all available balance. More information below. Datatype: Positive float or \"unlimited\". tradable_balance_ratio Ratio of the total account balance the bot is allowed to trade. More information below. Defaults to 0.99 99%). Datatype: Positive float between 0.1 and 1.0. available_capital Available starting capital for the bot. Useful when running multiple bots on the same exchange account. More information below. Datatype: Positive float. amend_last_stake_amount Use reduced last stake amount if necessary. More information below. Defaults to false. Datatype: Boolean last_stake_amount_min_ratio Defines minimum stake amount that has to be left and executed. Applies only to the last stake amount when it's amended to a reduced value (i.e. if amend_last_stake_amount is set to true). More information below. Defaults to 0.5. Datatype: Float (as ratio) amount_reserve_percent Reserve some amount in min pair stake amount. The bot will reserve amount_reserve_percent + stoploss value when calculating min pair stake amount in order to avoid possible trade refusals. Defaults to 0.05 (5%). Datatype: Positive Float as ratio. timeframe The timeframe to use (e.g 1m, 5m, 15m, 30m, 1h ...). Usually missing in configuration, and specified in the strategy. Strategy Override. Datatype: String fiat_display_currency Fiat currency used to show your profits. More information below. Datatype: String dry_run Required. Define if the bot must be in Dry Run or production mode. Defaults to true. Datatype: Boolean dry_run_wallet Define the starting amount in stake currency for the simulated wallet used by the bot running in Dry Run mode.Defaults to 1000. Datatype: Float cancel_open_orders_on_exit Cancel open orders when the /stop RPC command is issued, Ctrl+C is pressed or the bot dies unexpectedly. When set to true, this allows you to use /stop to cancel unfilled and partially filled orders in the event of a market crash. It does not impact open positions. Defaults to false. Datatype: Boolean process_only_new_candles Enable processing of indicators only when new candles arrive. If false each loop populates the indicators, this will mean the same candle is processed many times creating system load but can be useful of your strategy depends on tick data not only candle. Strategy Override. Defaults to true. Datatype: Boolean minimal_roi Required. Set the threshold as ratio the bot will use to exit a trade. More information below. Strategy Override. Datatype: Dict stoploss Required. Value as ratio of the stoploss used by the bot. More details in the stoploss documentation. Strategy Override. Datatype: Float (as ratio) trailing_stop Enables trailing stoploss (based on stoploss in either configuration or strategy file). More details in the stoploss documentation. Strategy Override. Datatype: Boolean trailing_stop_positive Changes stoploss once profit has been reached. More details in the stoploss documentation. Strategy Override. Datatype: Float trailing_stop_positive_offset Offset on when to apply trailing_stop_positive. Percentage value which should be positive. More details in the stoploss documentation. Strategy Override. Defaults to 0.0 (no offset). Datatype: Float trailing_only_offset_is_reached Only apply trailing stoploss when the offset is reached. stoploss documentation. Strategy Override. Defaults to false. Datatype: Boolean fee Fee used during backtesting / dry-runs. Should normally not be configured, which has freqtrade fall back to the exchange default fee. Set as ratio (e.g. 0.001 = 0.1%). Fee is applied twice for each trade, once when buying, once when selling. Datatype: Float (as ratio) futures_funding_rate User-specified funding rate to be used when historical funding rates are not available from the exchange. This does not overwrite real historical rates. It is recommended that this be set to 0 unless you are testing a specific coin and you understand how the funding rate will affect freqtrade's profit calculations. More information here Defaults to None. Datatype: Float trading_mode Specifies if you want to trade regularly, trade with leverage, or trade contracts whose prices are derived from matching cryptocurrency prices. leverage documentation. Defaults to \"spot\". Datatype: String margin_mode When trading with leverage, this determines if the collateral owned by the trader will be shared or isolated to each trading pair leverage documentation. Datatype: String liquidation_buffer A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price leverage documentation. Defaults to 0.05. Datatype: Float Unfilled timeout unfilledtimeout.entry Required. How long (in minutes or seconds) the bot will wait for an unfilled entry order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. Strategy Override. Datatype: Integer unfilledtimeout.exit Required. How long (in minutes or seconds) the bot will wait for an unfilled exit order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. Strategy Override. Datatype: Integer unfilledtimeout.unit Unit to use in unfilledtimeout setting. Note: If you set unfilledtimeout.unit to \"seconds\", \"internals.process_throttle_secs\" must be inferior or equal to timeout Strategy Override. Defaults to \"minutes\". Datatype: String unfilledtimeout.exit_timeout_count How many times can exit orders time out. Once this number of timeouts is reached, an emergency exit is triggered. 0 to disable and allow unlimited order cancels. Strategy Override.Defaults to 0. Datatype: Integer Pricing entry_pricing.price_side Select the side of the spread the bot should look at to get the entry rate. More information below. Defaults to \"same\". Datatype: String (either ask, bid, same or other). entry_pricing.price_last_balance Required. Interpolate the bidding price. More information below. entry_pricing.use_order_book Enable entering using the rates in Order Book Entry. Defaults to true. Datatype: Boolean entry_pricing.order_book_top Bot will use the top N rate in Order Book \"price_side\" to enter a trade. I.e. a value of 2 will allow the bot to pick the 2nd entry in Order Book Entry. Defaults to 1. Datatype: Positive Integer entry_pricing. check_depth_of_market.enabled Do not enter if the difference of buy orders and sell orders is met in Order Book. Check market depth. Defaults to false. Datatype: Boolean entry_pricing. check_depth_of_market.bids_to_ask_delta The difference ratio of buy orders and sell orders found in Order Book. A value below 1 means sell order size is greater, while value greater than 1 means buy order size is higher. Check market depth Defaults to 0. Datatype: Float (as ratio) exit_pricing.price_side Select the side of the spread the bot should look at to get the exit rate. More information below. Defaults to \"same\". Datatype: String (either ask, bid, same or other). exit_pricing.price_last_balance Interpolate the exiting price. More information below. exit_pricing.use_order_book Enable exiting of open trades using Order Book Exit. Defaults to true. Datatype: Boolean exit_pricing.order_book_top Bot will use the top N rate in Order Book \"price_side\" to exit. I.e. a value of 2 will allow the bot to pick the 2nd ask rate in Order Book ExitDefaults to 1. Datatype: Positive Integer custom_price_max_distance_ratio Configure maximum distance ratio between current and custom entry or exit price. Defaults to 0.02 2%). Datatype: Positive float TODO use_exit_signal Use exit signals produced by the strategy in addition to the minimal_roi. Setting this to false disables the usage of \"exit_long\" and \"exit_short\" columns. Has no influence on other exit methods (Stoploss, ROI, callbacks). Strategy Override. Defaults to true. Datatype: Boolean exit_profit_only Wait until the bot reaches exit_profit_offset before taking an exit decision. Strategy Override. Defaults to false. Datatype: Boolean exit_profit_offset Exit-signal is only active above this value. Only active in combination with exit_profit_only=True. Strategy Override. Defaults to 0.0. Datatype: Float (as ratio) ignore_roi_if_entry_signal Do not exit if the entry signal is still active. This setting takes preference over minimal_roi and use_exit_signal. Strategy Override. Defaults to false. Datatype: Boolean ignore_buying_expired_candle_after Specifies the number of seconds until a buy signal is no longer used. Datatype: Integer order_types Configure order-types depending on the action (\"entry\", \"exit\", \"stoploss\", \"stoploss_on_exchange\"). More information below. Strategy Override. Datatype: Dict order_time_in_force Configure time in force for entry and exit orders. More information below. Strategy Override. Datatype: Dict position_adjustment_enable Enables the strategy to use position adjustments (additional buys or sells). More information here. Strategy Override. Defaults to false. Datatype: Boolean max_entry_position_adjustment Maximum additional order(s) for each open trade on top of the first entry Order. Set it to -1 for unlimited additional orders. More information here. Strategy Override. Defaults to -1. Datatype: Positive Integer or -1 Exchange exchange.name Required. Name of the exchange class to use. Datatype: String exchange.key API key to use for the exchange. Only required when you are in production mode.Keep it in secret, do not disclose publicly. Datatype: String exchange.secret API secret to use for the exchange. Only required when you are in production mode.Keep it in secret, do not disclose publicly. Datatype: String exchange.password API password to use for the exchange. Only required when you are in production mode and for exchanges that use password for API requests.Keep it in secret, do not disclose publicly. Datatype: String exchange.uid API uid to use for the exchange. Only required when you are in production mode and for exchanges that use uid for API requests.Keep it in secret, do not disclose publicly. Datatype: String exchange.pair_whitelist List of pairs to use by the bot for trading and to check for potential trades during backtesting. Supports regex pairs as .*/BTC. Not used by VolumePairList. More information. Datatype: List exchange.pair_blacklist List of pairs the bot must absolutely avoid for trading and backtesting. More information. Datatype: List exchange.ccxt_config Additional CCXT parameters passed to both ccxt instances (sync and async). This is usually the correct place for additional ccxt configurations. Parameters may differ from exchange to exchange and are documented in the ccxt documentation. Please avoid adding exchange secrets here (use the dedicated fields instead), as they may be contained in logs. Datatype: Dict exchange.ccxt_sync_config Additional CCXT parameters passed to the regular (sync) ccxt instance. Parameters may differ from exchange to exchange and are documented in the ccxt documentation Datatype: Dict exchange.ccxt_async_config Additional CCXT parameters passed to the async ccxt instance. Parameters may differ from exchange to exchange and are documented in the ccxt documentation Datatype: Dict exchange.enable_ws Enable the usage of Websockets for the exchange. More information.Defaults to true. Datatype: Boolean exchange.markets_refresh_interval The interval in minutes in which markets are reloaded. Defaults to 60 minutes. Datatype: Positive Integer exchange.skip_pair_validation Skip pairlist validation on startup.Defaults to false Datatype: Boolean exchange.skip_open_order_update Skips open order updates on startup should the exchange cause problems. Only relevant in live conditions.Defaults to false Datatype: Boolean exchange.unknown_fee_rate Fallback value to use when calculating trading fees. This can be useful for exchanges which have fees in non-tradable currencies. The value provided here will be multiplied with the \"fee cost\".Defaults to None Datatype:* float exchange.log_responses Log relevant exchange responses. For debug mode only - use with care.Defaults to false Datatype: Boolean experimental.block_bad_exchanges Block exchanges known to not work with freqtrade. Leave on default unless you want to test if that exchange works now. Defaults to true. Datatype: Boolean Plugins edge.* Please refer to edge configuration document for detailed explanation of all possible configuration options. pairlists Define one or more pairlists to be used. More information. Defaults to StaticPairList. Datatype: List of Dicts protections Define one or more protections to be used. More information. Datatype: List of Dicts Telegram telegram.enabled Enable the usage of Telegram. Datatype: Boolean telegram.token Your Telegram bot token. Only required if telegram.enabled is true. Keep it in secret, do not disclose publicly. Datatype: String telegram.chat_id Your personal Telegram account id. Only required if telegram.enabled is true. Keep it in secret, do not disclose publicly. Datatype: String telegram.balance_dust_level Dust-level (in stake currency) - currencies with a balance below this will not be shown by /balance. Datatype: float telegram.reload Allow \"reload\" buttons on telegram messages. Defaults to true. Datatype:* boolean telegram.notification_settings.* Detailed notification settings. Refer to the telegram documentation for details. Datatype: dictionary telegram.allow_custom_messages Enable the sending of Telegram messages from strategies via the dataprovider.send_msg() function. Datatype: Boolean Webhook webhook.enabled Enable usage of Webhook notifications Datatype: Boolean webhook.url URL for the webhook. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.entry Payload to send on entry. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.entry_cancel Payload to send on entry order cancel. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.entry_fill Payload to send on entry order filled. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.exit Payload to send on exit. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.exit_cancel Payload to send on exit order cancel. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.exit_fill Payload to send on exit order filled. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.status Payload to send on status calls. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.allow_custom_messages Enable the sending of Webhook messages from strategies via the dataprovider.send_msg() function. Datatype: Boolean Rest API / FreqUI / Producer-Consumer api_server.enabled Enable usage of API Server. See the API Server documentation for more details. Datatype: Boolean api_server.listen_ip_address Bind IP address. See the API Server documentation for more details. Datatype: IPv4 api_server.listen_port Bind Port. See the API Server documentation for more details. Datatype: Integer between 1024 and 65535 api_server.verbosity Logging verbosity. info will print all RPC Calls, while \"error\" will only display errors. Datatype: Enum, either info or error. Defaults to info. api_server.username Username for API server. See the API Server documentation for more details. Keep it in secret, do not disclose publicly. Datatype: String api_server.password Password for API server. See the API Server documentation for more details. Keep it in secret, do not disclose publicly. Datatype: String api_server.ws_token API token for the Message WebSocket. See the API Server documentation for more details. Keep it in secret, do not disclose publicly. Datatype: String bot_name Name of the bot. Passed via API to a client - can be shown to distinguish / name bots. Defaults to freqtrade Datatype: String external_message_consumer Enable Producer/Consumer mode for more details. Datatype: Dict Other initial_state Defines the initial application state. If set to stopped, then the bot has to be explicitly started via /start RPC command. Defaults to stopped. Datatype: Enum, either stopped or running force_entry_enable Enables the RPC Commands to force a Trade entry. More information below. Datatype: Boolean disable_dataframe_checks Disable checking the OHLCV dataframe returned from the strategy methods for correctness. Only use when intentionally changing the dataframe and understand what you are doing. Strategy Override. Defaults to False. Datatype: Boolean internals.process_throttle_secs Set the process throttle, or minimum loop duration for one bot iteration loop. Value in second. Defaults to 5 seconds. Datatype: Positive Integer internals.heartbeat_interval Print heartbeat message every N seconds. Set to 0 to disable heartbeat messages. Defaults to 60 seconds. Datatype: Positive Integer or 0 internals.sd_notify Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See here for more details. Datatype: Boolean strategy Required Defines Strategy class to use. Recommended to be set via --strategy NAME. Datatype: ClassName strategy_path Adds an additional strategy lookup path (must be a directory). Datatype: String recursive_strategy_search Set to true to recursively search sub-directories inside user_data/strategies for a strategy. Datatype: Boolean user_data_dir Directory containing user data. Defaults to ./user_data/. Datatype: String db_url Declares database URL to use. NOTE: This defaults to sqlite:///tradesv3.dryrun.sqlite if dry_run is true, and to sqlite:///tradesv3.sqlite for production instances. Datatype: String, SQLAlchemy connect string logfile Specifies logfile name. Uses a rolling strategy for log file rotation for 10 files with the 1MB limit per file. Datatype: String add_config_files Additional config files. These files will be loaded and merged with the current config file. The files are resolved relative to the initial file. Defaults to []. Datatype: List of strings dataformat_ohlcv Data format to use to store historical candle (OHLCV) data. Defaults to feather. Datatype: String dataformat_trades Data format to use to store historical trades data. Defaults to feather. Datatype: String reduce_df_footprint Recast all numeric columns to float32/int32, with the objective of reducing ram/disk usage (and decreasing train/inference timing in FreqAI). (Currently only affects FreqAI use-cases) Datatype: Boolean. Default: False."},{"location":"configuration/#parameters-in-the-strategy","title":"Parameters in the strategy","text":"

    The following parameters can be set in the configuration file or strategy. Values set in the configuration file always overwrite values set in the strategy.

    • minimal_roi
    • timeframe
    • stoploss
    • max_open_trades
    • trailing_stop
    • trailing_stop_positive
    • trailing_stop_positive_offset
    • trailing_only_offset_is_reached
    • use_custom_stoploss
    • process_only_new_candles
    • order_types
    • order_time_in_force
    • unfilledtimeout
    • disable_dataframe_checks
    • use_exit_signal
    • exit_profit_only
    • exit_profit_offset
    • ignore_roi_if_entry_signal
    • ignore_buying_expired_candle_after
    • position_adjustment_enable
    • max_entry_position_adjustment
    "},{"location":"configuration/#configuring-amount-per-trade","title":"Configuring amount per trade","text":"

    There are several methods to configure how much of the stake currency the bot will use to enter a trade. All methods respect the available balance configuration as explained below.

    "},{"location":"configuration/#minimum-trade-stake","title":"Minimum trade stake","text":"

    The minimum stake amount will depend on exchange and pair and is usually listed in the exchange support pages.

    Assuming the minimum tradable amount for XRP/USD is 20 XRP (given by the exchange), and the price is 0.6\\(, the minimum stake amount to buy this pair is 20 * 0.6 ~= 12. This exchange has also a limit on USD - where all orders must be > 10\\) - which however does not apply in this case.

    To guarantee safe execution, freqtrade will not allow buying with a stake-amount of 10.1$, instead, it'll make sure that there's enough space to place a stoploss below the pair (+ an offset, defined by amount_reserve_percent, which defaults to 5%).

    With a reserve of 5%, the minimum stake amount would be ~12.6$ (12 * (1 + 0.05)). If we take into account a stoploss of 10% on top of that - we'd end up with a value of ~14$ (12.6 / (1 - 0.1)).

    To limit this calculation in case of large stoploss values, the calculated minimum stake-limit will never be more than 50% above the real limit.

    Warning

    Since the limits on exchanges are usually stable and are not updated often, some pairs can show pretty high minimum limits, simply because the price increased a lot since the last limit adjustment by the exchange. Freqtrade adjusts the stake-amount to this value, unless it's > 30% more than the calculated/desired stake-amount - in which case the trade is rejected.

    "},{"location":"configuration/#tradable-balance","title":"Tradable balance","text":"

    By default, the bot assumes that the complete amount - 1% is at it's disposal, and when using dynamic stake amount, it will split the complete balance into max_open_trades buckets per trade. Freqtrade will reserve 1% for eventual fees when entering a trade and will therefore not touch that by default.

    You can configure the \"untouched\" amount by using the tradable_balance_ratio setting.

    For example, if you have 10 ETH available in your wallet on the exchange and tradable_balance_ratio=0.5 (which is 50%), then the bot will use a maximum amount of 5 ETH for trading and considers this as an available balance. The rest of the wallet is untouched by the trades.

    Danger

    This setting should not be used when running multiple bots on the same account. Please look at Available Capital to the bot instead.

    Warning

    The tradable_balance_ratio setting applies to the current balance (free balance + tied up in trades). Therefore, assuming the starting balance of 1000, a configuration with tradable_balance_ratio=0.99 will not guarantee that 10 currency units will always remain available on the exchange. For example, the free amount may reduce to 5 units if the total balance is reduced to 500 (either by a losing streak or by withdrawing balance).

    "},{"location":"configuration/#assign-available-capital","title":"Assign available Capital","text":"

    To fully utilize compounding profits when using multiple bots on the same exchange account, you'll want to limit each bot to a certain starting balance. This can be accomplished by setting available_capital to the desired starting balance.

    Assuming your account has 10000 USDT and you want to run 2 different strategies on this exchange. You'd set available_capital=5000 - granting each bot an initial capital of 5000 USDT. The bot will then split this starting balance equally into max_open_trades buckets. Profitable trades will result in increased stake-sizes for this bot - without affecting the stake-sizes of the other bot.

    Adjusting available_capital requires reloading the configuration to take effect. Adjusting the available_capital adds the difference between the previous available_capital and the new available_capital. Decreasing the available capital when trades are open doesn't exit the trades. The difference is returned to the wallet when the trades conclude. The outcome of this differs depending on the price movement between the adjustment and exiting the trades.

    Incompatible with tradable_balance_ratio

    Setting this option will replace any configuration of tradable_balance_ratio.

    "},{"location":"configuration/#amend-last-stake-amount","title":"Amend last stake amount","text":"

    Assuming we have the tradable balance of 1000 USDT, stake_amount=400, and max_open_trades=3. The bot would open 2 trades and will be unable to fill the last trading slot, since the requested 400 USDT are no longer available since 800 USDT are already tied in other trades.

    To overcome this, the option amend_last_stake_amount can be set to True, which will enable the bot to reduce stake_amount to the available balance to fill the last trade slot.

    In the example above this would mean:

    • Trade1: 400 USDT
    • Trade2: 400 USDT
    • Trade3: 200 USDT

    Note

    This option only applies with Static stake amount - since Dynamic stake amount divides the balances evenly.

    Note

    The minimum last stake amount can be configured using last_stake_amount_min_ratio - which defaults to 0.5 (50%). This means that the minimum stake amount that's ever used is stake_amount * 0.5. This avoids very low stake amounts, that are close to the minimum tradable amount for the pair and can be refused by the exchange.

    "},{"location":"configuration/#static-stake-amount","title":"Static stake amount","text":"

    The stake_amount configuration statically configures the amount of stake-currency your bot will use for each trade.

    The minimal configuration value is 0.0001, however, please check your exchange's trading minimums for the stake currency you're using to avoid problems.

    This setting works in combination with max_open_trades. The maximum capital engaged in trades is stake_amount * max_open_trades. For example, the bot will at most use (0.05 BTC x 3) = 0.15 BTC, assuming a configuration of max_open_trades=3 and stake_amount=0.05.

    Note

    This setting respects the available balance configuration.

    "},{"location":"configuration/#dynamic-stake-amount","title":"Dynamic stake amount","text":"

    Alternatively, you can use a dynamic stake amount, which will use the available balance on the exchange, and divide that equally by the number of allowed trades (max_open_trades).

    To configure this, set stake_amount=\"unlimited\". We also recommend to set tradable_balance_ratio=0.99 (99%) - to keep a minimum balance for eventual fees.

    In this case a trade amount is calculated as:

    currency_balance / (max_open_trades - current_open_trades)\n

    To allow the bot to trade all the available stake_currency in your account (minus tradable_balance_ratio) set

    \"stake_amount\" : \"unlimited\",\n\"tradable_balance_ratio\": 0.99,\n

    Compounding profits

    This configuration will allow increasing/decreasing stakes depending on the performance of the bot (lower stake if the bot is losing, higher stakes if the bot has a winning record since higher balances are available), and will result in profit compounding.

    When using Dry-Run Mode

    When using \"stake_amount\" : \"unlimited\", in combination with Dry-Run, Backtesting or Hyperopt, the balance will be simulated starting with a stake of dry_run_wallet which will evolve. It is therefore important to set dry_run_wallet to a sensible value (like 0.05 or 0.01 for BTC and 1000 or 100 for USDT, for example), otherwise, it may simulate trades with 100 BTC (or more) or 0.05 USDT (or less) at once - which may not correspond to your real available balance or is less than the exchange minimal limit for the order amount for the stake currency.

    "},{"location":"configuration/#dynamic-stake-amount-with-position-adjustment","title":"Dynamic stake amount with position adjustment","text":"

    When you want to use position adjustment with unlimited stakes, you must also implement custom_stake_amount to a return a value depending on your strategy. Typical value would be in the range of 25% - 50% of the proposed stakes, but depends highly on your strategy and how much you wish to leave into the wallet as position adjustment buffer.

    For example if your position adjustment assumes it can do 2 additional buys with the same stake amounts then your buffer should be 66.6667% of the initially proposed unlimited stake amount.

    Or another example if your position adjustment assumes it can do 1 additional buy with 3x the original stake amount then custom_stake_amount should return 25% of proposed stake amount and leave 75% for possible later position adjustments.

    "},{"location":"configuration/#prices-used-for-orders","title":"Prices used for orders","text":"

    Prices for regular orders can be controlled via the parameter structures entry_pricing for trade entries and exit_pricing for trade exits. Prices are always retrieved right before an order is placed, either by querying the exchange tickers or by using the orderbook data.

    Note

    Orderbook data used by Freqtrade are the data retrieved from exchange by the ccxt's function fetch_order_book(), i.e. are usually data from the L2-aggregated orderbook, while the ticker data are the structures returned by the ccxt's fetch_ticker()/fetch_tickers() functions. Refer to the ccxt library documentation for more details.

    Using market orders

    Please read the section Market order pricing section when using market orders.

    "},{"location":"configuration/#entry-price","title":"Entry price","text":""},{"location":"configuration/#enter-price-side","title":"Enter price side","text":"

    The configuration setting entry_pricing.price_side defines the side of the orderbook the bot looks for when buying.

    The following displays an orderbook.

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If entry_pricing.price_side is set to \"bid\", then the bot will use 99 as entry price. In line with that, if entry_pricing.price_side is set to \"ask\", then the bot will use 101 as entry price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    direction Order setting price crosses spread long buy ask 101 yes long buy bid 99 no long buy same 99 no long buy other 101 yes short sell ask 101 no short sell bid 99 yes short sell same 101 no short sell other 99 yes

    Using the other side of the orderbook often guarantees quicker filled orders, but the bot can also end up paying more than what would have been necessary. Taker fees instead of maker fees will most likely apply even when using limit buy orders. Also, prices at the \"other\" side of the spread are higher than prices at the \"bid\" side in the orderbook, so the order behaves similar to a market order (however with a maximum price).

    "},{"location":"configuration/#entry-price-with-orderbook-enabled","title":"Entry price with Orderbook enabled","text":"

    When entering a trade with the orderbook enabled (entry_pricing.use_order_book=True), Freqtrade fetches the entry_pricing.order_book_top entries from the orderbook and uses the entry specified as entry_pricing.order_book_top on the configured side (entry_pricing.price_side) of the orderbook. 1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"configuration/#entry-price-without-orderbook-enabled","title":"Entry price without Orderbook enabled","text":"

    The following section uses side as the configured entry_pricing.price_side (defaults to \"same\").

    When not using orderbook (entry_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's below the last traded price from the ticker. Otherwise (when the side price is above the last price), it calculates a rate between side and last price based on entry_pricing.price_last_balance.

    The entry_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between ask and last price.

    "},{"location":"configuration/#check-depth-of-market","title":"Check depth of market","text":"

    When check depth of market is enabled (entry_pricing.check_depth_of_market.enabled=True), the entry signals are filtered based on the orderbook depth (sum of all amounts) for each orderbook side.

    Orderbook bid (buy) side depth is then divided by the orderbook ask (sell) side depth and the resulting delta is compared to the value of the entry_pricing.check_depth_of_market.bids_to_ask_delta parameter. The entry order is only executed if the orderbook delta is greater than or equal to the configured delta value.

    Note

    A delta value below 1 means that ask (sell) orderbook side depth is greater than the depth of the bid (buy) orderbook side, while a value greater than 1 means opposite (depth of the buy side is higher than the depth of the sell side).

    "},{"location":"configuration/#exit-price","title":"Exit price","text":""},{"location":"configuration/#exit-price-side","title":"Exit price side","text":"

    The configuration setting exit_pricing.price_side defines the side of the spread the bot looks for when exiting a trade.

    The following displays an orderbook:

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If exit_pricing.price_side is set to \"ask\", then the bot will use 101 as exiting price. In line with that, if exit_pricing.price_side is set to \"bid\", then the bot will use 99 as exiting price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    Direction Order setting price crosses spread long sell ask 101 no long sell bid 99 yes long sell same 101 no long sell other 99 yes short buy ask 101 yes short buy bid 99 no short buy same 99 no short buy other 101 yes"},{"location":"configuration/#exit-price-with-orderbook-enabled","title":"Exit price with Orderbook enabled","text":"

    When exiting with the orderbook enabled (exit_pricing.use_order_book=True), Freqtrade fetches the exit_pricing.order_book_top entries in the orderbook and uses the entry specified as exit_pricing.order_book_top from the configured side (exit_pricing.price_side) as trade exit price.

    1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"configuration/#exit-price-without-orderbook-enabled","title":"Exit price without Orderbook enabled","text":"

    The following section uses side as the configured exit_pricing.price_side (defaults to \"ask\").

    When not using orderbook (exit_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's above the last traded price from the ticker. Otherwise (when the side price is below the last price), it calculates a rate between side and last price based on exit_pricing.price_last_balance.

    The exit_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between side and last price.

    "},{"location":"configuration/#market-order-pricing","title":"Market order pricing","text":"

    When using market orders, prices should be configured to use the \"correct\" side of the orderbook to allow realistic pricing detection. Assuming both entry and exits are using market orders, a configuration similar to the following must be used

      \"order_types\": {\n    \"entry\": \"market\",\n    \"exit\": \"market\"\n    // ...\n  },\n  \"entry_pricing\": {\n    \"price_side\": \"other\",\n    // ...\n  },\n  \"exit_pricing\":{\n    \"price_side\": \"other\",\n    // ...\n  },\n

    Obviously, if only one side is using limit orders, different pricing combinations can be used.

    "},{"location":"configuration/#further-configuration-details","title":"Further Configuration details","text":""},{"location":"configuration/#understand-minimal_roi","title":"Understand minimal_roi","text":"

    The minimal_roi configuration parameter is a JSON object where the key is a duration in minutes and the value is the minimum ROI as a ratio. See the example below:

    \"minimal_roi\": {\n    \"40\": 0.0,    # Exit after 40 minutes if the profit is not negative\n    \"30\": 0.01,   # Exit after 30 minutes if there is at least 1% profit\n    \"20\": 0.02,   # Exit after 20 minutes if there is at least 2% profit\n    \"0\":  0.04    # Exit immediately if there is at least 4% profit\n},\n

    Most of the strategy files already include the optimal minimal_roi value. This parameter can be set in either Strategy or Configuration file. If you use it in the configuration file, it will override the minimal_roi value from the strategy file. If it is not set in either Strategy or Configuration, a default of 1000% {\"0\": 10} is used, and minimal ROI is disabled unless your trade generates 1000% profit.

    Special case to forceexit after a specific time

    A special case presents using \"<N>\": -1 as ROI. This forces the bot to exit a trade after N Minutes, no matter if it's positive or negative, so represents a time-limited force-exit.

    "},{"location":"configuration/#understand-force_entry_enable","title":"Understand force_entry_enable","text":"

    The force_entry_enable configuration parameter enables the usage of force-enter (/forcelong, /forceshort) commands via Telegram and REST API. For security reasons, it's disabled by default, and freqtrade will show a warning message on startup if enabled. For example, you can send /forceenter ETH/BTC to the bot, which will result in freqtrade buying the pair and holds it until a regular exit-signal (ROI, stoploss, /forceexit) appears.

    This can be dangerous with some strategies, so use with care.

    See the telegram documentation for details on usage.

    "},{"location":"configuration/#ignoring-expired-candles","title":"Ignoring expired candles","text":"

    When working with larger timeframes (for example 1h or more) and using a low max_open_trades value, the last candle can be processed as soon as a trade slot becomes available. When processing the last candle, this can lead to a situation where it may not be desirable to use the buy signal on that candle. For example, when using a condition in your strategy where you use a cross-over, that point may have passed too long ago for you to start a trade on it.

    In these situations, you can enable the functionality to ignore candles that are beyond a specified period by setting ignore_buying_expired_candle_after to a positive number, indicating the number of seconds after which the buy signal becomes expired.

    For example, if your strategy is using a 1h timeframe, and you only want to buy within the first 5 minutes when a new candle comes in, you can add the following configuration to your strategy:

      {\n    //...\n    \"ignore_buying_expired_candle_after\": 300,\n    // ...\n  }\n

    Note

    This setting resets with each new candle, so it will not prevent sticking-signals from executing on the 2nd or 3rd candle they're active. Best use a \"trigger\" selector for buy signals, which are only active for one candle.

    "},{"location":"configuration/#understand-order_types","title":"Understand order_types","text":"

    The order_types configuration parameter maps actions (entry, exit, stoploss, emergency_exit, force_exit, force_entry) to order-types (market, limit, ...) as well as configures stoploss to be on the exchange and defines stoploss on exchange update interval in seconds.

    This allows to enter using limit orders, exit using limit-orders, and create stoplosses using market orders. It also allows to set the stoploss \"on exchange\" which means stoploss order would be placed immediately once the buy order is fulfilled.

    order_types set in the configuration file overwrites values set in the strategy as a whole, so you need to configure the whole order_types dictionary in one place.

    If this is configured, the following 4 values (entry, exit, stoploss and stoploss_on_exchange) need to be present, otherwise, the bot will fail to start.

    For information on (emergency_exit,force_exit, force_entry, stoploss_on_exchange,stoploss_on_exchange_interval,stoploss_on_exchange_limit_ratio) please see stop loss documentation stop loss on exchange

    Syntax for Strategy:

    order_types = {\n    \"entry\": \"limit\",\n    \"exit\": \"limit\",\n    \"emergency_exit\": \"market\",\n    \"force_entry\": \"market\",\n    \"force_exit\": \"market\",\n    \"stoploss\": \"market\",\n    \"stoploss_on_exchange\": False,\n    \"stoploss_on_exchange_interval\": 60,\n    \"stoploss_on_exchange_limit_ratio\": 0.99,\n}\n

    Configuration:

    \"order_types\": {\n    \"entry\": \"limit\",\n    \"exit\": \"limit\",\n    \"emergency_exit\": \"market\",\n    \"force_entry\": \"market\",\n    \"force_exit\": \"market\",\n    \"stoploss\": \"market\",\n    \"stoploss_on_exchange\": false,\n    \"stoploss_on_exchange_interval\": 60\n}\n

    Market order support

    Not all exchanges support \"market\" orders. The following message will be shown if your exchange does not support market orders: \"Exchange <yourexchange> does not support market orders.\" and the bot will refuse to start.

    Using market orders

    Please carefully read the section Market order pricing section when using market orders.

    Stoploss on exchange

    order_types.stoploss_on_exchange_interval is not mandatory. Do not change its value if you are unsure of what you are doing. For more information about how stoploss works please refer to the stoploss documentation.

    If order_types.stoploss_on_exchange is enabled and the stoploss is cancelled manually on the exchange, then the bot will create a new stoploss order.

    Warning: order_types.stoploss_on_exchange failures

    If stoploss on exchange creation fails for some reason, then an \"emergency exit\" is initiated. By default, this will exit the trade using a market order. The order-type for the emergency-exit can be changed by setting the emergency_exit value in the order_types dictionary - however, this is not advised.

    "},{"location":"configuration/#understand-order_time_in_force","title":"Understand order_time_in_force","text":"

    The order_time_in_force configuration parameter defines the policy by which the order is executed on the exchange. Three commonly used time in force are:

    GTC (Good Till Canceled):

    This is most of the time the default time in force. It means the order will remain on exchange till it is cancelled by the user. It can be fully or partially fulfilled. If partially fulfilled, the remaining will stay on the exchange till cancelled.

    FOK (Fill Or Kill):

    It means if the order is not executed immediately AND fully then it is cancelled by the exchange.

    IOC (Immediate Or Canceled):

    It is the same as FOK (above) except it can be partially fulfilled. The remaining part is automatically cancelled by the exchange.

    PO (Post only):

    Post only order. The order is either placed as a maker order, or it is canceled. This means the order must be placed on orderbook for at least time in an unfilled state.

    "},{"location":"configuration/#time_in_force-config","title":"time_in_force config","text":"

    The order_time_in_force parameter contains a dict with entry and exit time in force policy values. This can be set in the configuration file or in the strategy. Values set in the configuration file overwrites values set in the strategy.

    The possible values are: GTC (default), FOK or IOC.

    \"order_time_in_force\": {\n    \"entry\": \"GTC\",\n    \"exit\": \"GTC\"\n},\n

    Warning

    This is ongoing work. For now, it is supported only for binance, gate and kucoin. Please don't change the default value unless you know what you are doing and have researched the impact of using different values for your particular exchange.

    "},{"location":"configuration/#fiat-conversion","title":"Fiat conversion","text":"

    Freqtrade uses the Coingecko API to convert the coin value to it's corresponding fiat value for the Telegram reports. The FIAT currency can be set in the configuration file as fiat_display_currency.

    Removing fiat_display_currency completely from the configuration will skip initializing coingecko, and will not show any FIAT currency conversion. This has no importance for the correct functioning of the bot.

    "},{"location":"configuration/#what-values-can-be-used-for-fiat_display_currency","title":"What values can be used for fiat_display_currency?","text":"

    The fiat_display_currency configuration parameter sets the base currency to use for the conversion from coin to fiat in the bot Telegram reports.

    The valid values are:

    \"AUD\", \"BRL\", \"CAD\", \"CHF\", \"CLP\", \"CNY\", \"CZK\", \"DKK\", \"EUR\", \"GBP\", \"HKD\", \"HUF\", \"IDR\", \"ILS\", \"INR\", \"JPY\", \"KRW\", \"MXN\", \"MYR\", \"NOK\", \"NZD\", \"PHP\", \"PKR\", \"PLN\", \"RUB\", \"SEK\", \"SGD\", \"THB\", \"TRY\", \"TWD\", \"ZAR\", \"USD\"\n

    In addition to fiat currencies, a range of crypto currencies is supported.

    The valid values are:

    \"BTC\", \"ETH\", \"XRP\", \"LTC\", \"BCH\", \"BNB\"\n
    "},{"location":"configuration/#coingecko-rate-limit-problems","title":"Coingecko Rate limit problems","text":"

    On some IP ranges, coingecko is heavily rate-limiting. In such cases, you may want to add your coingecko API key to the configuration.

    {\n    \"fiat_display_currency\": \"USD\",\n    \"coingecko\": {\n        \"api_key\": \"your-api\",\n        \"is_demo\": true\n    }\n}\n

    Freqtrade supports both Demo and Pro coingecko API keys.

    The Coingecko API key is NOT required for the bot to function correctly. It is only used for the conversion of coin to fiat in the Telegram reports, which usually also work without API key.

    "},{"location":"configuration/#consuming-exchange-websockets","title":"Consuming exchange Websockets","text":"

    Freqtrade can consume websockets through ccxt.pro.

    Freqtrade aims ensure data is available at all times. Should the websocket connection fail (or be disabled), the bot will fall back to REST API calls.

    Should you experience problems you suspect are caused by websockets, you can disable these via the setting exchange.enable_ws, which defaults to true.

    \"exchange\": {\n    // ...\n    \"enable_ws\": false,\n    // ...\n}\n

    Should you be required to use a proxy, please refer to the proxy section for more information.

    Rollout

    We're implementing this out slowly, ensuring stability of your bots. Currently, usage is limited to ohlcv data streams. It's also limited to a few exchanges, with new exchanges being added on an ongoing basis.

    "},{"location":"configuration/#using-dry-run-mode","title":"Using Dry-run mode","text":"

    We recommend starting the bot in the Dry-run mode to see how your bot will behave and what is the performance of your strategy. In the Dry-run mode, the bot does not engage your money. It only runs a live simulation without creating trades on the exchange.

    1. Edit your config.json configuration file.
    2. Switch dry-run to true and specify db_url for a persistence database.
    \"dry_run\": true,\n\"db_url\": \"sqlite:///tradesv3.dryrun.sqlite\",\n
    1. Remove your Exchange API key and secret (change them by empty values or fake credentials):
    \"exchange\": {\n    \"name\": \"binance\",\n    \"key\": \"key\",\n    \"secret\": \"secret\",\n    ...\n}\n

    Once you will be happy with your bot performance running in the Dry-run mode, you can switch it to production mode.

    Note

    A simulated wallet is available during dry-run mode and will assume a starting capital of dry_run_wallet (defaults to 1000).

    "},{"location":"configuration/#considerations-for-dry-run","title":"Considerations for dry-run","text":"
    • API-keys may or may not be provided. Only Read-Only operations (i.e. operations that do not alter account state) on the exchange are performed in dry-run mode.
    • Wallets (/balance) are simulated based on dry_run_wallet.
    • Orders are simulated, and will not be posted to the exchange.
    • Market orders fill based on orderbook volume the moment the order is placed, with a maximum slippage of 5%.
    • Limit orders fill once the price reaches the defined level - or time out based on unfilledtimeout settings.
    • Limit orders will be converted to market orders if they cross the price by more than 1%, and will be filled immediately based regular market order rules (see point about Market orders above).
    • In combination with stoploss_on_exchange, the stop_loss price is assumed to be filled.
    • Open orders (not trades, which are stored in the database) are kept open after bot restarts, with the assumption that they were not filled while being offline.
    "},{"location":"configuration/#switch-to-production-mode","title":"Switch to production mode","text":"

    In production mode, the bot will engage your money. Be careful, since a wrong strategy can lose all your money. Be aware of what you are doing when you run it in production mode.

    When switching to Production mode, please make sure to use a different / fresh database to avoid dry-run trades messing with your exchange money and eventually tainting your statistics.

    "},{"location":"configuration/#setup-your-exchange-account","title":"Setup your exchange account","text":"

    You will need to create API Keys (usually you get key and secret, some exchanges require an additional password) from the Exchange website and you'll need to insert this into the appropriate fields in the configuration or when asked by the freqtrade new-config command. API Keys are usually only required for live trading (trading for real money, bot running in \"production mode\", executing real orders on the exchange) and are not required for the bot running in dry-run (trade simulation) mode. When you set up the bot in dry-run mode, you may fill these fields with empty values.

    "},{"location":"configuration/#to-switch-your-bot-in-production-mode","title":"To switch your bot in production mode","text":"

    Edit your config.json file.

    Switch dry-run to false and don't forget to adapt your database URL if set:

    \"dry_run\": false,\n

    Insert your Exchange API key (change them by fake API keys):

    {\n    \"exchange\": {\n        \"name\": \"binance\",\n        \"key\": \"af8ddd35195e9dc500b9a6f799f6f5c93d89193b\",\n        \"secret\": \"08a9dc6db3d7b53e1acebd9275677f4b0a04f1a5\",\n        //\"password\": \"\", // Optional, not needed by all exchanges)\n        // ...\n    }\n    //...\n}\n

    You should also make sure to read the Exchanges section of the documentation to be aware of potential configuration details specific to your exchange.

    Keep your secrets secret

    To keep your secrets secret, we recommend using a 2nd configuration for your API keys. Simply use the above snippet in a new configuration file (e.g. config-private.json) and keep your settings in this file. You can then start the bot with freqtrade trade --config user_data/config.json --config user_data/config-private.json <...> to have your keys loaded.

    NEVER share your private configuration file or your exchange keys with anyone!

    "},{"location":"configuration/#using-a-proxy-with-freqtrade","title":"Using a proxy with Freqtrade","text":"

    To use a proxy with freqtrade, export your proxy settings using the variables \"HTTP_PROXY\" and \"HTTPS_PROXY\" set to the appropriate values. This will have the proxy settings applied to everything (telegram, coingecko, ...) except for exchange requests.

    export HTTP_PROXY=\"http://addr:port\"\nexport HTTPS_PROXY=\"http://addr:port\"\nfreqtrade\n
    "},{"location":"configuration/#proxy-exchange-requests","title":"Proxy exchange requests","text":"

    To use a proxy for exchange connections - you will have to define the proxies as part of the ccxt configuration.

    { \n  \"exchange\": {\n    \"ccxt_config\": {\n      \"httpsProxy\": \"http://addr:port\",\n      \"wsProxy\": \"http://addr:port\",\n    }\n  }\n}\n

    For more information on available proxy types, please consult the ccxt proxy documentation.

    "},{"location":"configuration/#next-step","title":"Next step","text":"

    Now you have configured your config.json, the next step is to start your bot.

    "},{"location":"data-analysis/","title":"Analyzing bot data with Jupyter notebooks","text":"

    You can analyze the results of backtests and trading history easily using Jupyter notebooks. Sample notebooks are located at user_data/notebooks/ after initializing the user directory with freqtrade create-userdir --userdir user_data.

    "},{"location":"data-analysis/#quick-start-with-docker","title":"Quick start with docker","text":"

    Freqtrade provides a docker-compose file which starts up a jupyter lab server. You can run this server using the following command: docker compose -f docker/docker-compose-jupyter.yml up

    This will create a dockercontainer running jupyter lab, which will be accessible using https://127.0.0.1:8888/lab. Please use the link that's printed in the console after startup for simplified login.

    For more information, Please visit the Data analysis with Docker section.

    "},{"location":"data-analysis/#pro-tips","title":"Pro tips","text":"
    • See jupyter.org for usage instructions.
    • Don't forget to start a Jupyter notebook server from within your conda or venv environment or use nb_conda_kernels*
    • Copy the example notebook before use so your changes don't get overwritten with the next freqtrade update.
    "},{"location":"data-analysis/#using-virtual-environment-with-system-wide-jupyter-installation","title":"Using virtual environment with system-wide Jupyter installation","text":"

    Sometimes it can be desired to use a system-wide installation of Jupyter notebook, and use a jupyter kernel from the virtual environment. This prevents you from installing the full jupyter suite multiple times per system, and provides an easy way to switch between tasks (freqtrade / other analytics tasks).

    For this to work, first activate your virtual environment and run the following commands:

    # Activate virtual environment\nsource .venv/bin/activate\n\npip install ipykernel\nipython kernel install --user --name=freqtrade\n# Restart jupyter (lab / notebook)\n# select kernel \"freqtrade\" in the notebook\n

    Note

    This section is provided for completeness, the Freqtrade Team won't provide full support for problems with this setup and will recommend to install Jupyter in the virtual environment directly, as that is the easiest way to get jupyter notebooks up and running. For help with this setup please refer to the Project Jupyter documentation or help channels.

    Warning

    Some tasks don't work especially well in notebooks. For example, anything using asynchronous execution is a problem for Jupyter. Also, freqtrade's primary entry point is the shell cli, so using pure python in a notebook bypasses arguments that provide required objects and parameters to helper functions. You may need to set those values or create expected objects manually.

    "},{"location":"data-analysis/#recommended-workflow","title":"Recommended workflow","text":"Task Tool Bot operations CLI Repetitive tasks Shell scripts Data analysis & visualization Notebook
    1. Use the CLI to

      * download historical data * run a backtest * run with real-time data * export results

    2. Collect these actions in shell scripts

      * save complicated commands with arguments * execute multi-step operations * automate testing strategies and preparing data for analysis

    3. Use a notebook to

      * visualize data * mangle and plot to generate insights

    "},{"location":"data-analysis/#example-utility-snippets","title":"Example utility snippets","text":""},{"location":"data-analysis/#change-directory-to-root","title":"Change directory to root","text":"

    Jupyter notebooks execute from the notebook directory. The following snippet searches for the project root, so relative paths remain consistent.

    import os\nfrom pathlib import Path\n\n# Change directory\n# Modify this cell to insure that the output shows the correct path.\n# Define all paths relative to the project root shown in the cell output\nproject_root = \"somedir/freqtrade\"\ni=0\ntry:\n    os.chdir(project_root)\n    assert Path('LICENSE').is_file()\nexcept:\n    while i<4 and (not Path('LICENSE').is_file()):\n        os.chdir(Path(Path.cwd(), '../'))\n        i+=1\n    project_root = Path.cwd()\nprint(Path.cwd())\n
    "},{"location":"data-analysis/#load-multiple-configuration-files","title":"Load multiple configuration files","text":"

    This option can be useful to inspect the results of passing in multiple configs. This will also run through the whole Configuration initialization, so the configuration is completely initialized to be passed to other methods.

    import json\nfrom freqtrade.configuration import Configuration\n\n# Load config from multiple files\nconfig = Configuration.from_files([\"config1.json\", \"config2.json\"])\n\n# Show the config in memory\nprint(json.dumps(config['original_config'], indent=2))\n

    For Interactive environments, have an additional configuration specifying user_data_dir and pass this in last, so you don't have to change directories while running the bot. Best avoid relative paths, since this starts at the storage location of the jupyter notebook, unless the directory is changed.

    {\n    \"user_data_dir\": \"~/.freqtrade/\"\n}\n
    "},{"location":"data-analysis/#further-data-analysis-documentation","title":"Further Data analysis documentation","text":"
    • Strategy debugging - also available as Jupyter notebook (user_data/notebooks/strategy_analysis_example.ipynb)
    • Plotting
    • Tag Analysis

    Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.

    "},{"location":"data-download/","title":"Data Downloading","text":""},{"location":"data-download/#getting-data-for-backtesting-and-hyperopt","title":"Getting data for backtesting and hyperopt","text":"

    To download data (candles / OHLCV) needed for backtesting and hyperoptimization use the freqtrade download-data command.

    If no additional parameter is specified, freqtrade will download data for \"1m\" and \"5m\" timeframes for the last 30 days. Exchange and pairs will come from config.json (if specified using -c/--config). Without provided configuration, --exchange becomes mandatory.

    You can use a relative timerange (--days 20) or an absolute starting point (--timerange 20200101-). For incremental downloads, the relative approach should be used.

    Tip: Updating existing data

    If you already have backtesting data available in your data-directory and would like to refresh this data up to today, freqtrade will automatically calculate the data missing for the existing pairs and the download will occur from the latest available point until \"now\", neither --days or --timerange parameters are required. Freqtrade will keep the available data and only download the missing data. If you are updating existing data after inserting new pairs that you have no data for, use --new-pairs-days xx parameter. Specified number of days will be downloaded for new pairs while old pairs will be updated with missing data only. If you use --days xx parameter alone - data for specified number of days will be downloaded for all pairs. Be careful, if specified number of days is smaller than gap between now and last downloaded candle - freqtrade will delete all existing data to avoid gaps in candle data.

    "},{"location":"data-download/#usage","title":"Usage","text":"
    usage: freqtrade download-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                               [-d PATH] [--userdir PATH]\n                               [-p PAIRS [PAIRS ...]] [--pairs-file FILE]\n                               [--days INT] [--new-pairs-days INT]\n                               [--include-inactive-pairs]\n                               [--timerange TIMERANGE] [--dl-trades]\n                               [--convert] [--exchange EXCHANGE]\n                               [-t TIMEFRAMES [TIMEFRAMES ...]] [--erase]\n                               [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                               [--data-format-trades {json,jsongz,hdf5,feather,parquet}]\n                               [--trading-mode {spot,margin,futures}]\n                               [--prepend]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --pairs-file FILE     File containing a list of pairs. Takes precedence over\n                        --pairs or pairs configured in the configuration.\n  --days INT            Download data for given number of days.\n  --new-pairs-days INT  Download data of new pairs for given number of days.\n                        Default: `None`.\n  --include-inactive-pairs\n                        Also download data from inactive pairs.\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --dl-trades           Download trades instead of OHLCV data. The bot will\n                        resample trades to the desired timeframe as specified\n                        as --timeframes/-t.\n  --convert             Convert downloaded trades to OHLCV data. Only\n                        applicable in combination with `--dl-trades`. Will be\n                        automatic for exchanges which don't have historic\n                        OHLCV (e.g. Kraken). If not provided, use `trades-to-\n                        ohlcv` to convert trades data to OHLCV data.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  -t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]\n                        Specify which tickers to download. Space-separated\n                        list. Default: `1m 5m`.\n  --erase               Clean all existing data for the selected\n                        exchange/pairs/timeframes.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --data-format-trades {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded trades data. (default:\n                        `feather`).\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n  --prepend             Allow data prepending. (Data-appending is disabled)\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Downloading all data for one quote currency

    Often, you'll want to download data for all pairs of a specific quote-currency. In such cases, you can use the following shorthand: freqtrade download-data --exchange binance --pairs .*/USDT <...>. The provided \"pairs\" string will be expanded to contain all active pairs on the exchange. To also download data for inactive (delisted) pairs, add --include-inactive-pairs to the command.

    Startup period

    download-data is a strategy-independent command. The idea is to download a big chunk of data once, and then iteratively increase the amount of data stored.

    For that reason, download-data does not care about the \"startup-period\" defined in a strategy. It's up to the user to download additional days if the backtest should start at a specific point in time (while respecting startup period).

    "},{"location":"data-download/#start-download","title":"Start download","text":"

    A very simple command (assuming an available config.json file) can look as follows.

    freqtrade download-data --exchange binance\n

    This will download historical candle (OHLCV) data for all the currency pairs defined in the configuration.

    Alternatively, specify the pairs directly

    freqtrade download-data --exchange binance --pairs ETH/USDT XRP/USDT BTC/USDT\n

    or as regex (in this case, to download all active USDT pairs)

    freqtrade download-data --exchange binance --pairs .*/USDT\n
    "},{"location":"data-download/#other-notes","title":"Other Notes","text":"
    • To use a different directory than the exchange specific default, use --datadir user_data/data/some_directory.
    • To change the exchange used to download the historical data from, please use a different configuration file (you'll probably need to adjust rate limits etc.)
    • To use pairs.json from some other directory, use --pairs-file some_other_dir/pairs.json.
    • To download historical candle (OHLCV) data for only 10 days, use --days 10 (defaults to 30 days).
    • To download historical candle (OHLCV) data from a fixed starting point, use --timerange 20200101- - which will download all data from January 1st, 2020.
    • Use --timeframes to specify what timeframe download the historical candle (OHLCV) data for. Default is --timeframes 1m 5m which will download 1-minute and 5-minute data.
    • To use exchange, timeframe and list of pairs as defined in your configuration file, use the -c/--config option. With this, the script uses the whitelist defined in the config as the list of currency pairs to download data for and does not require the pairs.json file. You can combine -c/--config with most other options.
    Permission denied errors

    If your configuration directory user_data was made by docker, you may get the following error:

    cp: cannot create regular file 'user_data/data/binance/pairs.json': Permission denied\n

    You can fix the permissions of your user-data directory as follows:

    sudo chown -R $UID:$GID user_data\n
    "},{"location":"data-download/#download-additional-data-before-the-current-timerange","title":"Download additional data before the current timerange","text":"

    Assuming you downloaded all data from 2022 (--timerange 20220101-) - but you'd now like to also backtest with earlier data. You can do so by using the --prepend flag, combined with --timerange - specifying an end-date.

    freqtrade download-data --exchange binance --pairs ETH/USDT XRP/USDT BTC/USDT --prepend --timerange 20210101-20220101\n

    Note

    Freqtrade will ignore the end-date in this mode if data is available, updating the end-date to the existing data start point.

    "},{"location":"data-download/#data-format","title":"Data format","text":"

    Freqtrade currently supports the following data-formats:

    • feather - a dataformat based on Apache Arrow
    • json - plain \"text\" json files
    • jsongz - a gzip-zipped version of json files
    • hdf5 - a high performance datastore
    • parquet - columnar datastore (OHLCV only)

    By default, both OHLCV data and trades data are stored in the feather format.

    This can be changed via the --data-format-ohlcv and --data-format-trades command line arguments respectively. To persist this change, you should also add the following snippet to your configuration, so you don't have to insert the above arguments each time:

        // ...\n    \"dataformat_ohlcv\": \"hdf5\",\n    \"dataformat_trades\": \"hdf5\",\n    // ...\n

    If the default data-format has been changed during download, then the keys dataformat_ohlcv and dataformat_trades in the configuration file need to be adjusted to the selected dataformat as well.

    Note

    You can convert between data-formats using the convert-data and convert-trade-data methods.

    "},{"location":"data-download/#dataformat-comparison","title":"Dataformat comparison","text":"

    The following comparisons have been made with the following data, and by using the linux time command.

    Found 6 pair / timeframe combinations.\n+----------+-------------+--------+---------------------+---------------------+\n|     Pair |   Timeframe |   Type |                From |                  To |\n|----------+-------------+--------+---------------------+---------------------|\n| BTC/USDT |          5m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:25:00 |\n| ETH/USDT |          1m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:26:00 |\n| BTC/USDT |          1m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:30:00 |\n| XRP/USDT |          5m |   spot | 2018-05-04 08:10:00 | 2022-09-13 19:15:00 |\n| XRP/USDT |          1m |   spot | 2018-05-04 08:11:00 | 2022-09-13 19:22:00 |\n| ETH/USDT |          5m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:20:00 |\n+----------+-------------+--------+---------------------+---------------------+\n

    Timings have been taken in a not very scientific way with the following command, which forces reading the data into memory.

    time freqtrade list-data --show-timerange --data-format-ohlcv <dataformat>\n
    Format Size timing feather 72Mb 3.5s json 149Mb 25.6s jsongz 39Mb 27s hdf5 145Mb 3.9s parquet 83Mb 3.8s

    Size has been taken from the BTC/USDT 1m spot combination for the timerange specified above.

    To have a best performance/size mix, we recommend using the default feather format, or parquet.

    "},{"location":"data-download/#pairs-file","title":"Pairs file","text":"

    In alternative to the whitelist from config.json, a pairs.json file can be used. If you are using Binance for example:

    • create a directory user_data/data/binance and copy or create the pairs.json file in that directory.
    • update the pairs.json file to contain the currency pairs you are interested in.
    mkdir -p user_data/data/binance\ntouch user_data/data/binance/pairs.json\n

    The format of the pairs.json file is a simple json list. Mixing different stake-currencies is allowed for this file, since it's only used for downloading.

    [\n    \"ETH/BTC\",\n    \"ETH/USDT\",\n    \"BTC/USDT\",\n    \"XRP/ETH\"\n]\n

    Note

    The pairs.json file is only used when no configuration is loaded (implicitly by naming, or via --config flag). You can force the usage of this file via --pairs-file pairs.json - however we recommend to use the pairlist from within the configuration, either via exchange.pair_whitelist or pairs setting in the configuration.

    "},{"location":"data-download/#sub-command-convert-data","title":"Sub-command convert data","text":"
    usage: freqtrade convert-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                              [-d PATH] [--userdir PATH]\n                              [-p PAIRS [PAIRS ...]] --format-from\n                              {json,jsongz,hdf5,feather,parquet} --format-to\n                              {json,jsongz,hdf5,feather,parquet} [--erase]\n                              [--exchange EXCHANGE]\n                              [-t TIMEFRAMES [TIMEFRAMES ...]]\n                              [--trading-mode {spot,margin,futures}]\n                              [--candle-types {spot,futures,mark,index,premiumIndex,funding_rate} [{spot,futures,mark,index,premiumIndex,funding_rate} ...]]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --format-from {json,jsongz,hdf5,feather,parquet}\n                        Source format for data conversion.\n  --format-to {json,jsongz,hdf5,feather,parquet}\n                        Destination format for data conversion.\n  --erase               Clean all existing data for the selected\n                        exchange/pairs/timeframes.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  -t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]\n                        Specify which tickers to download. Space-separated\n                        list. Default: `1m 5m`.\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n  --candle-types {spot,futures,mark,index,premiumIndex,funding_rate} [{spot,futures,mark,index,premiumIndex,funding_rate} ...]\n                        Select candle type to convert. Defaults to all\n                        available types.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-converting-data","title":"Example converting data","text":"

    The following command will convert all candle (OHLCV) data available in ~/.freqtrade/data/binance from json to jsongz, saving diskspace in the process. It'll also remove original json data files (--erase parameter).

    freqtrade convert-data --format-from json --format-to jsongz --datadir ~/.freqtrade/data/binance -t 5m 15m --erase\n
    "},{"location":"data-download/#sub-command-convert-trade-data","title":"Sub-command convert trade data","text":"
    usage: freqtrade convert-trade-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                    [-d PATH] [--userdir PATH]\n                                    [-p PAIRS [PAIRS ...]] --format-from\n                                    {json,jsongz,hdf5,feather,parquet}\n                                    --format-to\n                                    {json,jsongz,hdf5,feather,parquet}\n                                    [--erase] [--exchange EXCHANGE]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --format-from {json,jsongz,hdf5,feather,parquet}\n                        Source format for data conversion.\n  --format-to {json,jsongz,hdf5,feather,parquet}\n                        Destination format for data conversion.\n  --erase               Clean all existing data for the selected\n                        exchange/pairs/timeframes.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-converting-trades","title":"Example converting trades","text":"

    The following command will convert all available trade-data in ~/.freqtrade/data/kraken from jsongz to json. It'll also remove original jsongz data files (--erase parameter).

    freqtrade convert-trade-data --format-from jsongz --format-to json --datadir ~/.freqtrade/data/kraken --erase\n
    "},{"location":"data-download/#sub-command-trades-to-ohlcv","title":"Sub-command trades to ohlcv","text":"

    When you need to use --dl-trades (kraken only) to download data, conversion of trades data to ohlcv data is the last step. This command will allow you to repeat this last step for additional timeframes without re-downloading the data.

    usage: freqtrade trades-to-ohlcv [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                 [-d PATH] [--userdir PATH]\n                                 [-p PAIRS [PAIRS ...]]\n                                 [-t TIMEFRAMES [TIMEFRAMES ...]]\n                                 [--exchange EXCHANGE]\n                                 [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                                 [--data-format-trades {json,jsongz,hdf5,feather}]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  -t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]\n                        Specify which tickers to download. Space-separated\n                        list. Default: `1m 5m`.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --data-format-trades {json,jsongz,hdf5,feather}\n                        Storage format for downloaded trades data. (default:\n                        `feather`).\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-trade-to-ohlcv-conversion","title":"Example trade-to-ohlcv conversion","text":"
    freqtrade trades-to-ohlcv --exchange kraken -t 5m 1h 1d --pairs BTC/EUR ETH/EUR\n
    "},{"location":"data-download/#sub-command-list-data","title":"Sub-command list-data","text":"

    You can get a list of downloaded data using the list-data sub-command.

    usage: freqtrade list-data [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                           [--userdir PATH] [--exchange EXCHANGE]\n                           [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                           [--data-format-trades {json,jsongz,hdf5,feather,parquet}]\n                           [--trades] [-p PAIRS [PAIRS ...]]\n                           [--trading-mode {spot,margin,futures}]\n                           [--show-timerange]\n\noptions:\n  -h, --help            show this help message and exit\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --data-format-trades {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded trades data. (default:\n                        `feather`).\n  --trades              Work on trades data instead of OHLCV data.\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n  --show-timerange      Show timerange available for available data. (May take\n                        a while to calculate).\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-list-data","title":"Example list-data","text":"
    > freqtrade list-data --userdir ~/.freqtrade/user_data/\n\n              Found 33 pair / timeframe combinations.\n\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503          Pair \u2503                                 Timeframe \u2503 Type \u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502       ADA/BTC \u2502     5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d \u2502 spot \u2502\n\u2502       ADA/ETH \u2502     5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d \u2502 spot \u2502\n\u2502       ETH/BTC \u2502     5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d \u2502 spot \u2502\n\u2502      ETH/USDT \u2502                  5m, 15m, 30m, 1h, 2h, 4h \u2502 spot \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n

    Show all trades data including from/to timerange

    > freqtrade list-data --show --trades\n                     Found trades data for 1 pair.                     \n\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503    Pair \u2503 Type \u2503                From \u2503                  To \u2503 Trades \u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502 XRP/ETH \u2502 spot \u2502 2019-10-11 00:00:11 \u2502 2019-10-13 11:19:28 \u2502  12477 \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n
    "},{"location":"data-download/#trades-tick-data","title":"Trades (tick) data","text":"

    By default, download-data sub-command downloads Candles (OHLCV) data. Most exchanges also provide historic trade-data via their API. This data can be useful if you need many different timeframes, since it is only downloaded once, and then resampled locally to the desired timeframes.

    Since this data is large by default, the files use the feather file format by default. They are stored in your data-directory with the naming convention of <pair>-trades.feather (ETH_BTC-trades.feather). Incremental mode is also supported, as for historic OHLCV data, so downloading the data once per week with --days 8 will create an incremental data-repository.

    To use this mode, simply add --dl-trades to your call. This will swap the download method to download trades. If --convert is also provided, the resample step will happen automatically and overwrite eventually existing OHLCV data for the given pair/timeframe combinations.

    Do not use

    You should not use this unless you're a kraken user (Kraken does not provide historic OHLCV data). Most other exchanges provide OHLCV data with sufficient history, so downloading multiple timeframes through that method will still proof to be a lot faster than downloading trades data.

    Kraken user

    Kraken users should read this before starting to download data.

    Example call:

    freqtrade download-data --exchange kraken --pairs XRP/EUR ETH/EUR --days 20 --dl-trades\n

    Note

    While this method uses async calls, it will be slow, since it requires the result of the previous call to generate the next request to the exchange.

    "},{"location":"data-download/#next-step","title":"Next step","text":"

    Great, you now have some data downloaded, so you can now start backtesting your strategy.

    "},{"location":"deprecated/","title":"Deprecated features","text":"

    This page contains description of the command line arguments, configuration parameters and the bot features that were declared as DEPRECATED by the bot development team and are no longer supported. Please avoid their usage in your configuration.

    "},{"location":"deprecated/#removed-features","title":"Removed features","text":""},{"location":"deprecated/#the-refresh-pairs-cached-command-line-option","title":"the --refresh-pairs-cached command line option","text":"

    --refresh-pairs-cached in the context of backtesting, hyperopt and edge allows to refresh candle data for backtesting. Since this leads to much confusion, and slows down backtesting (while not being part of backtesting) this has been singled out as a separate freqtrade sub-command freqtrade download-data.

    This command line option was deprecated in 2019.7-dev (develop branch) and removed in 2019.9.

    "},{"location":"deprecated/#the-dynamic-whitelist-command-line-option","title":"The --dynamic-whitelist command line option","text":"

    This command line option was deprecated in 2018 and removed freqtrade 2019.6-dev (develop branch) and in freqtrade 2019.7. Please refer to pairlists instead.

    "},{"location":"deprecated/#the-live-command-line-option","title":"the --live command line option","text":"

    --live in the context of backtesting allowed to download the latest tick data for backtesting. Did only download the latest 500 candles, so was ineffective in getting good backtest data. Removed in 2019-7-dev (develop branch) and in freqtrade 2019.8.

    "},{"location":"deprecated/#ticker_interval-now-timeframe","title":"ticker_interval (now timeframe)","text":"

    Support for ticker_interval terminology was deprecated in 2020.6 in favor of timeframe - and compatibility code was removed in 2022.3.

    "},{"location":"deprecated/#allow-running-multiple-pairlists-in-sequence","title":"Allow running multiple pairlists in sequence","text":"

    The former \"pairlist\" section in the configuration has been removed, and is replaced by \"pairlists\" - being a list to specify a sequence of pairlists.

    The old section of configuration parameters (\"pairlist\") has been deprecated in 2019.11 and has been removed in 2020.4.

    "},{"location":"deprecated/#deprecation-of-bidvolume-and-askvolume-from-volume-pairlist","title":"deprecation of bidVolume and askVolume from volume-pairlist","text":"

    Since only quoteVolume can be compared between assets, the other options (bidVolume, askVolume) have been deprecated in 2020.4, and have been removed in 2020.9.

    "},{"location":"deprecated/#using-order-book-steps-for-exit-price","title":"Using order book steps for exit price","text":"

    Using order_book_min and order_book_max used to allow stepping the orderbook and trying to find the next ROI slot - trying to place sell-orders early. As this does however increase risk and provides no benefit, it's been removed for maintainability purposes in 2021.7.

    "},{"location":"deprecated/#legacy-hyperopt-mode","title":"Legacy Hyperopt mode","text":"

    Using separate hyperopt files was deprecated in 2021.4 and was removed in 2021.9. Please switch to the new Parametrized Strategies to benefit from the new hyperopt interface.

    "},{"location":"deprecated/#strategy-changes-between-v2-and-v3","title":"Strategy changes between V2 and V3","text":"

    Isolated Futures / short trading was introduced in 2022.4. This required major changes to configuration settings, strategy interfaces, ...

    We have put a great effort into keeping compatibility with existing strategies, so if you just want to continue using freqtrade in spot markets, there are no changes necessary. While we may drop support for the current interface sometime in the future, we will announce this separately and have an appropriate transition period.

    Please follow the Strategy migration guide to migrate your strategy to the new format to start using the new functionalities.

    "},{"location":"deprecated/#webhooks-changes-with-20224","title":"webhooks - changes with 2022.4","text":""},{"location":"deprecated/#buy_tag-has-been-renamed-to-enter_tag","title":"buy_tag has been renamed to enter_tag","text":"

    This should apply only to your strategy and potentially to webhooks. We will keep a compatibility layer for 1-2 versions (so both buy_tag and enter_tag will still work), but support for this in webhooks will disappear after that.

    "},{"location":"deprecated/#naming-changes","title":"Naming changes","text":"

    Webhook terminology changed from \"sell\" to \"exit\", and from \"buy\" to \"entry\", removing \"webhook\" in the process.

    • webhookbuy, webhookentry -> entry
    • webhookbuyfill, webhookentryfill -> entry_fill
    • webhookbuycancel, webhookentrycancel -> entry_cancel
    • webhooksell, webhookexit -> exit
    • webhooksellfill, webhookexitfill -> exit_fill
    • webhooksellcancel, webhookexitcancel -> exit_cancel
    "},{"location":"deprecated/#removal-of-populate_any_indicators","title":"Removal of populate_any_indicators","text":"

    version 2023.3 saw the removal of populate_any_indicators in favor of split methods for feature engineering and targets. Please read the migration document for full details.

    "},{"location":"developer/","title":"Development Help","text":"

    This page is intended for developers of Freqtrade, people who want to contribute to the Freqtrade codebase or documentation, or people who want to understand the source code of the application they're running.

    All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome. We track issues on GitHub and also have a dev channel on discord where you can ask questions.

    "},{"location":"developer/#documentation","title":"Documentation","text":"

    Documentation is available at https://freqtrade.io and needs to be provided with every new feature PR.

    Special fields for the documentation (like Note boxes, ...) can be found here.

    To test the documentation locally use the following commands.

    pip install -r docs/requirements-docs.txt\nmkdocs serve\n

    This will spin up a local server (usually on port 8000) so you can see if everything looks as you'd like it to.

    "},{"location":"developer/#developer-setup","title":"Developer setup","text":"

    To configure a development environment, you can either use the provided DevContainer, or use the setup.sh script and answer \"y\" when asked \"Do you want to install dependencies for dev [y/N]? \". Alternatively (e.g. if your system is not supported by the setup.sh script), follow the manual installation process and run pip3 install -r requirements-dev.txt - followed by pip3 install -e .[all].

    This will install all required tools for development, including pytest, ruff, mypy, and coveralls.

    Then install the git hook scripts by running pre-commit install, so your changes will be verified locally before committing. This avoids a lot of waiting for CI already, as some basic formatting checks are done locally on your machine.

    Before opening a pull request, please familiarize yourself with our Contributing Guidelines.

    "},{"location":"developer/#devcontainer-setup","title":"Devcontainer setup","text":"

    The fastest and easiest way to get started is to use VSCode with the Remote container extension. This gives developers the ability to start the bot with all required dependencies without needing to install any freqtrade specific dependencies on your local machine.

    "},{"location":"developer/#devcontainer-dependencies","title":"Devcontainer dependencies","text":"
    • VSCode
    • docker
    • Remote container extension documentation

    For more information about the Remote container extension, best consult the documentation.

    "},{"location":"developer/#tests","title":"Tests","text":"

    New code should be covered by basic unittests. Depending on the complexity of the feature, Reviewers may request more in-depth unittests. If necessary, the Freqtrade team can assist and give guidance with writing good tests (however please don't expect anyone to write the tests for you).

    "},{"location":"developer/#how-to-run-tests","title":"How to run tests","text":"

    Use pytest in root folder to run all available testcases and confirm your local environment is setup correctly

    feature branches

    Tests are expected to pass on the develop and stable branches. Other branches may be work in progress with tests not working yet.

    "},{"location":"developer/#checking-log-content-in-tests","title":"Checking log content in tests","text":"

    Freqtrade uses 2 main methods to check log content in tests, log_has() and log_has_re() (to check using regex, in case of dynamic log-messages). These are available from conftest.py and can be imported in any test module.

    A sample check looks as follows:

    from tests.conftest import log_has, log_has_re\n\ndef test_method_to_test(caplog):\n    method_to_test()\n\n    assert log_has(\"This event happened\", caplog)\n    # Check regex with trailing number ...\n    assert log_has_re(r\"This dynamic event happened and produced \\d+\", caplog)\n
    "},{"location":"developer/#debug-configuration","title":"Debug configuration","text":"

    To debug freqtrade, we recommend VSCode (with the Python extension) with the following launch configuration (located in .vscode/launch.json). Details will obviously vary between setups - but this should work to get you started.

    {\n    \"name\": \"freqtrade trade\",\n    \"type\": \"debugpy\",\n    \"request\": \"launch\",\n    \"module\": \"freqtrade\",\n    \"console\": \"integratedTerminal\",\n    \"args\": [\n        \"trade\",\n        // Optional:\n        // \"--userdir\", \"user_data\",\n        \"--strategy\", \n        \"MyAwesomeStrategy\",\n    ]\n},\n

    Command line arguments can be added in the \"args\" array. This method can also be used to debug a strategy, by setting the breakpoints within the strategy.

    A similar setup can also be taken for Pycharm - using freqtrade as module name, and setting the command line arguments as \"parameters\".

    Correct venv usage

    When using a virtual environment (which you should), make sure that your Editor is using the correct virtual environment to avoid problems or \"unknown import\" errors.

    Startup directory

    This assumes that you have the repository checked out, and the editor is started at the repository root level (so setup.py is at the top level of your repository).

    "},{"location":"developer/#vscode","title":"Vscode","text":"

    You can select the correct environment in VSCode with the command \"Python: Select Interpreter\" - which will show you environments the extension detected. If your environment has not been detected, you can also pick a path manually.

    "},{"location":"developer/#pycharm","title":"Pycharm","text":"

    In pycharm, you can select the appropriate Environment in the \"Run/Debug Configurations\" window.

    "},{"location":"developer/#errorhandling","title":"ErrorHandling","text":"

    Freqtrade Exceptions all inherit from FreqtradeException. This general class of error should however not be used directly. Instead, multiple specialized sub-Exceptions exist.

    Below is an outline of exception inheritance hierarchy:

    + FreqtradeException\n|\n+---+ OperationalException\n|   |\n|   +---+ ConfigurationError\n|\n+---+ DependencyException\n|   |\n|   +---+ PricingError\n|   |\n|   +---+ ExchangeError\n|       |\n|       +---+ TemporaryError\n|       |\n|       +---+ DDosProtection\n|       |\n|       +---+ InvalidOrderException\n|           |\n|           +---+ RetryableOrderError\n|           |\n|           +---+ InsufficientFundsError\n|\n+---+ StrategyError\n
    "},{"location":"developer/#plugins","title":"Plugins","text":""},{"location":"developer/#pairlists","title":"Pairlists","text":"

    You have a great idea for a new pair selection algorithm you would like to try out? Great. Hopefully you also want to contribute this back upstream.

    Whatever your motivations are - This should get you off the ground in trying to develop a new Pairlist Handler.

    First of all, have a look at the VolumePairList Handler, and best copy this file with a name of your new Pairlist Handler.

    This is a simple Handler, which however serves as a good example on how to start developing.

    Next, modify the class-name of the Handler (ideally align this with the module filename).

    The base-class provides an instance of the exchange (self._exchange) the pairlist manager (self._pairlistmanager), as well as the main configuration (self._config), the pairlist dedicated configuration (self._pairlistconfig) and the absolute position within the list of pairlists.

            self._exchange = exchange\n        self._pairlistmanager = pairlistmanager\n        self._config = config\n        self._pairlistconfig = pairlistconfig\n        self._pairlist_pos = pairlist_pos\n

    Tip

    Don't forget to register your pairlist in constants.py under the variable AVAILABLE_PAIRLISTS - otherwise it will not be selectable.

    Now, let's step through the methods which require actions:

    "},{"location":"developer/#pairlist-configuration","title":"Pairlist configuration","text":"

    Configuration for the chain of Pairlist Handlers is done in the bot configuration file in the element \"pairlists\", an array of configuration parameters for each Pairlist Handlers in the chain.

    By convention, \"number_assets\" is used to specify the maximum number of pairs to keep in the pairlist. Please follow this to ensure a consistent user experience.

    Additional parameters can be configured as needed. For instance, VolumePairList uses \"sort_key\" to specify the sorting value - however feel free to specify whatever is necessary for your great algorithm to be successful and dynamic.

    "},{"location":"developer/#short_desc","title":"short_desc","text":"

    Returns a description used for Telegram messages.

    This should contain the name of the Pairlist Handler, as well as a short description containing the number of assets. Please follow the format \"PairlistName - top/bottom X pairs\".

    "},{"location":"developer/#gen_pairlist","title":"gen_pairlist","text":"

    Override this method if the Pairlist Handler can be used as the leading Pairlist Handler in the chain, defining the initial pairlist which is then handled by all Pairlist Handlers in the chain. Examples are StaticPairList and VolumePairList.

    This is called with each iteration of the bot (only if the Pairlist Handler is at the first location) - so consider implementing caching for compute/network heavy calculations.

    It must return the resulting pairlist (which may then be passed into the chain of Pairlist Handlers).

    Validations are optional, the parent class exposes a _verify_blacklist(pairlist) and _whitelist_for_active_markets(pairlist) to do default filtering. Use this if you limit your result to a certain number of pairs - so the end-result is not shorter than expected.

    "},{"location":"developer/#filter_pairlist","title":"filter_pairlist","text":"

    This method is called for each Pairlist Handler in the chain by the pairlist manager.

    This is called with each iteration of the bot - so consider implementing caching for compute/network heavy calculations.

    It gets passed a pairlist (which can be the result of previous pairlists) as well as tickers, a pre-fetched version of get_tickers().

    The default implementation in the base class simply calls the _validate_pair() method for each pair in the pairlist, but you may override it. So you should either implement the _validate_pair() in your Pairlist Handler or override filter_pairlist() to do something else.

    If overridden, it must return the resulting pairlist (which may then be passed into the next Pairlist Handler in the chain).

    Validations are optional, the parent class exposes a _verify_blacklist(pairlist) and _whitelist_for_active_markets(pairlist) to do default filters. Use this if you limit your result to a certain number of pairs - so the end result is not shorter than expected.

    In VolumePairList, this implements different methods of sorting, does early validation so only the expected number of pairs is returned.

    "},{"location":"developer/#sample","title":"sample","text":"
        def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:\n        # Generate dynamic whitelist\n        pairs = self._calculate_pairlist(pairlist, tickers)\n        return pairs\n
    "},{"location":"developer/#protections","title":"Protections","text":"

    Best read the Protection documentation to understand protections. This Guide is directed towards Developers who want to develop a new protection.

    No protection should use datetime directly, but use the provided date_now variable for date calculations. This preserves the ability to backtest protections.

    Writing a new Protection

    Best copy one of the existing Protections to have a good example. Don't forget to register your protection in constants.py under the variable AVAILABLE_PROTECTIONS - otherwise it will not be selectable.

    "},{"location":"developer/#implementation-of-a-new-protection","title":"Implementation of a new protection","text":"

    All Protection implementations must have IProtection as parent class. For that reason, they must implement the following methods:

    • short_desc()
    • global_stop()
    • stop_per_pair().

    global_stop() and stop_per_pair() must return a ProtectionReturn object, which consists of:

    • lock pair - boolean
    • lock until - datetime - until when should the pair be locked (will be rounded up to the next new candle)
    • reason - string, used for logging and storage in the database
    • lock_side - long, short or '*'.

    The until portion should be calculated using the provided calculate_lock_end() method.

    All Protections should use \"stop_duration\" / \"stop_duration_candles\" to define how long a pair (or all pairs) should be locked. The content of this is made available as self._stop_duration to the each Protection.

    If your protection requires a look-back period, please use \"lookback_period\" / \"lockback_period_candles\" to keep all protections aligned.

    "},{"location":"developer/#global-vs-local-stops","title":"Global vs. local stops","text":"

    Protections can have 2 different ways to stop trading for a limited :

    • Per pair (local)
    • For all Pairs (globally)
    "},{"location":"developer/#protections-per-pair","title":"Protections - per pair","text":"

    Protections that implement the per pair approach must set has_local_stop=True. The method stop_per_pair() will be called whenever a trade closed (exit order completed).

    "},{"location":"developer/#protections-global-protection","title":"Protections - global protection","text":"

    These Protections should do their evaluation across all pairs, and consequently will also lock all pairs from trading (called a global PairLock). Global protection must set has_global_stop=True to be evaluated for global stops. The method global_stop() will be called whenever a trade closed (exit order completed).

    "},{"location":"developer/#protections-calculating-lock-end-time","title":"Protections - calculating lock end time","text":"

    Protections should calculate the lock end time based on the last trade it considers. This avoids re-locking should the lookback-period be longer than the actual lock period.

    The IProtection parent class provides a helper method for this in calculate_lock_end().

    "},{"location":"developer/#implement-a-new-exchange-wip","title":"Implement a new Exchange (WIP)","text":"

    Note

    This section is a Work in Progress and is not a complete guide on how to test a new exchange with Freqtrade.

    Note

    Make sure to use an up-to-date version of CCXT before running any of the below tests. You can get the latest version of ccxt by running pip install -U ccxt with activated virtual environment. Native docker is not supported for these tests, however the available dev-container will support all required actions and eventually necessary changes.

    Most exchanges supported by CCXT should work out of the box.

    To quickly test the public endpoints of an exchange, add a configuration for your exchange to tests/exchange_online/conftest.py and run these tests with pytest --longrun tests/exchange_online/test_ccxt_compat.py. Completing these tests successfully a good basis point (it's a requirement, actually), however these won't guarantee correct exchange functioning, as this only tests public endpoints, but no private endpoint (like generate order or similar).

    Also try to use freqtrade download-data for an extended timerange (multiple months) and verify that the data downloaded correctly (no holes, the specified timerange was actually downloaded).

    These are prerequisites to have an exchange listed as either Supported or Community tested (listed on the homepage). The below are \"extras\", which will make an exchange better (feature-complete) - but are not absolutely necessary for either of the 2 categories.

    Additional tests / steps to complete:

    • Verify data provided by fetch_ohlcv() - and eventually adjust ohlcv_candle_limit for this exchange
    • Check L2 orderbook limit range (API documentation) - and eventually set as necessary
    • Check if balance shows correctly (*)
    • Create market order (*)
    • Create limit order (*)
    • Cancel order (*)
    • Complete trade (enter + exit) (*)
      • Compare result calculation between exchange and bot
      • Ensure fees are applied correctly (check the database against the exchange)

    (*) Requires API keys and Balance on the exchange.

    "},{"location":"developer/#stoploss-on-exchange","title":"Stoploss On Exchange","text":"

    Check if the new exchange supports Stoploss on Exchange orders through their API.

    Since CCXT does not provide unification for Stoploss On Exchange yet, we'll need to implement the exchange-specific parameters ourselves. Best look at binance.py for an example implementation of this. You'll need to dig through the documentation of the Exchange's API on how exactly this can be done. CCXT Issues may also provide great help, since others may have implemented something similar for their projects.

    "},{"location":"developer/#incomplete-candles","title":"Incomplete candles","text":"

    While fetching candle (OHLCV) data, we may end up getting incomplete candles (depending on the exchange). To demonstrate this, we'll use daily candles (\"1d\") to keep things simple. We query the api (ct.fetch_ohlcv()) for the timeframe and look at the date of the last entry. If this entry changes or shows the date of a \"incomplete\" candle, then we should drop this since having incomplete candles is problematic because indicators assume that only complete candles are passed to them, and will generate a lot of false buy signals. By default, we're therefore removing the last candle assuming it's incomplete.

    To check how the new exchange behaves, you can use the following snippet:

    import ccxt\nfrom datetime import datetime, timezone\nfrom freqtrade.data.converter import ohlcv_to_dataframe\nct = ccxt.binance()  # Use the exchange you're testing\ntimeframe = \"1d\"\npair = \"BTC/USDT\"  # Make sure to use a pair that exists on that exchange!\nraw = ct.fetch_ohlcv(pair, timeframe=timeframe)\n\n# convert to dataframe\ndf1 = ohlcv_to_dataframe(raw, timeframe, pair=pair, drop_incomplete=False)\n\nprint(df1.tail(1))\nprint(datetime.now(timezone.utc))\n
                             date      open      high       low     close  volume  \n499 2019-06-08 00:00:00+00:00  0.000007  0.000007  0.000007  0.000007   26264344.0  \n2019-06-09 12:30:27.873327\n

    The output will show the last entry from the Exchange as well as the current UTC date. If the day shows the same day, then the last candle can be assumed as incomplete and should be dropped (leave the setting \"ohlcv_partial_candle\" from the exchange-class untouched / True). Otherwise, set \"ohlcv_partial_candle\" to False to not drop Candles (shown in the example above). Another way is to run this command multiple times in a row and observe if the volume is changing (while the date remains the same).

    "},{"location":"developer/#update-binance-cached-leverage-tiers","title":"Update binance cached leverage tiers","text":"

    Updating leveraged tiers should be done regularly - and requires an authenticated account with futures enabled.

    import ccxt\nimport json\nfrom pathlib import Path\n\nexchange = ccxt.binance({\n    'apiKey': '<apikey>',\n    'secret': '<secret>',\n    'options': {'defaultType': 'swap'}\n    })\n_ = exchange.load_markets()\n\nlev_tiers = exchange.fetch_leverage_tiers()\n\n# Assumes this is running in the root of the repository.\nfile = Path('freqtrade/exchange/binance_leverage_tiers.json')\njson.dump(dict(sorted(lev_tiers.items())), file.open('w'), indent=2)\n

    This file should then be contributed upstream, so others can benefit from this, too.

    "},{"location":"developer/#updating-example-notebooks","title":"Updating example notebooks","text":"

    To keep the jupyter notebooks aligned with the documentation, the following should be ran after updating a example notebook.

    jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace freqtrade/templates/strategy_analysis_example.ipynb\njupyter nbconvert --ClearOutputPreprocessor.enabled=True --to markdown freqtrade/templates/strategy_analysis_example.ipynb --stdout > docs/strategy_analysis_example.md\n
    "},{"location":"developer/#continuous-integration","title":"Continuous integration","text":"

    This documents some decisions taken for the CI Pipeline.

    • CI runs on all OS variants, Linux (ubuntu), macOS and Windows.
    • Docker images are build for the branches stable and develop, and are built as multiarch builds, supporting multiple platforms via the same tag.
    • Docker images containing Plot dependencies are also available as stable_plot and develop_plot.
    • Docker images contain a file, /freqtrade/freqtrade_commit containing the commit this image is based of.
    • Full docker image rebuilds are run once a week via schedule.
    • Deployments run on ubuntu.
    • ta-lib binaries are contained in the build_helpers directory to avoid fails related to external unavailability.
    • All tests must pass for a PR to be merged to stable or develop.
    "},{"location":"developer/#creating-a-release","title":"Creating a release","text":"

    This part of the documentation is aimed at maintainers, and shows how to create a release.

    "},{"location":"developer/#create-release-branch","title":"Create release branch","text":"

    Note

    Make sure that the stable branch is up-to-date!

    First, pick a commit that's about one week old (to not include latest additions to releases).

    # create new branch\ngit checkout -b new_release <commitid>\n

    Determine if crucial bugfixes have been made between this commit and the current state, and eventually cherry-pick these.

    • Merge the release branch (stable) into this branch.
    • Edit freqtrade/__init__.py and add the version matching the current date (for example 2019.7 for July 2019). Minor versions can be 2019.7.1 should we need to do a second release that month. Version numbers must follow allowed versions from PEP0440 to avoid failures pushing to pypi.
    • Commit this part.
    • Push that branch to the remote and create a PR against the stable branch.
    • Update develop version to next version following the pattern 2019.8-dev.
    "},{"location":"developer/#create-changelog-from-git-commits","title":"Create changelog from git commits","text":"
    # Needs to be done before merging / pulling that branch.\ngit log --oneline --no-decorate --no-merges stable..new_release\n

    To keep the release-log short, best wrap the full git changelog into a collapsible details section.

    <details>\n<summary>Expand full changelog</summary>\n\n... Full git changelog\n\n</details>\n
    "},{"location":"developer/#frequi-release","title":"FreqUI release","text":"

    If FreqUI has been updated substantially, make sure to create a release before merging the release branch. Make sure that freqUI CI on the release is finished and passed before merging the release.

    "},{"location":"developer/#create-github-release-tag","title":"Create github release / tag","text":"

    Once the PR against stable is merged (best right after merging):

    • Use the button \"Draft a new release\" in the Github UI (subsection releases).
    • Use the version-number specified as tag.
    • Use \"stable\" as reference (this step comes after the above PR is merged).
    • Use the above changelog as release comment (as codeblock).
    • Use the below snippet for the new release
    Release template
    ## Highlighted changes\n\n- ...\n\n### How to update\n\nAs always, you can update your bot using one of the following commands:\n\n#### docker-compose\n\n```bash\ndocker-compose pull\ndocker-compose up -d\n```\n\n#### Installation via setup script\n\n```\n# Deactivate venv and run \n./setup.sh --update\n```\n\n#### Plain native installation\n\n```\ngit pull\npip install -U -r requirements.txt\n```\n\n<details>\n<summary>Expand full changelog</summary>\n\n```\n<Paste your changelog here>\n```\n\n</details>\n
    "},{"location":"developer/#releases","title":"Releases","text":""},{"location":"developer/#pypi","title":"pypi","text":"

    Manual Releases

    This process is automated as part of Github Actions. Manual pypi pushes should not be necessary.

    Manual release

    To manually create a pypi release, please run the following commands:

    Additional requirement: wheel, twine (for uploading), account on pypi with proper permissions.

    pip install -U build\npython -m build --sdist --wheel\n\n# For pypi test (to check if some change to the installation did work)\ntwine upload --repository-url https://test.pypi.org/legacy/ dist/*\n\n# For production:\ntwine upload dist/*\n

    Please don't push non-releases to the productive / real pypi instance.

    "},{"location":"docker_quickstart/","title":"Using Freqtrade with Docker","text":"

    This page explains how to run the bot with Docker. It is not meant to work out of the box. You'll still need to read through the documentation and understand how to properly configure it.

    "},{"location":"docker_quickstart/#install-docker","title":"Install Docker","text":"

    Start by downloading and installing Docker / Docker Desktop for your platform:

    • Mac
    • Windows
    • Linux

    Docker compose install

    Freqtrade documentation assumes the use of Docker desktop (or the docker compose plugin). While the docker-compose standalone installation still works, it will require changing all docker compose commands from docker compose to docker-compose to work (e.g. docker compose up -d will become docker-compose up -d).

    Docker on windows

    If you just installed docker on a windows system, make sure to reboot your system, otherwise you might encounter unexplainable Problems related to network connectivity to docker containers.

    "},{"location":"docker_quickstart/#freqtrade-with-docker","title":"Freqtrade with docker","text":"

    Freqtrade provides an official Docker image on Dockerhub, as well as a docker compose file ready for usage.

    Note

    • The following section assumes that docker is installed and available to the logged in user.
    • All below commands use relative directories and will have to be executed from the directory containing the docker-compose.yml file.
    "},{"location":"docker_quickstart/#docker-quick-start","title":"Docker quick start","text":"

    Create a new directory and place the docker-compose file in this directory.

    mkdir ft_userdata\ncd ft_userdata/\n# Download the docker-compose file from the repository\ncurl https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml\n\n# Pull the freqtrade image\ndocker compose pull\n\n# Create user directory structure\ndocker compose run --rm freqtrade create-userdir --userdir user_data\n\n# Create configuration - Requires answering interactive questions\ndocker compose run --rm freqtrade new-config --config user_data/config.json\n

    The above snippet creates a new directory called ft_userdata, downloads the latest compose file and pulls the freqtrade image. The last 2 steps in the snippet create the directory with user_data, as well as (interactively) the default configuration based on your selections.

    How to edit the bot configuration?

    You can edit the configuration at any time, which is available as user_data/config.json (within the directory ft_userdata) when using the above configuration.

    You can also change the both Strategy and commands by editing the command section of your docker-compose.yml file.

    "},{"location":"docker_quickstart/#adding-a-custom-strategy","title":"Adding a custom strategy","text":"
    1. The configuration is now available as user_data/config.json
    2. Copy a custom strategy to the directory user_data/strategies/
    3. Add the Strategy' class name to the docker-compose.yml file

    The SampleStrategy is run by default.

    SampleStrategy is just a demo!

    The SampleStrategy is there for your reference and give you ideas for your own strategy. Please always backtest your strategy and use dry-run for some time before risking real money! You will find more information about Strategy development in the Strategy documentation.

    Once this is done, you're ready to launch the bot in trading mode (Dry-run or Live-trading, depending on your answer to the corresponding question you made above).

    docker compose up -d\n

    Default configuration

    While the configuration generated will be mostly functional, you will still need to verify that all options correspond to what you want (like Pricing, pairlist, ...) before starting the bot.

    "},{"location":"docker_quickstart/#accessing-the-ui","title":"Accessing the UI","text":"

    If you've selected to enable FreqUI in the new-config step, you will have freqUI available at port localhost:8080.

    You can now access the UI by typing localhost:8080 in your browser.

    UI Access on a remote server

    If you're running on a VPS, you should consider using either a ssh tunnel, or setup a VPN (openVPN, wireguard) to connect to your bot. This will ensure that freqUI is not directly exposed to the internet, which is not recommended for security reasons (freqUI does not support https out of the box). Setup of these tools is not part of this tutorial, however many good tutorials can be found on the internet. Please also read the API configuration with docker section to learn more about this configuration.

    "},{"location":"docker_quickstart/#monitoring-the-bot","title":"Monitoring the bot","text":"

    You can check for running instances with docker compose ps. This should list the service freqtrade as running. If that's not the case, best check the logs (see next point).

    "},{"location":"docker_quickstart/#docker-compose-logs","title":"Docker compose logs","text":"

    Logs will be written to: user_data/logs/freqtrade.log. You can also check the latest log with the command docker compose logs -f.

    "},{"location":"docker_quickstart/#database","title":"Database","text":"

    The database will be located at: user_data/tradesv3.sqlite

    "},{"location":"docker_quickstart/#updating-freqtrade-with-docker","title":"Updating freqtrade with docker","text":"

    Updating freqtrade when using docker is as simple as running the following 2 commands:

    # Download the latest image\ndocker compose pull\n# Restart the image\ndocker compose up -d\n

    This will first pull the latest image, and will then restart the container with the just pulled version.

    Check the Changelog

    You should always check the changelog for breaking changes / manual interventions required and make sure the bot starts correctly after the update.

    "},{"location":"docker_quickstart/#editing-the-docker-compose-file","title":"Editing the docker-compose file","text":"

    Advanced users may edit the docker-compose file further to include all possible options or arguments.

    All freqtrade arguments will be available by running docker compose run --rm freqtrade <command> <optional arguments>.

    docker compose for trade commands

    Trade commands (freqtrade trade <...>) should not be ran via docker compose run - but should use docker compose up -d instead. This makes sure that the container is properly started (including port forwardings) and will make sure that the container will restart after a system reboot. If you intend to use freqUI, please also ensure to adjust the configuration accordingly, otherwise the UI will not be available.

    docker compose run --rm

    Including --rm will remove the container after completion, and is highly recommended for all modes except trading mode (running with freqtrade trade command).

    Using docker without docker compose

    \"docker compose run --rm\" will require a compose file to be provided. Some freqtrade commands that don't require authentication such as list-pairs can be run with \"docker run --rm\" instead. For example docker run --rm freqtradeorg/freqtrade:stable list-pairs --exchange binance --quote BTC --print-json. This can be useful for fetching exchange information to add to your config.json without affecting your running containers.

    "},{"location":"docker_quickstart/#example-download-data-with-docker","title":"Example: Download data with docker","text":"

    Download backtesting data for 5 days for the pair ETH/BTC and 1h timeframe from Binance. The data will be stored in the directory user_data/data/ on the host.

    docker compose run --rm freqtrade download-data --pairs ETH/BTC --exchange binance --days 5 -t 1h\n

    Head over to the Data Downloading Documentation for more details on downloading data.

    "},{"location":"docker_quickstart/#example-backtest-with-docker","title":"Example: Backtest with docker","text":"

    Run backtesting in docker-containers for SampleStrategy and specified timerange of historical data, on 5m timeframe:

    docker compose run --rm freqtrade backtesting --config user_data/config.json --strategy SampleStrategy --timerange 20190801-20191001 -i 5m\n

    Head over to the Backtesting Documentation to learn more.

    "},{"location":"docker_quickstart/#additional-dependencies-with-docker","title":"Additional dependencies with docker","text":"

    If your strategy requires dependencies not included in the default image - it will be necessary to build the image on your host. For this, please create a Dockerfile containing installation steps for the additional dependencies (have a look at docker/Dockerfile.custom for an example).

    You'll then also need to modify the docker-compose.yml file and uncomment the build step, as well as rename the image to avoid naming collisions.

        image: freqtrade_custom\n    build:\n      context: .\n      dockerfile: \"./Dockerfile.<yourextension>\"\n

    You can then run docker compose build --pull to build the docker image, and run it using the commands described above.

    "},{"location":"docker_quickstart/#plotting-with-docker","title":"Plotting with docker","text":"

    Commands freqtrade plot-profit and freqtrade plot-dataframe (Documentation) are available by changing the image to *_plot in your docker-compose.yml file. You can then use these commands as follows:

    docker compose run --rm freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805\n

    The output will be stored in the user_data/plot directory, and can be opened with any modern browser.

    "},{"location":"docker_quickstart/#data-analysis-using-docker-compose","title":"Data analysis using docker compose","text":"

    Freqtrade provides a docker-compose file which starts up a jupyter lab server. You can run this server using the following command:

    docker compose -f docker/docker-compose-jupyter.yml up\n

    This will create a docker-container running jupyter lab, which will be accessible using https://127.0.0.1:8888/lab. Please use the link that's printed in the console after startup for simplified login.

    Since part of this image is built on your machine, it is recommended to rebuild the image from time to time to keep freqtrade (and dependencies) up-to-date.

    docker compose -f docker/docker-compose-jupyter.yml build --no-cache\n
    "},{"location":"docker_quickstart/#troubleshooting","title":"Troubleshooting","text":""},{"location":"docker_quickstart/#docker-on-windows","title":"Docker on Windows","text":"
    • Error: \"Timestamp for this request is outside of the recvWindow.\" The market api requests require a synchronized clock but the time in the docker container shifts a bit over time into the past. To fix this issue temporarily you need to run wsl --shutdown and restart docker again (a popup on windows 10 will ask you to do so). A permanent solution is either to host the docker container on a linux host or restart the wsl from time to time with the scheduler.

      taskkill /IM \"Docker Desktop.exe\" /F\nwsl --shutdown\nstart \"\" \"C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe\"\n
    • Cannot connect to the API (Windows) If you're on windows and just installed Docker (desktop), make sure to reboot your System. Docker can have problems with network connectivity without a restart. You should obviously also make sure to have your settings accordingly.

    Warning

    Due to the above, we do not recommend the usage of docker on windows for production setups, but only for experimentation, datadownload and backtesting. Best use a linux-VPS for running freqtrade reliably.

    "},{"location":"edge/","title":"Edge positioning","text":"

    The Edge Positioning module uses probability to calculate your win rate and risk reward ratio. It will use these statistics to control your strategy trade entry points, position size and, stoploss.

    Deprecated functionality

    Edge positioning (or short Edge) is currently in maintenance mode only (we keep existing functionality alive) and should be considered as deprecated. It will currently not receive new features until either someone stepped forward to take up ownership of that module - or we'll decide to remove edge from freqtrade.

    Warning

    When using Edge positioning with a dynamic whitelist (VolumePairList), make sure to also use AgeFilter and set it to at least calculate_since_number_of_days to avoid problems with missing data.

    Note

    Edge Positioning only considers its own buy/sell/stoploss signals. It ignores the stoploss, trailing stoploss, and ROI settings in the strategy configuration file. Edge Positioning improves the performance of some trading strategies and decreases the performance of others.

    "},{"location":"edge/#introduction","title":"Introduction","text":"

    Trading strategies are not perfect. They are frameworks that are susceptible to the market and its indicators. Because the market is not at all predictable, sometimes a strategy will win and sometimes the same strategy will lose.

    To obtain an edge in the market, a strategy has to make more money than it loses. Making money in trading is not only about how often the strategy makes or loses money.

    It doesn't matter how often, but how much!

    A bad strategy might make 1 penny in ten transactions but lose 1 dollar in one transaction. If one only checks the number of winning trades, it would be misleading to think that the strategy is actually making a profit.

    The Edge Positioning module seeks to improve a strategy's winning probability and the money that the strategy will make on the long run.

    We raise the following question1:

    Which trade is a better option?

    a) A trade with 80% of chance of losing 100$ and 20% chance of winning 200$ b) A trade with 100% of chance of losing 30$

    Answer

    The expected value of a) is smaller than the expected value of b). Hence, b) represents a smaller loss in the long run. However, the answer is: it depends

    Another way to look at it is to ask a similar question:

    Which trade is a better option?

    a) A trade with 80% of chance of winning 100$ and 20% chance of losing 200$ b) A trade with 100% of chance of winning 30$

    Edge positioning tries to answer the hard questions about risk/reward and position size automatically, seeking to minimizes the chances of losing of a given strategy.

    "},{"location":"edge/#trading-winning-and-losing","title":"Trading, winning and losing","text":"

    Let's call \\(o\\) the return of a single transaction \\(o\\) where \\(o \\in \\mathbb{R}\\). The collection \\(O = \\{o_1, o_2, ..., o_N\\}\\) is the set of all returns of transactions made during a trading session. We say that \\(N\\) is the cardinality of \\(O\\), or, in lay terms, it is the number of transactions made in a trading session.

    Example

    In a session where a strategy made three transactions we can say that \\(O = \\{3.5, -1, 15\\}\\). That means that \\(N = 3\\) and \\(o_1 = 3.5\\), \\(o_2 = -1\\), \\(o_3 = 15\\).

    A winning trade is a trade where a strategy made money. Making money means that the strategy closed the position in a value that returned a profit, after all deducted fees. Formally, a winning trade will have a return \\(o_i > 0\\). Similarly, a losing trade will have a return \\(o_j \\leq 0\\). With that, we can discover the set of all winning trades, \\(T_{win}\\), as follows:

    \\[ T_{win} = \\{ o \\in O | o > 0 \\} \\]

    Similarly, we can discover the set of losing trades \\(T_{lose}\\) as follows:

    \\[ T_{lose} = \\{o \\in O | o \\leq 0\\} \\]

    Example

    In a section where a strategy made four transactions \\(O = \\{3.5, -1, 15, 0\\}\\): \\(T_{win} = \\{3.5, 15\\}\\) \\(T_{lose} = \\{-1, 0\\}\\)

    "},{"location":"edge/#win-rate-and-lose-rate","title":"Win Rate and Lose Rate","text":"

    The win rate \\(W\\) is the proportion of winning trades with respect to all the trades made by a strategy. We use the following function to compute the win rate:

    \\[W = \\frac{|T_{win}|}{N}\\]

    Where \\(W\\) is the win rate, \\(N\\) is the number of trades and, \\(T_{win}\\) is the set of all trades where the strategy made money.

    Similarly, we can compute the rate of losing trades:

    \\[ L = \\frac{|T_{lose}|}{N} \\]

    Where \\(L\\) is the lose rate, \\(N\\) is the amount of trades made and, \\(T_{lose}\\) is the set of all trades where the strategy lost money. Note that the above formula is the same as calculating \\(L = 1 \u2013 W\\) or \\(W = 1 \u2013 L\\)

    "},{"location":"edge/#risk-reward-ratio","title":"Risk Reward Ratio","text":"

    Risk Reward Ratio (\\(R\\)) is a formula used to measure the expected gains of a given investment against the risk of loss. It is basically what you potentially win divided by what you potentially lose. Formally:

    \\[ R = \\frac{\\text{potential_profit}}{\\text{potential_loss}} \\] Worked example of \\(R\\) calculation

    Let's say that you think that the price of stonecoin today is 10.0$. You believe that, because they will start mining stonecoin, it will go up to 15.0$ tomorrow. There is the risk that the stone is too hard, and the GPUs can't mine it, so the price might go to 0$ tomorrow. You are planning to invest 100$, which will give you 10 shares (100 / 10).

    Your potential profit is calculated as:

    \\(\\begin{aligned} \\text{potential_profit} &= (\\text{potential_price} - \\text{entry_price}) * \\frac{\\text{investment}}{\\text{entry_price}} \\\\ &= (15 - 10) * (100 / 10) \\\\ &= 50 \\end{aligned}\\)

    Since the price might go to 0$, the 100$ dollars invested could turn into 0.

    We do however use a stoploss of 15% - so in the worst case, we'll sell 15% below entry price (or at 8.5$).

    \\(\\begin{aligned} \\text{potential_loss} &= (\\text{entry_price} - \\text{stoploss}) * \\frac{\\text{investment}}{\\text{entry_price}} \\\\ &= (10 - 8.5) * (100 / 10)\\\\ &= 15 \\end{aligned}\\)

    We can compute the Risk Reward Ratio as follows:

    \\(\\begin{aligned} R &= \\frac{\\text{potential_profit}}{\\text{potential_loss}}\\\\ &= \\frac{50}{15}\\\\ &= 3.33 \\end{aligned}\\) What it effectively means is that the strategy have the potential to make 3.33$ for each 1$ invested.

    On a long horizon, that is, on many trades, we can calculate the risk reward by dividing the strategy' average profit on winning trades by the strategy' average loss on losing trades. We can calculate the average profit, \\(\\mu_{win}\\), as follows:

    \\[ \\text{average_profit} = \\mu_{win} = \\frac{\\text{sum_of_profits}}{\\text{count_winning_trades}} = \\frac{\\sum^{o \\in T_{win}} o}{|T_{win}|} \\]

    Similarly, we can calculate the average loss, \\(\\mu_{lose}\\), as follows:

    \\[ \\text{average_loss} = \\mu_{lose} = \\frac{\\text{sum_of_losses}}{\\text{count_losing_trades}} = \\frac{\\sum^{o \\in T_{lose}} o}{|T_{lose}|} \\]

    Finally, we can calculate the Risk Reward ratio, \\(R\\), as follows:

    \\[ R = \\frac{\\text{average_profit}}{\\text{average_loss}} = \\frac{\\mu_{win}}{\\mu_{lose}}\\\\ \\] Worked example of \\(R\\) calculation using mean profit/loss

    Let's say the strategy that we are using makes an average win \\(\\mu_{win} = 2.06\\) and an average loss \\(\\mu_{loss} = 4.11\\). We calculate the risk reward ratio as follows: \\(R = \\frac{\\mu_{win}}{\\mu_{loss}} = \\frac{2.06}{4.11} = 0.5012...\\)

    "},{"location":"edge/#expectancy","title":"Expectancy","text":"

    By combining the Win Rate \\(W\\) and the Risk Reward ratio \\(R\\) to create an expectancy ratio \\(E\\). A expectance ratio is the expected return of the investment made in a trade. We can compute the value of \\(E\\) as follows:

    \\[E = R * W - L\\]

    Calculating \\(E\\)

    Let's say that a strategy has a win rate \\(W = 0.28\\) and a risk reward ratio \\(R = 5\\). What this means is that the strategy is expected to make 5 times the investment around on 28% of the trades it makes. Working out the example: \\(E = R * W - L = 5 * 0.28 - 0.72 = 0.68\\)

    The expectancy worked out in the example above means that, on average, this strategy' trades will return 1.68 times the size of its losses. Said another way, the strategy makes 1.68$ for every 1$ it loses, on average.

    This is important for two reasons: First, it may seem obvious, but you know right away that you have a positive return. Second, you now have a number you can compare to other candidate systems to make decisions about which ones you employ.

    It is important to remember that any system with an expectancy greater than 0 is profitable using past data. The key is finding one that will be profitable in the future.

    You can also use this value to evaluate the effectiveness of modifications to this system.

    Note

    It's important to keep in mind that Edge is testing your expectancy using historical data, there's no guarantee that you will have a similar edge in the future. It's still vital to do this testing in order to build confidence in your methodology but be wary of \"curve-fitting\" your approach to the historical data as things are unlikely to play out the exact same way for future trades.

    "},{"location":"edge/#how-does-it-work","title":"How does it work?","text":"

    Edge combines dynamic stoploss, dynamic positions, and whitelist generation into one isolated module which is then applied to the trading strategy. If enabled in config, Edge will go through historical data with a range of stoplosses in order to find buy and sell/stoploss signals. It then calculates win rate and expectancy over N trades for each stoploss. Here is an example:

    Pair Stoploss Win Rate Risk Reward Ratio Expectancy XZC/ETH -0.01 0.50 1.176384 0.088 XZC/ETH -0.02 0.51 1.115941 0.079 XZC/ETH -0.03 0.52 1.359670 0.228 XZC/ETH -0.04 0.51 1.234539 0.117

    The goal here is to find the best stoploss for the strategy in order to have the maximum expectancy. In the above example stoploss at \\(3%\\) leads to the maximum expectancy according to historical data.

    Edge module then forces stoploss value it evaluated to your strategy dynamically.

    "},{"location":"edge/#position-size","title":"Position size","text":"

    Edge dictates the amount at stake for each trade to the bot according to the following factors:

    • Allowed capital at risk
    • Stoploss

    Allowed capital at risk is calculated as follows:

    Allowed capital at risk = (Capital available_percentage) X (Allowed risk per trade)\n

    Stoploss is calculated as described above with respect to historical data.

    The position size is calculated as follows:

    Position size = (Allowed capital at risk) / Stoploss\n

    Example:

    Let's say the stake currency is ETH and there is \\(10\\) ETH on the wallet. The capital available percentage is \\(50%\\) and the allowed risk per trade is \\(1\\%\\). Thus, the available capital for trading is \\(10 * 0.5 = 5\\) ETH and the allowed capital at risk would be \\(5 * 0.01 = 0.05\\) ETH.

    • Trade 1: The strategy detects a new buy signal in the XLM/ETH market. Edge Positioning calculates a stoploss of \\(2\\%\\) and a position of \\(0.05 / 0.02 = 2.5\\) ETH. The bot takes a position of \\(2.5\\) ETH in the XLM/ETH market.
    • Trade 2: The strategy detects a buy signal on the BTC/ETH market while Trade 1 is still open. Edge Positioning calculates the stoploss of \\(4\\%\\) on this market. Thus, Trade 2 position size is \\(0.05 / 0.04 = 1.25\\) ETH.

    Available Capital \\(\\neq\\) Available in wallet

    The available capital for trading didn't change in Trade 2 even with Trade 1 still open. The available capital is not the free amount in the wallet.

    • Trade 3: The strategy detects a buy signal in the ADA/ETH market. Edge Positioning calculates a stoploss of \\(1\\%\\) and a position of \\(0.05 / 0.01 = 5\\) ETH. Since Trade 1 has \\(2.5\\) ETH blocked and Trade 2 has \\(1.25\\) ETH blocked, there is only \\(5 - 1.25 - 2.5 = 1.25\\) ETH available. Hence, the position size of Trade 3 is \\(1.25\\) ETH.

    Available Capital Updates

    The available capital does not change before a position is sold. After a trade is closed the Available Capital goes up if the trade was profitable or goes down if the trade was a loss.

    • The strategy detects a sell signal in the XLM/ETH market. The bot exits Trade 1 for a profit of \\(1\\) ETH. The total capital in the wallet becomes \\(11\\) ETH and the available capital for trading becomes \\(5.5\\) ETH.
    • Trade 4 The strategy detects a new buy signal int the XLM/ETH market. Edge Positioning calculates the stoploss of \\(2\\%\\), and the position size of \\(0.055 / 0.02 = 2.75\\) ETH.
    "},{"location":"edge/#edge-command-reference","title":"Edge command reference","text":"
    usage: freqtrade edge [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                      [--userdir PATH] [-s NAME] [--strategy-path PATH]\n                      [-i TIMEFRAME] [--timerange TIMERANGE]\n                      [--data-format-ohlcv {json,jsongz,hdf5}]\n                      [--max-open-trades INT] [--stake-amount STAKE_AMOUNT]\n                      [--fee FLOAT] [-p PAIRS [PAIRS ...]]\n                      [--stoplosses STOPLOSS_RANGE]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --data-format-ohlcv {json,jsongz,hdf5}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `None`).\n  --max-open-trades INT\n                        Override the value of the `max_open_trades`\n                        configuration setting.\n  --stake-amount STAKE_AMOUNT\n                        Override the value of the `stake_amount` configuration\n                        setting.\n  --fee FLOAT           Specify fee ratio. Will be applied twice (on trade\n                        entry and exit).\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --stoplosses STOPLOSS_RANGE\n                        Defines a range of stoploss values against which edge\n                        will assess the strategy. The format is \"min,max,step\"\n                        (without any space). Example:\n                        `--stoplosses=-0.01,-0.1,-0.001`\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n
    "},{"location":"edge/#configurations","title":"Configurations","text":"

    Edge module has following configuration options:

    Parameter Description enabled If true, then Edge will run periodically. Defaults to false. Datatype: Boolean process_throttle_secs How often should Edge run in seconds. Defaults to 3600 (once per hour). Datatype: Integer calculate_since_number_of_days Number of days of data against which Edge calculates Win Rate, Risk Reward and Expectancy. Note that it downloads historical data so increasing this number would lead to slowing down the bot. Defaults to 7. Datatype: Integer allowed_risk Ratio of allowed risk per trade. Defaults to 0.01 (1%)). Datatype: Float stoploss_range_min Minimum stoploss. Defaults to -0.01. Datatype: Float stoploss_range_max Maximum stoploss. Defaults to -0.10. Datatype: Float stoploss_range_step As an example if this is set to -0.01 then Edge will test the strategy for [-0.01, -0,02, -0,03 ..., -0.09, -0.10] ranges. Note than having a smaller step means having a bigger range which could lead to slow calculation. If you set this parameter to -0.001, you then slow down the Edge calculation by a factor of 10. Defaults to -0.001. Datatype: Float minimum_winrate It filters out pairs which don't have at least minimum_winrate. This comes handy if you want to be conservative and don't comprise win rate in favour of risk reward ratio. Defaults to 0.60. Datatype: Float minimum_expectancy It filters out pairs which have the expectancy lower than this number. Having an expectancy of 0.20 means if you put 10$ on a trade you expect a 12$ return. Defaults to 0.20. Datatype: Float min_trade_number When calculating W, R and E (expectancy) against historical data, you always want to have a minimum number of trades. The more this number is the more Edge is reliable. Having a win rate of 100% on a single trade doesn't mean anything at all. But having a win rate of 70% over past 100 trades means clearly something. Defaults to 10 (it is highly recommended not to decrease this number). Datatype: Integer max_trade_duration_minute Edge will filter out trades with long duration. If a trade is profitable after 1 month, it is hard to evaluate the strategy based on it. But if most of trades are profitable and they have maximum duration of 30 minutes, then it is clearly a good sign.NOTICE: While configuring this value, you should take into consideration your timeframe. As an example filtering out trades having duration less than one day for a strategy which has 4h interval does not make sense. Default value is set assuming your strategy interval is relatively small (1m or 5m, etc.).Defaults to 1440 (one day). Datatype: Integer remove_pumps Edge will remove sudden pumps in a given market while going through historical data. However, given that pumps happen very often in crypto markets, we recommend you keep this off.Defaults to false. Datatype: Boolean"},{"location":"edge/#running-edge-independently","title":"Running Edge independently","text":"

    You can run Edge independently in order to see in details the result. Here is an example:

    freqtrade edge\n

    An example of its output:

    pair stoploss win rate risk reward ratio required risk reward expectancy total number of trades average duration (min) AGI/BTC -0.02 0.64 5.86 0.56 3.41 14 54 NXS/BTC -0.03 0.64 2.99 0.57 1.54 11 26 LEND/BTC -0.02 0.82 2.05 0.22 1.50 11 36 VIA/BTC -0.01 0.55 3.01 0.83 1.19 11 48 MTH/BTC -0.09 0.56 2.82 0.80 1.12 18 52 ARDR/BTC -0.04 0.42 3.14 1.40 0.73 12 42 BCPT/BTC -0.01 0.71 1.34 0.40 0.67 14 30 WINGS/BTC -0.02 0.56 1.97 0.80 0.65 27 42 VIBE/BTC -0.02 0.83 0.91 0.20 0.59 12 35 MCO/BTC -0.02 0.79 0.97 0.27 0.55 14 31 GNT/BTC -0.02 0.50 2.06 1.00 0.53 18 24 HOT/BTC -0.01 0.17 7.72 4.81 0.50 209 7 SNM/BTC -0.03 0.71 1.06 0.42 0.45 17 38 APPC/BTC -0.02 0.44 2.28 1.27 0.44 25 43 NEBL/BTC -0.03 0.63 1.29 0.58 0.44 19 59

    Edge produced the above table by comparing calculate_since_number_of_days to minimum_expectancy to find min_trade_number historical information based on the config file. The timerange Edge uses for its comparisons can be further limited by using the --timerange switch.

    In live and dry-run modes, after the process_throttle_secs has passed, Edge will again process calculate_since_number_of_days against minimum_expectancy to find min_trade_number. If no min_trade_number is found, the bot will return \"whitelist empty\". Depending on the trade strategy being deployed, \"whitelist empty\" may be return much of the time - or all of the time. The use of Edge may also cause trading to occur in bursts, though this is rare.

    If you encounter \"whitelist empty\" a lot, condsider tuning calculate_since_number_of_days, minimum_expectancy and min_trade_number to align to the trading frequency of your strategy.

    "},{"location":"edge/#update-cached-pairs-with-the-latest-data","title":"Update cached pairs with the latest data","text":"

    Edge requires historic data the same way as backtesting does. Please refer to the Data Downloading section of the documentation for details.

    "},{"location":"edge/#precising-stoploss-range","title":"Precising stoploss range","text":"
    freqtrade edge --stoplosses=-0.01,-0.1,-0.001 #min,max,step\n
    "},{"location":"edge/#advanced-use-of-timerange","title":"Advanced use of timerange","text":"
    freqtrade edge --timerange=20181110-20181113\n

    Doing --timerange=-20190901 will get all available data until September 1st (excluding September 1st 2019).

    The full timerange specification:

    • Use tickframes till 2018/01/31: --timerange=-20180131
    • Use tickframes since 2018/01/31: --timerange=20180131-
    • Use tickframes since 2018/01/31 till 2018/03/01 : --timerange=20180131-20180301
    • Use tickframes between POSIX timestamps 1527595200 1527618600: --timerange=1527595200-1527618600
    1. Question extracted from MIT Opencourseware S096 - Mathematics with applications in Finance: https://ocw.mit.edu/courses/mathematics/18-s096-topics-in-mathematics-with-applications-in-finance-fall-2013/ \u21a9

    "},{"location":"exchanges/","title":"Exchange-specific Notes","text":"

    This page combines common gotchas and Information which are exchange-specific and most likely don't apply to other exchanges.

    "},{"location":"exchanges/#exchange-configuration","title":"Exchange configuration","text":"

    Freqtrade is based on CCXT library that supports over 100 cryptocurrency exchange markets and trading APIs. The complete up-to-date list can be found in the CCXT repo homepage. However, the bot was tested by the development team with only a few exchanges. A current list of these can be found in the \"Home\" section of this documentation.

    Feel free to test other exchanges and submit your feedback or PR to improve the bot or confirm exchanges that work flawlessly..

    Some exchanges require special configuration, which can be found below.

    "},{"location":"exchanges/#sample-exchange-configuration","title":"Sample exchange configuration","text":"

    A exchange configuration for \"binance\" would look as follows:

    \"exchange\": {\n    \"name\": \"binance\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"ccxt_config\": {},\n    \"ccxt_async_config\": {},\n    // ... \n
    "},{"location":"exchanges/#setting-rate-limits","title":"Setting rate limits","text":"

    Usually, rate limits set by CCXT are reliable and work well. In case of problems related to rate-limits (usually DDOS Exceptions in your logs), it's easy to change rateLimit settings to other values.

    \"exchange\": {\n    \"name\": \"kraken\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"ccxt_config\": {\"enableRateLimit\": true},\n    \"ccxt_async_config\": {\n        \"enableRateLimit\": true,\n        \"rateLimit\": 3100\n    },\n

    This configuration enables kraken, as well as rate-limiting to avoid bans from the exchange. \"rateLimit\": 3100 defines a wait-event of 3.1s between each call. This can also be completely disabled by setting \"enableRateLimit\" to false.

    Note

    Optimal settings for rate-limiting depend on the exchange and the size of the whitelist, so an ideal parameter will vary on many other settings. We try to provide sensible defaults per exchange where possible, if you encounter bans please make sure that \"enableRateLimit\" is enabled and increase the \"rateLimit\" parameter step by step.

    "},{"location":"exchanges/#binance","title":"Binance","text":"

    Server location and geo-ip restrictions

    Please be aware that Binance restricts API access regarding the server country. The current and non-exhaustive countries blocked are Canada, Malaysia, Netherlands and United States. Please go to binance terms > b. Eligibility to find up to date list.

    Binance supports time_in_force.

    Stoploss on Exchange

    Binance supports stoploss_on_exchange and uses stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange. On futures, Binance supports both stop-limit as well as stop-market orders. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type to use.

    "},{"location":"exchanges/#binance-blacklist-recommendation","title":"Binance Blacklist recommendation","text":"

    For Binance, it is suggested to add \"BNB/<STAKE>\" to your blacklist to avoid issues, unless you are willing to maintain enough extra BNB on the account or unless you're willing to disable using BNB for fees. Binance accounts may use BNB for fees, and if a trade happens to be on BNB, further trades may consume this position and make the initial BNB trade unsellable as the expected amount is not there anymore.

    If not enough BNB is available to cover transaction fees, then fees will not be covered by BNB and no fee reduction will occur. Freqtrade will never buy BNB to cover for fees. BNB needs to be bought and monitored manually to this end.

    "},{"location":"exchanges/#binance-sites","title":"Binance sites","text":"

    Binance has been split into 2, and users must use the correct ccxt exchange ID for their exchange, otherwise API keys are not recognized.

    • binance.com - International users. Use exchange id: binance.
    • binance.us - US based users. Use exchange id: binanceus.
    "},{"location":"exchanges/#binance-rsa-keys","title":"Binance RSA keys","text":"

    Freqtrade supports binance RSA API keys.

    We recommend to use them as environment variable.

    export FREQTRADE__EXCHANGE__SECRET=\"$(cat ./rsa_binance.private)\"\n

    They can however also be configured via configuration file. Since json doesn't support multi-line strings, you'll have to replace all newlines with \\n to have a valid json file.

    // ...\n \"key\": \"<someapikey>\",\n \"secret\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvQIBABACAFQA<...>s8KX8=\\n-----END PRIVATE KEY-----\"\n// ...\n
    "},{"location":"exchanges/#binance-futures","title":"Binance Futures","text":"

    Binance has specific (unfortunately complex) Futures Trading Quantitative Rules which need to be followed, and which prohibit a too low stake-amount (among others) for too many orders. Violating these rules will result in a trading restriction.

    When trading on Binance Futures market, orderbook must be used because there is no price ticker data for futures.

      \"entry_pricing\": {\n      \"use_order_book\": true,\n      \"order_book_top\": 1,\n      \"check_depth_of_market\": {\n          \"enabled\": false,\n          \"bids_to_ask_delta\": 1\n      }\n  },\n  \"exit_pricing\": {\n      \"use_order_book\": true,\n      \"order_book_top\": 1\n  },\n
    "},{"location":"exchanges/#binance-futures-settings","title":"Binance futures settings","text":"

    Users will also have to have the futures-setting \"Position Mode\" set to \"One-way Mode\", and \"Asset Mode\" set to \"Single-Asset Mode\". These settings will be checked on startup, and freqtrade will show an error if this setting is wrong.

    Freqtrade will not attempt to change these settings.

    "},{"location":"exchanges/#bingx","title":"Bingx","text":"

    BingX supports time_in_force with settings \"GTC\" (good till cancelled), \"IOC\" (immediate-or-cancel) and \"PO\" (Post only) settings.

    Stoploss on Exchange

    Bingx supports stoploss_on_exchange and can use both stop-limit and stop-market orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange.

    "},{"location":"exchanges/#kraken","title":"Kraken","text":"

    Kraken supports time_in_force with settings \"GTC\" (good till cancelled), \"IOC\" (immediate-or-cancel) and \"PO\" (Post only) settings.

    Stoploss on Exchange

    Kraken supports stoploss_on_exchange and can use both stop-loss-market and stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type to use.

    "},{"location":"exchanges/#historic-kraken-data","title":"Historic Kraken data","text":"

    The Kraken API does only provide 720 historic candles, which is sufficient for Freqtrade dry-run and live trade modes, but is a problem for backtesting. To download data for the Kraken exchange, using --dl-trades is mandatory, otherwise the bot will download the same 720 candles over and over, and you'll not have enough backtest data.

    To speed up downloading, you can download the trades zip files kraken provides. These are usually updated once per quarter. Freqtrade expects these files to be placed in user_data/data/kraken/trades_csv.

    A structure as follows can make sense if using incremental files, with the \"full\" history in one directory, and incremental files in different directories. The assumption for this mode is that the data is downloaded and unzipped keeping filenames as they are. Duplicate content will be ignored (based on timestamp) - though the assumption is that there is no gap in the data.

    This means, if your \"full\" history ends in Q4 2022 - then both incremental updates Q1 2023 and Q2 2023 are available. Not having this will lead to incomplete data, and therefore invalid results while using the data.

    \u2514\u2500\u2500 trades_csv\n\u00a0 \u00a0 \u251c\u2500\u2500 Kraken_full_history\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 BCHEUR.csv\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 XBTEUR.csv\n \u00a0\u00a0 \u251c\u2500\u2500 Kraken_Trading_History_Q1_2023\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 BCHEUR.csv\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 XBTEUR.csv\n \u00a0\u00a0 \u2514\u2500\u2500 Kraken_Trading_History_Q2_2023\n \u00a0\u00a0  \u00a0\u00a0 \u251c\u2500\u2500 BCHEUR.csv\n \u00a0\u00a0  \u00a0\u00a0 \u2514\u2500\u2500 XBTEUR.csv\n

    You can convert these files into freqtrade files:

    freqtrade convert-trade-data --exchange kraken --format-from kraken_csv --format-to feather\n# Convert trade data to different ohlcv timeframes\nfreqtrade trades-to-ohlcv -p BTC/EUR BCH/EUR --exchange kraken -t 1m 5m 15m 1h\n

    The converted data also makes downloading data possible, and will start the download after the latest loaded trade.

    freqtrade download-data --exchange kraken --dl-trades -p BTC/EUR BCH/EUR \n

    Downloading data from kraken

    Downloading kraken data will require significantly more memory (RAM) than any other exchange, as the trades-data needs to be converted into candles on your machine. It will also take a long time, as freqtrade will need to download every single trade that happened on the exchange for the pair / timerange combination, therefore please be patient.

    rateLimit tuning

    Please pay attention that rateLimit configuration entry holds delay in milliseconds between requests, NOT requests\\sec rate. So, in order to mitigate Kraken API \"Rate limit exceeded\" exception, this configuration should be increased, NOT decreased.

    "},{"location":"exchanges/#kucoin","title":"Kucoin","text":"

    Kucoin requires a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows:

    \"exchange\": {\n    \"name\": \"kucoin\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"password\": \"your_exchange_api_key_password\",\n    // ...\n}\n

    Kucoin supports time_in_force.

    Stoploss on Exchange

    Kucoin supports stoploss_on_exchange and can use both stop-loss-market and stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type of stoploss shall be used.

    "},{"location":"exchanges/#kucoin-blacklists","title":"Kucoin Blacklists","text":"

    For Kucoin, it is suggested to add \"KCS/<STAKE>\" to your blacklist to avoid issues, unless you are willing to maintain enough extra KCS on the account or unless you're willing to disable using KCS for fees. Kucoin accounts may use KCS for fees, and if a trade happens to be on KCS, further trades may consume this position and make the initial KCS trade unsellable as the expected amount is not there anymore.

    "},{"location":"exchanges/#htx-formerly-huobi","title":"HTX (formerly Huobi)","text":"

    Stoploss on Exchange

    HTX supports stoploss_on_exchange and uses stop-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange.

    "},{"location":"exchanges/#okx-former-okex","title":"OKX (former OKEX)","text":"

    OKX requires a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows:

    \"exchange\": {\n    \"name\": \"okx\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"password\": \"your_exchange_api_key_password\",\n    // ...\n}\n

    Warning

    OKX only provides 100 candles per api call. Therefore, the strategy will only have a pretty low amount of data available in backtesting mode.

    Futures

    OKX Futures has the concept of \"position mode\" - which can be \"Buy/Sell\" or long/short (hedge mode). Freqtrade supports both modes (we recommend to use Buy/Sell mode) - but changing the mode mid-trading is not supported and will lead to exceptions and failures to place trades. OKX also only provides MARK candles for the past ~3 months. Backtesting futures prior to that date will therefore lead to slight deviations, as funding-fees cannot be calculated correctly without this data.

    "},{"location":"exchanges/#gateio","title":"Gate.io","text":"

    Stoploss on Exchange

    Gate.io supports stoploss_on_exchange and uses stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange..

    Gate.io allows the use of POINT to pay for fees. As this is not a tradable currency (no regular market available), automatic fee calculations will fail (and default to a fee of 0). The configuration parameter exchange.unknown_fee_rate can be used to specify the exchange rate between Point and the stake currency. Obviously, changing the stake-currency will also require changes to this value.

    "},{"location":"exchanges/#bybit","title":"Bybit","text":"

    Futures trading on bybit is currently supported for USDT markets, and will use isolated futures mode.

    On startup, freqtrade will set the position mode to \"One-way Mode\" for the whole (sub)account. This avoids making this call over and over again (slowing down bot operations), but means that changes to this setting may result in exceptions and errors.

    As bybit doesn't provide funding rate history, the dry-run calculation is used for live trades as well.

    API Keys for live futures trading must have the following permissions: * Read-write * Contract - Orders * Contract - Positions

    We do strongly recommend to limit all API keys to the IP you're going to use it from.

    Unified accounts

    Freqtrade assumes accounts to be dedicated to the bot. We therefore recommend the usage of one subaccount per bot. This is especially important when using unified accounts. Other configurations (multiple bots on one account, manual non-bot trades on the bot account) are not supported and may lead to unexpected behavior.

    Stoploss on Exchange

    Bybit (futures only) supports stoploss_on_exchange and uses stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange. On futures, Bybit supports both stop-limit as well as stop-market orders. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type to use.

    "},{"location":"exchanges/#bitmart","title":"Bitmart","text":"

    Bitmart requires the API key Memo (the name you give the API key) to go along with the exchange key and secret. It's therefore required to pass the UID as well.

    \"exchange\": {\n    \"name\": \"bitmart\",\n    \"uid\": \"your_bitmart_api_key_memo\",\n    \"secret\": \"your_exchange_secret\",\n    \"password\": \"your_exchange_api_key_password\",\n    // ...\n}\n

    Necessary Verification

    Bitmart requires Verification Lvl2 to successfully trade on the spot market through the API - even though trading via UI works just fine with just Lvl1 verification.

    "},{"location":"exchanges/#all-exchanges","title":"All exchanges","text":"

    Should you experience constant errors with Nonce (like InvalidNonce), it is best to regenerate the API keys. Resetting Nonce is difficult and it's usually easier to regenerate the API keys.

    "},{"location":"exchanges/#random-notes-for-other-exchanges","title":"Random notes for other exchanges","text":"
    • The Ocean (exchange id: theocean) exchange uses Web3 functionality and requires web3 python package to be installed:
    $ pip3 install web3\n
    "},{"location":"exchanges/#getting-latest-price-incomplete-candles","title":"Getting latest price / Incomplete candles","text":"

    Most exchanges return current incomplete candle via their OHLCV/klines API interface. By default, Freqtrade assumes that incomplete candle is fetched from the exchange and removes the last candle assuming it's the incomplete candle.

    Whether your exchange returns incomplete candles or not can be checked using the helper script from the Contributor documentation.

    Due to the danger of repainting, Freqtrade does not allow you to use this incomplete candle.

    However, if it is based on the need for the latest price for your strategy - then this requirement can be acquired using the data provider from within the strategy.

    "},{"location":"exchanges/#advanced-freqtrade-exchange-configuration","title":"Advanced Freqtrade Exchange configuration","text":"

    Advanced options can be configured using the _ft_has_params setting, which will override Defaults and exchange-specific behavior.

    Available options are listed in the exchange-class as _ft_has_default.

    For example, to test the order type FOK with Kraken, and modify candle limit to 200 (so you only get 200 candles per API call):

    \"exchange\": {\n    \"name\": \"kraken\",\n    \"_ft_has_params\": {\n        \"order_time_in_force\": [\"GTC\", \"FOK\"],\n        \"ohlcv_candle_limit\": 200\n        }\n    //...\n}\n

    Warning

    Please make sure to fully understand the impacts of these settings before modifying them.

    "},{"location":"faq/","title":"Freqtrade FAQ","text":""},{"location":"faq/#supported-markets","title":"Supported Markets","text":"

    Freqtrade supports spot trading, as well as (isolated) futures trading for some selected exchanges. Please refer to the documentation start page for an up-to-date list of supported exchanges.

    "},{"location":"faq/#can-my-bot-open-short-positions","title":"Can my bot open short positions?","text":"

    Freqtrade can open short positions in futures markets. This requires the strategy to be made for this - and \"trading_mode\": \"futures\" in the configuration. Please make sure to read the relevant documentation page first.

    In spot markets, you can in some cases use leveraged spot tokens, which reflect an inverted pair (eg. BTCUP/USD, BTCDOWN/USD, ETHBULL/USD, ETHBEAR/USD,...) which can be traded with Freqtrade.

    "},{"location":"faq/#can-my-bot-trade-options-or-futures","title":"Can my bot trade options or futures?","text":"

    Futures trading is supported for selected exchanges. Please refer to the documentation start page for an up-to-date list of supported exchanges.

    "},{"location":"faq/#beginner-tips-tricks","title":"Beginner Tips & Tricks","text":"
    • When you work with your strategy & hyperopt file you should use a proper code editor like VSCode or PyCharm. A good code editor will provide syntax highlighting as well as line numbers, making it easy to find syntax errors (most likely pointed out by Freqtrade during startup).
    "},{"location":"faq/#freqtrade-common-questions","title":"Freqtrade common questions","text":""},{"location":"faq/#can-freqtrade-open-multiple-positions-on-the-same-pair-in-parallel","title":"Can freqtrade open multiple positions on the same pair in parallel?","text":"

    No. Freqtrade will only open one position per pair at a time. You can however use the adjust_trade_position() callback to adjust an open position.

    Backtesting provides an option for this in --eps - however this is only there to highlight \"hidden\" signals, and will not work in live.

    "},{"location":"faq/#the-bot-does-not-start","title":"The bot does not start","text":"

    Running the bot with freqtrade trade --config config.json shows the output freqtrade: command not found.

    This could be caused by the following reasons:

    • The virtual environment is not active.
      • Run source .venv/bin/activate to activate the virtual environment.
    • The installation did not complete successfully.
      • Please check the Installation documentation.
    "},{"location":"faq/#i-have-waited-5-minutes-why-hasnt-the-bot-made-any-trades-yet","title":"I have waited 5 minutes, why hasn't the bot made any trades yet?","text":"
    • Depending on the buy strategy, the amount of whitelisted coins, the situation of the market etc, it can take up to hours to find a good entry position for a trade. Be patient!
    • It may be because of a configuration error. It's best to check the logs, they usually tell you if the bot is simply not getting buy signals (only heartbeat messages), or if there is something wrong (errors / exceptions in the log).
    "},{"location":"faq/#i-have-made-12-trades-already-why-is-my-total-profit-negative","title":"I have made 12 trades already, why is my total profit negative?","text":"

    I understand your disappointment but unfortunately 12 trades is just not enough to say anything. If you run backtesting, you can see that the current algorithm does leave you on the plus side, but that is after thousands of trades and even there, you will be left with losses on specific coins that you have traded tens if not hundreds of times. We of course constantly aim to improve the bot but it will always be a gamble, which should leave you with modest wins on monthly basis but you can't say much from few trades.

    "},{"location":"faq/#id-like-to-make-changes-to-the-config-can-i-do-that-without-having-to-kill-the-bot","title":"I\u2019d like to make changes to the config. Can I do that without having to kill the bot?","text":"

    Yes. You can edit your config and use the /reload_config command to reload the configuration. The bot will stop, reload the configuration and strategy and will restart with the new configuration and strategy.

    "},{"location":"faq/#why-does-my-bot-not-sell-everything-it-bought","title":"Why does my bot not sell everything it bought?","text":"

    This is called \"coin dust\" and can happen on all exchanges. It happens because many exchanges subtract fees from the \"receiving currency\" - so you buy 100 COIN - but you only get 99.9 COIN. As COIN is trading in full lot sizes (1COIN steps), you cannot sell 0.9 COIN (or 99.9 COIN) - but you need to round down to 99 COIN.

    This is not a bot-problem, but will also happen while manual trading.

    While freqtrade can handle this (it'll sell 99 COIN), fees are often below the minimum tradable lot-size (you can only trade full COIN, not 0.9 COIN). Leaving the dust (0.9 COIN) on the exchange makes usually sense, as the next time freqtrade buys COIN, it'll eat into the remaining small balance, this time selling everything it bought, and therefore slowly declining the dust balance (although it most likely will never reach exactly 0).

    Where possible (e.g. on binance), the use of the exchange's dedicated fee currency will fix this. On binance, it's sufficient to have BNB in your account, and have \"Pay fees in BNB\" enabled in your profile. Your BNB balance will slowly decline (as it's used to pay fees) - but you'll no longer encounter dust (Freqtrade will include the fees in the profit calculations). Other exchanges don't offer such possibilities, where it's simply something you'll have to accept or move to a different exchange.

    "},{"location":"faq/#i-deposited-more-funds-to-the-exchange-but-my-bot-doesnt-recognize-this","title":"I deposited more funds to the exchange, but my bot doesn't recognize this","text":"

    Freqtrade will update the exchange balance when necessary (Before placing an order). RPC calls (Telegram's /balance, API calls to /balance) can trigger an update at max. once per hour.

    If adjust_trade_position is enabled (and the bot has open trades eligible for position adjustments) - then the wallets will be refreshed once per hour. To force an immediate update, you can use /reload_config - which will restart the bot.

    "},{"location":"faq/#i-want-to-use-incomplete-candles","title":"I want to use incomplete candles","text":"

    Freqtrade will not provide incomplete candles to strategies. Using incomplete candles will lead to repainting and consequently to strategies with \"ghost\" buys, which are impossible to both backtest, and verify after they happened.

    You can use \"current\" market data by using the dataprovider's orderbook or ticker methods - which however cannot be used during backtesting.

    "},{"location":"faq/#is-there-a-setting-to-only-exit-the-trades-being-held-and-not-perform-any-new-entries","title":"Is there a setting to only Exit the trades being held and not perform any new Entries?","text":"

    You can use the /stopentry command in Telegram to prevent future trade entry, followed by /forceexit all (sell all open trades).

    "},{"location":"faq/#i-want-to-run-multiple-bots-on-the-same-machine","title":"I want to run multiple bots on the same machine","text":"

    Please look at the advanced setup documentation Page.

    "},{"location":"faq/#im-getting-missing-data-fillup-messages-in-the-log","title":"I'm getting \"Missing data fillup\" messages in the log","text":"

    This message is just a warning that the latest candles had missing candles in them. Depending on the exchange, this can indicate that the pair didn't have a trade for the timeframe you are using - and the exchange does only return candles with volume. On low volume pairs, this is a rather common occurrence.

    If this happens for all pairs in the pairlist, this might indicate a recent exchange downtime. Please check your exchange's public channels for details.

    Irrespectively of the reason, Freqtrade will fill up these candles with \"empty\" candles, where open, high, low and close are set to the previous candle close - and volume is empty. In a chart, this will look like a _ - and is aligned with how exchanges usually represent 0 volume candles.

    "},{"location":"faq/#im-getting-price-jump-between-2-candles-detected","title":"I'm getting \"Price jump between 2 candles detected\"","text":"

    This message is a warning that the candles had a price jump of > 30%. This might be a sign that the pair stopped trading, and some token exchange took place (e.g. COCOS in 2021 - where price jumped from 0.0000154 to 0.01621). This message is often accompanied by \"Missing data fillup\" - as trading on such pairs is often stopped for some time.

    "},{"location":"faq/#im-getting-outdated-history-for-pair-xxx-in-the-log","title":"I'm getting \"Outdated history for pair xxx\" in the log","text":"

    The bot is trying to tell you that it got an outdated last candle (not the last complete candle). As a consequence, Freqtrade will not enter a trade for this pair - as trading on old information is usually not what is desired.

    This warning can point to one of the below problems:

    • Exchange downtime -> Check your exchange status page / blog / twitter feed for details.
    • Wrong system time -> Ensure your system-time is correct.
    • Barely traded pair -> Check the pair on the exchange webpage, look at the timeframe your strategy uses. If the pair does not have any volume in some candles (usually visualized with a \"volume 0\" bar, and a \"_\" as candle), this pair did not have any trades in this timeframe. These pairs should ideally be avoided, as they can cause problems with order-filling.
    • API problem -> API returns wrong data (this only here for completeness, and should not happen with supported exchanges).
    "},{"location":"faq/#im-getting-the-exchange-xxx-does-not-support-market-orders-message-and-cannot-run-my-strategy","title":"I'm getting the \"Exchange XXX does not support market orders.\" message and cannot run my strategy","text":"

    As the message says, your exchange does not support market orders and you have one of the order types set to \"market\". Your strategy was probably written with other exchanges in mind and sets \"market\" orders for \"stoploss\" orders, which is correct and preferable for most of the exchanges supporting market orders (but not for Gate.io).

    To fix this, redefine order types in the strategy to use \"limit\" instead of \"market\":

        order_types = {\n        ...\n        \"stoploss\": \"limit\",\n        ...\n    }\n

    The same fix should be applied in the configuration file, if order types are defined in your custom config rather than in the strategy.

    "},{"location":"faq/#im-trying-to-start-the-bot-live-but-get-an-api-permission-error","title":"I'm trying to start the bot live, but get an API permission error","text":"

    Errors like Invalid API-key, IP, or permissions for action mean exactly what they actually say. Your API key is either invalid (copy/paste error? check for leading/trailing spaces in the config), expired, or the IP you're running the bot from is not enabled in the Exchange's API console. Usually, the permission \"Spot Trading\" (or the equivalent in the exchange you use) will be necessary. Futures will usually have to be enabled specifically.

    "},{"location":"faq/#how-do-i-search-the-bot-logs-for-something","title":"How do I search the bot logs for something?","text":"

    By default, the bot writes its log into stderr stream. This is implemented this way so that you can easily separate the bot's diagnostics messages from Backtesting, Edge and Hyperopt results, output from other various Freqtrade utility sub-commands, as well as from the output of your custom print()'s you may have inserted into your strategy. So if you need to search the log messages with the grep utility, you need to redirect stderr to stdout and disregard stdout.

    • In unix shells, this normally can be done as simple as:
      $ freqtrade --some-options 2>&1 >/dev/null | grep 'something'\n
      (note, 2>&1 and >/dev/null should be written in this order)
    • Bash interpreter also supports so called process substitution syntax, you can grep the log for a string with it as:
      $ freqtrade --some-options 2> >(grep 'something') >/dev/null\n
      or
      $ freqtrade --some-options 2> >(grep -v 'something' 1>&2)\n
    • You can also write the copy of Freqtrade log messages to a file with the --logfile option:
      $ freqtrade --logfile /path/to/mylogfile.log --some-options\n
      and then grep it as:
      $ cat /path/to/mylogfile.log | grep 'something'\n
      or even on the fly, as the bot works and the log file grows:
      $ tail -f /path/to/mylogfile.log | grep 'something'\n
      from a separate terminal window.

    On Windows, the --logfile option is also supported by Freqtrade and you can use the findstr command to search the log for the string of interest:

    > type \\path\\to\\mylogfile.log | findstr \"something\"\n

    "},{"location":"faq/#hyperopt-module","title":"Hyperopt module","text":""},{"location":"faq/#why-does-freqtrade-not-have-gpu-support","title":"Why does freqtrade not have GPU support?","text":"

    First of all, most indicator libraries don't have GPU support - as such, there would be little benefit for indicator calculations. The GPU improvements would only apply to pandas-native calculations - or ones written by yourself.

    For hyperopt, freqtrade is using scikit-optimize, which is built on top of scikit-learn. Their statement about GPU support is pretty clear.

    GPU's also are only good at crunching numbers (floating point operations). For hyperopt, we need both number-crunching (find next parameters) and running python code (running backtesting). As such, GPU's are not too well suited for most parts of hyperopt.

    The benefit of using GPU would therefore be pretty slim - and will not justify the complexity introduced by trying to add GPU support.

    There is however nothing preventing you from using GPU-enabled indicators within your strategy if you think you must have this - you will however probably be disappointed by the slim gain that will give you (compared to the complexity).

    "},{"location":"faq/#how-many-epochs-do-i-need-to-get-a-good-hyperopt-result","title":"How many epochs do I need to get a good Hyperopt result?","text":"

    Per default Hyperopt called without the -e/--epochs command line option will only run 100 epochs, means 100 evaluations of your triggers, guards, ... Too few to find a great result (unless if you are very lucky), so you probably have to run it for 10000 or more. But it will take an eternity to compute.

    Since hyperopt uses Bayesian search, running for too many epochs may not produce greater results.

    It's therefore recommended to run between 500-1000 epochs over and over until you hit at least 10000 epochs in total (or are satisfied with the result). You can best judge by looking at the results - if the bot keeps discovering better strategies, it's best to keep on going.

    freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy SampleStrategy -e 1000\n
    "},{"location":"faq/#why-does-it-take-a-long-time-to-run-hyperopt","title":"Why does it take a long time to run hyperopt?","text":"
    • Discovering a great strategy with Hyperopt takes time. Study www.freqtrade.io, the Freqtrade Documentation page, join the Freqtrade discord community. While you patiently wait for the most advanced, free crypto bot in the world, to hand you a possible golden strategy specially designed just for you.
    • If you wonder why it can take from 20 minutes to days to do 1000 epochs here are some answers:

    This answer was written during the release 0.15.1, when we had:

    • 8 triggers
    • 9 guards: let's say we evaluate even 10 values from each
    • 1 stoploss calculation: let's say we want 10 values from that too to be evaluated

    The following calculation is still very rough and not very precise but it will give the idea. With only these triggers and guards there is already 8*10^9*10 evaluations. A roughly total of 80 billion evaluations. Did you run 100 000 evaluations? Congrats, you've done roughly 1 / 100 000 th of the search space, assuming that the bot never tests the same parameters more than once.

    • The time it takes to run 1000 hyperopt epochs depends on things like: The available cpu, hard-disk, ram, timeframe, timerange, indicator settings, indicator count, amount of coins that hyperopt test strategies on and the resulting trade count - which can be 650 trades in a year or 100000 trades depending if the strategy aims for big profits by trading rarely or for many low profit trades.

    Example: 4% profit 650 times vs 0,3% profit a trade 10000 times in a year. If we assume you set the --timerange to 365 days.

    Example: freqtrade --config config.json --strategy SampleStrategy --hyperopt SampleHyperopt -e 1000 --timerange 20190601-20200601

    "},{"location":"faq/#edge-module","title":"Edge module","text":""},{"location":"faq/#edge-implements-interesting-approach-for-controlling-position-size-is-there-any-theory-behind-it","title":"Edge implements interesting approach for controlling position size, is there any theory behind it?","text":"

    The Edge module is mostly a result of brainstorming of @mishaker and @creslinux freqtrade team members.

    You can find further info on expectancy, win rate, risk management and position size in the following sources:

    • https://www.tradeciety.com/ultimate-math-guide-for-traders/
    • https://samuraitradingacademy.com/trading-expectancy/
    • https://www.learningmarkets.com/determining-expectancy-in-your-trading/
    • https://www.lonestocktrader.com/make-money-trading-positive-expectancy/
    • https://www.babypips.com/trading/trade-expectancy-matter
    "},{"location":"faq/#official-channels","title":"Official channels","text":"

    Freqtrade is using exclusively the following official channels:

    • Freqtrade discord server
    • Freqtrade documentation (https://freqtrade.io)
    • Freqtrade github organization

    Nobody affiliated with the freqtrade project will ask you about your exchange keys or anything else exposing your funds to exploitation. Should you be asked to expose your exchange keys or send funds to some random wallet, then please don't follow these instructions.

    Failing to follow these guidelines will not be responsibility of freqtrade.

    "},{"location":"faq/#freqtrade-token","title":"\"Freqtrade token\"","text":"

    Freqtrade does not have a Crypto token offering.

    Token offerings you find on the internet referring Freqtrade, FreqAI or freqUI must be considered to be a scam, trying to exploit freqtrade's popularity for their own, nefarious gains.

    "},{"location":"freq-ui/","title":"FreqUI","text":"

    Freqtrade provides a builtin webserver, which can serve FreqUI, the freqtrade frontend.

    By default, the UI is automatically installed as part of the installation (script, docker). freqUI can also be manually installed by using the freqtrade install-ui command. This same command can also be used to update freqUI to new new releases.

    Once the bot is started in trade / dry-run mode (with freqtrade trade) - the UI will be available under the configured API port (by default http://127.0.0.1:8080).

    Looking to contribute to freqUI?

    Developers should not use this method, but instead clone the corresponding use the method described in the freqUI repository to get the source-code of freqUI. A working installation of node will be required to build the frontend.

    freqUI is not required to run freqtrade

    freqUI is an optional component of freqtrade, and is not required to run the bot. It is a frontend that can be used to monitor the bot and to interact with it - but freqtrade itself will work perfectly fine without it.

    "},{"location":"freq-ui/#configuration","title":"Configuration","text":"

    FreqUI does not have it's own configuration file - but assumes a working setup for the rest-api is available. Please refer to the corresponding documentation page to get setup with freqUI

    "},{"location":"freq-ui/#ui","title":"UI","text":"

    FreqUI is a modern, responsive web application that can be used to monitor and interact with your bot.

    FreqUI provides a light, as well as a dark theme. Themes can be easily switched via a prominent button at the top of the page. The theme of the screenshots on this page will adapt to the selected documentation Theme, so to see the dark (or light) version, please switch the theme of the Documentation.

    "},{"location":"freq-ui/#login","title":"Login","text":"

    The below screenshot shows the login screen of freqUI.

    CORS

    The Cors error shown in this screenshot is due to the fact that the UI is running on a different port than the API, and CORS has not been setup correctly yet.

    "},{"location":"freq-ui/#trade-view","title":"Trade view","text":"

    The trade view allows you to visualize the trades that the bot is making and to interact with the bot. On this page, you can also interact with the bot by starting and stopping it and - if configured - force trade entries and exits.

    "},{"location":"freq-ui/#plot-configurator","title":"Plot Configurator","text":"

    FreqUI Plots can be configured either via a plot_config configuration object in the strategy (which can be loaded via \"from strategy\" button) or via the UI. Multiple plot configurations can be created and switched at will - allowing for flexible, different views into your charts.

    The plot configuration can be accessed via the \"Plot Configurator\" (Cog icon) button in the top right corner of the trade view.

    "},{"location":"freq-ui/#settings","title":"Settings","text":"

    Several UI related settings can be changed by accessing the settings page.

    Things you can change (among others):

    • Timezone of the UI
    • Visualization of open trades as part of the favicon (browser tab)
    • Candle colors (up/down -> red/green)
    • Enable / disable in-app notification types

    "},{"location":"freq-ui/#backtesting","title":"Backtesting","text":"

    When freqtrade is started in webserver mode (freqtrade started with freqtrade webserver), the backtesting view becomes available. This view allows you to backtest strategies and visualize the results.

    You can also load and visualize previous backtest results, as well as compare the results with each other.

    "},{"location":"freq-ui/#cors","title":"CORS","text":"

    This whole section is only necessary in cross-origin cases (where you multiple bot API's running on localhost:8081, localhost:8082, ...), and want to combine them into one FreqUI instance.

    Technical explanation

    All web-based front-ends are subject to CORS - Cross-Origin Resource Sharing. Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems. Also, the standard disallows * CORS policies for requests with credentials, so this setting must be set appropriately.

    Users can allow access from different origin URL's to the bot API via the CORS_origins configuration setting. It consists of a list of allowed URL's that are allowed to consume resources from the bot's API.

    Assuming your application is deployed as https://frequi.freqtrade.io/home/ - this would mean that the following configuration becomes necessary:

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"https://frequi.freqtrade.io\"],\n    //...\n}\n

    In the following (pretty common) case, FreqUI is accessible on http://localhost:8080/trade (this is what you see in your navbar when navigating to freqUI).

    The correct configuration for this case is http://localhost:8080 - the main part of the URL including the port.

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"http://localhost:8080\"],\n    //...\n}\n

    trailing Slash

    The trailing slash is not allowed in the CORS_origins configuration (e.g. \"http://localhots:8080/\"). Such a configuration will not take effect, and the cors errors will remain.

    Note

    We strongly recommend to also set jwt_secret_key to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"freqai-configuration/","title":"Configuration","text":"

    FreqAI is configured through the typical Freqtrade config file and the standard Freqtrade strategy. Examples of FreqAI config and strategy files can be found in config_examples/config_freqai.example.json and freqtrade/templates/FreqaiExampleStrategy.py, respectively.

    "},{"location":"freqai-configuration/#setting-up-the-configuration-file","title":"Setting up the configuration file","text":"

    Although there are plenty of additional parameters to choose from, as highlighted in the parameter table, a FreqAI config must at minimum include the following parameters (the parameter values are only examples):

        \"freqai\": {\n        \"enabled\": true,\n        \"purge_old_models\": 2,\n        \"train_period_days\": 30,\n        \"backtest_period_days\": 7,\n        \"identifier\" : \"unique-id\",\n        \"feature_parameters\" : {\n            \"include_timeframes\": [\"5m\",\"15m\",\"4h\"],\n            \"include_corr_pairlist\": [\n                \"ETH/USD\",\n                \"LINK/USD\",\n                \"BNB/USD\"\n            ],\n            \"label_period_candles\": 24,\n            \"include_shifted_candles\": 2,\n            \"indicator_periods_candles\": [10, 20]\n        },\n        \"data_split_parameters\" : {\n            \"test_size\": 0.25\n        }\n    }\n

    A full example config is available in config_examples/config_freqai.example.json.

    Note

    The identifier is commonly overlooked by newcomers, however, this value plays an important role in your configuration. This value is a unique ID that you choose to describe one of your runs. Keeping it the same allows you to maintain crash resilience as well as faster backtesting. As soon as you want to try a new run (new features, new model, etc.), you should change this value (or delete the user_data/models/unique-id folder. More details available in the parameter table.

    "},{"location":"freqai-configuration/#building-a-freqai-strategy","title":"Building a FreqAI strategy","text":"

    The FreqAI strategy requires including the following lines of code in the standard Freqtrade strategy:

        # user should define the maximum startup candle count (the largest number of candles\n    # passed to any single indicator)\n    startup_candle_count: int = 20\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n\n        # the model will return all labels created by user in `set_freqai_targets()`\n        # (& appended targets), an indication of whether or not the prediction should be accepted,\n        # the target mean/std values for each of the labels created by user in\n        # `set_freqai_targets()` for each training period.\n\n        dataframe = self.freqai.start(dataframe, metadata, self)\n\n        return dataframe\n\n    def feature_engineering_expand_all(self, dataframe: DataFrame, period, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and\n        `include_corr_pairs`. In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *\n        `include_corr_pairs` numbers of features added to the model.\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        :param period: period of the indicator - usage example:\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n        \"\"\"\n\n        dataframe[\"%-rsi-period\"] = ta.RSI(dataframe, timeperiod=period)\n        dataframe[\"%-mfi-period\"] = ta.MFI(dataframe, timeperiod=period)\n        dataframe[\"%-adx-period\"] = ta.ADX(dataframe, timeperiod=period)\n        dataframe[\"%-sma-period\"] = ta.SMA(dataframe, timeperiod=period)\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n\n        return dataframe\n\n    def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.\n        In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `include_timeframes` * `include_shifted_candles` * `include_corr_pairs`\n        numbers of features added to the model.\n\n        Features defined here will *not* be automatically duplicated on user defined\n        `indicator_periods_candles`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-ema-200\"] = ta.EMA(dataframe, timeperiod=200)\n        \"\"\"\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-raw_volume\"] = dataframe[\"volume\"]\n        dataframe[\"%-raw_price\"] = dataframe[\"close\"]\n        return dataframe\n\n    def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This optional function will be called once with the dataframe of the base timeframe.\n        This is the final function to be called, which means that the dataframe entering this\n        function will contain all the features and columns created by all other\n        freqai_feature_engineering_* functions.\n\n        This function is a good place to do custom exotic feature extractions (e.g. tsfresh).\n        This function is a good place for any feature that should not be auto-expanded upon\n        (e.g. day of the week).\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        usage example: dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        \"\"\"\n        dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        dataframe[\"%-hour_of_day\"] = (dataframe[\"date\"].dt.hour + 1) / 25\n        return dataframe\n\n    def set_freqai_targets(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        :param df: strategy dataframe which will receive the targets\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        dataframe[\"&-s_close\"] = (\n            dataframe[\"close\"]\n            .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .mean()\n            / dataframe[\"close\"]\n            - 1\n            )\n        return dataframe\n

    Notice how the feature_engineering_*() is where features are added. Meanwhile set_freqai_targets() adds the labels/targets. A full example strategy is available in templates/FreqaiExampleStrategy.py.

    Note

    The self.freqai.start() function cannot be called outside the populate_indicators().

    Note

    Features must be defined in feature_engineering_*(). Defining FreqAI features in populate_indicators() will cause the algorithm to fail in live/dry mode. In order to add generalized features that are not associated with a specific pair or timeframe, you should use feature_engineering_standard() (as exemplified in freqtrade/templates/FreqaiExampleStrategy.py).

    "},{"location":"freqai-configuration/#important-dataframe-key-patterns","title":"Important dataframe key patterns","text":"

    Below are the values you can expect to include/use inside a typical strategy dataframe (df[]):

    DataFrame Key Description df['&*'] Any dataframe column prepended with & in set_freqai_targets() is treated as a training target (label) inside FreqAI (typically following the naming convention &-s*). For example, to predict the close price 40 candles into the future, you would set df['&-s_close'] = df['close'].shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"]) with \"label_period_candles\": 40 in the config. FreqAI makes the predictions and gives them back under the same key (df['&-s_close']) to be used in populate_entry/exit_trend(). Datatype: Depends on the output of the model. df['&*_std/mean'] Standard deviation and mean values of the defined labels during training (or live tracking with fit_live_predictions_candles). Commonly used to understand the rarity of a prediction (use the z-score as shown in templates/FreqaiExampleStrategy.py and explained here to evaluate how often a particular prediction was observed during training or historically with fit_live_predictions_candles). Datatype: Float. df['do_predict'] Indication of an outlier data point. The return value is integer between -2 and 2, which lets you know if the prediction is trustworthy or not. do_predict==1 means that the prediction is trustworthy. If the Dissimilarity Index (DI, see details here) of the input data point is above the threshold defined in the config, FreqAI will subtract 1 from do_predict, resulting in do_predict==0. If use_SVM_to_remove_outliers is active, the Support Vector Machine (SVM, see details here) may also detect outliers in training and prediction data. In this case, the SVM will also subtract 1 from do_predict. If the input data point was considered an outlier by the SVM but not by the DI, or vice versa, the result will be do_predict==0. If both the DI and the SVM considers the input data point to be an outlier, the result will be do_predict==-1. As with the SVM, if use_DBSCAN_to_remove_outliers is active, DBSCAN (see details here) may also detect outliers and subtract 1 from do_predict. Hence, if both the SVM and DBSCAN are active and identify a datapoint that was above the DI threshold as an outlier, the result will be do_predict==-2. A particular case is when do_predict == 2, which means that the model has expired due to exceeding expired_hours. Datatype: Integer between -2 and 2. df['DI_values'] Dissimilarity Index (DI) values are proxies for the level of confidence FreqAI has in the prediction. A lower DI means the prediction is close to the training data, i.e., higher prediction confidence. See details about the DI here. Datatype: Float. df['%*'] Any dataframe column prepended with % in feature_engineering_*() is treated as a training feature. For example, you can include the RSI in the training feature set (similar to in templates/FreqaiExampleStrategy.py) by setting df['%-rsi']. See more details on how this is done here. Note: Since the number of features prepended with % can multiply very quickly (10s of thousands of features are easily engineered using the multiplictative functionality of, e.g., include_shifted_candles and include_timeframes as described in the parameter table), these features are removed from the dataframe that is returned from FreqAI to the strategy. To keep a particular type of feature for plotting purposes, you would prepend it with %% (see details below). Datatype: Depends on the feature created by the user. df['%%*'] Any dataframe column prepended with %% in feature_engineering_*() is treated as a training feature, just the same as the above % prepend. However, in this case, the features are returned back to the strategy for FreqUI/plot-dataframe plotting and monitoring in Dry/Live/Backtesting Datatype: Depends on the feature created by the user. Please note that features created in feature_engineering_expand() will have automatic FreqAI naming schemas depending on the expansions that you configured (i.e. include_timeframes, include_corr_pairlist, indicators_periods_candles, include_shifted_candles). So if you want to plot %%-rsi from feature_engineering_expand_all(), the final naming scheme for your plotting config would be: %%-rsi-period_10_ETH/USDT:USDT_1h for the rsi feature with period=10, timeframe=1h, and pair=ETH/USDT:USDT (the :USDT is added if you are using futures pairs). It is useful to simply add print(dataframe.columns) in your populate_indicators() after self.freqai.start() to see the full list of available features that are returned to the strategy for plotting purposes."},{"location":"freqai-configuration/#setting-the-startup_candle_count","title":"Setting the startup_candle_count","text":"

    The startup_candle_count in the FreqAI strategy needs to be set up in the same way as in the standard Freqtrade strategy (see details here). This value is used by Freqtrade to ensure that a sufficient amount of data is provided when calling the dataprovider, to avoid any NaNs at the beginning of the first training. You can easily set this value by identifying the longest period (in candle units) which is passed to the indicator creation functions (e.g., TA-Lib functions). In the presented example, startup_candle_count is 20 since this is the maximum value in indicators_periods_candles.

    Note

    There are instances where the TA-Lib functions actually require more data than just the passed period or else the feature dataset gets populated with NaNs. Anecdotally, multiplying the startup_candle_count by 2 always leads to a fully NaN free training dataset. Hence, it is typically safest to multiply the expected startup_candle_count by 2. Look out for this log message to confirm that the data is clean:

    2022-08-31 15:14:04 - freqtrade.freqai.data_kitchen - INFO - dropped 0 training points due to NaNs in populated dataset 4319.\n
    "},{"location":"freqai-configuration/#creating-a-dynamic-target-threshold","title":"Creating a dynamic target threshold","text":"

    Deciding when to enter or exit a trade can be done in a dynamic way to reflect current market conditions. FreqAI allows you to return additional information from the training of a model (more info here). For example, the &*_std/mean return values describe the statistical distribution of the target/label during the most recent training. Comparing a given prediction to these values allows you to know the rarity of the prediction. In templates/FreqaiExampleStrategy.py, the target_roi and sell_roi are defined to be 1.25 z-scores away from the mean which causes predictions that are closer to the mean to be filtered out.

    dataframe[\"target_roi\"] = dataframe[\"&-s_close_mean\"] + dataframe[\"&-s_close_std\"] * 1.25\ndataframe[\"sell_roi\"] = dataframe[\"&-s_close_mean\"] - dataframe[\"&-s_close_std\"] * 1.25\n

    To consider the population of historical predictions for creating the dynamic target instead of information from the training as discussed above, you would set fit_live_predictions_candles in the config to the number of historical prediction candles you wish to use to generate target statistics.

        \"freqai\": {\n        \"fit_live_predictions_candles\": 300,\n    }\n

    If this value is set, FreqAI will initially use the predictions from the training data and subsequently begin introducing real prediction data as it is generated. FreqAI will save this historical data to be reloaded if you stop and restart a model with the same identifier.

    "},{"location":"freqai-configuration/#using-different-prediction-models","title":"Using different prediction models","text":"

    FreqAI has multiple example prediction model libraries that are ready to be used as is via the flag --freqaimodel. These libraries include CatBoost, LightGBM, and XGBoost regression, classification, and multi-target models, and can be found in freqai/prediction_models/.

    Regression and classification models differ in what targets they predict - a regression model will predict a target of continuous values, for example what price BTC will be at tomorrow, whilst a classifier will predict a target of discrete values, for example if the price of BTC will go up tomorrow or not. This means that you have to specify your targets differently depending on which model type you are using (see details below).

    All of the aforementioned model libraries implement gradient boosted decision tree algorithms. They all work on the principle of ensemble learning, where predictions from multiple simple learners are combined to get a final prediction that is more stable and generalized. The simple learners in this case are decision trees. Gradient boosting refers to the method of learning, where each simple learner is built in sequence - the subsequent learner is used to improve on the error from the previous learner. If you want to learn more about the different model libraries you can find the information in their respective docs:

    • CatBoost: https://catboost.ai/en/docs/
    • LightGBM: https://lightgbm.readthedocs.io/en/v3.3.2/#
    • XGBoost: https://xgboost.readthedocs.io/en/stable/#

    There are also numerous online articles describing and comparing the algorithms. Some relatively lightweight examples would be CatBoost vs. LightGBM vs. XGBoost \u2014 Which is the best algorithm? and XGBoost, LightGBM or CatBoost \u2014 which boosting algorithm should I use?. Keep in mind that the performance of each model is highly dependent on the application and so any reported metrics might not be true for your particular use of the model.

    Apart from the models already available in FreqAI, it is also possible to customize and create your own prediction models using the IFreqaiModel class. You are encouraged to inherit fit(), train(), and predict() to customize various aspects of the training procedures. You can place custom FreqAI models in user_data/freqaimodels - and freqtrade will pick them up from there based on the provided --freqaimodel name - which has to correspond to the class name of your custom model. Make sure to use unique names to avoid overriding built-in models.

    "},{"location":"freqai-configuration/#setting-model-targets","title":"Setting model targets","text":""},{"location":"freqai-configuration/#regressors","title":"Regressors","text":"

    If you are using a regressor, you need to specify a target that has continuous values. FreqAI includes a variety of regressors, such as the CatboostRegressorvia the flag --freqaimodel CatboostRegressor. An example of how you could set a regression target for predicting the price 100 candles into the future would be

    df['&s-close_price'] = df['close'].shift(-100)\n

    If you want to predict multiple targets, you need to define multiple labels using the same syntax as shown above.

    "},{"location":"freqai-configuration/#classifiers","title":"Classifiers","text":"

    If you are using a classifier, you need to specify a target that has discrete values. FreqAI includes a variety of classifiers, such as the CatboostClassifier via the flag --freqaimodel CatboostClassifier. If you elects to use a classifier, the classes need to be set using strings. For example, if you want to predict if the price 100 candles into the future goes up or down you would set

    df['&s-up_or_down'] = np.where( df[\"close\"].shift(-100) > df[\"close\"], 'up', 'down')\n

    If you want to predict multiple targets you must specify all labels in the same label column. You could, for example, add the label same to define where the price was unchanged by setting

    df['&s-up_or_down'] = np.where( df[\"close\"].shift(-100) > df[\"close\"], 'up', 'down')\ndf['&s-up_or_down'] = np.where( df[\"close\"].shift(-100) == df[\"close\"], 'same', df['&s-up_or_down'])\n
    "},{"location":"freqai-configuration/#pytorch-module","title":"PyTorch Module","text":""},{"location":"freqai-configuration/#quick-start","title":"Quick start","text":"

    The easiest way to quickly run a pytorch model is with the following command (for regression task):

    freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel PyTorchMLPRegressor --strategy-path freqtrade/templates \n

    Installation/docker

    The PyTorch module requires large packages such as torch, which should be explicitly requested during ./setup.sh -i by answering \"y\" to the question \"Do you also want dependencies for freqai-rl or PyTorch (~700mb additional space required) [y/N]?\". Users who prefer docker should ensure they use the docker image appended with _freqaitorch. We do provide an explicit docker-compose file for this in docker/docker-compose-freqai.yml - which can be used via docker compose -f docker/docker-compose-freqai.yml run ... - or can be copied to replace the original docker file. This docker-compose file also contains a (disabled) section to enable GPU resources within docker containers. This obviously assumes the system has GPU resources available.

    "},{"location":"freqai-configuration/#structure","title":"Structure","text":""},{"location":"freqai-configuration/#model","title":"Model","text":"

    You can construct your own Neural Network architecture in PyTorch by simply defining your nn.Module class inside your custom IFreqaiModel file and then using that class in your def train() function. Here is an example of logistic regression model implementation using PyTorch (should be used with nn.BCELoss criterion) for classification tasks.

    class LogisticRegression(nn.Module):\n    def __init__(self, input_size: int):\n        super().__init__()\n        # Define your layers\n        self.linear = nn.Linear(input_size, 1)\n        self.activation = nn.Sigmoid()\n\n    def forward(self, x: torch.Tensor) -> torch.Tensor:\n        # Define the forward pass\n        out = self.linear(x)\n        out = self.activation(out)\n        return out\n\nclass MyCoolPyTorchClassifier(BasePyTorchClassifier):\n    \"\"\"\n    This is a custom IFreqaiModel showing how a user might setup their own \n    custom Neural Network architecture for their training.\n    \"\"\"\n\n    @property\n    def data_convertor(self) -> PyTorchDataConvertor:\n        return DefaultPyTorchDataConvertor(target_tensor_type=torch.float)\n\n    def __init__(self, **kwargs) -> None:\n        super().__init__(**kwargs)\n        config = self.freqai_info.get(\"model_training_parameters\", {})\n        self.learning_rate: float = config.get(\"learning_rate\",  3e-4)\n        self.model_kwargs: Dict[str, Any] = config.get(\"model_kwargs\",  {})\n        self.trainer_kwargs: Dict[str, Any] = config.get(\"trainer_kwargs\",  {})\n\n    def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:\n        \"\"\"\n        User sets up the training and test data to fit their desired model here\n        :param data_dictionary: the dictionary holding all data for train, test,\n            labels, weights\n        :param dk: The datakitchen object for the current coin/model\n        \"\"\"\n\n        class_names = self.get_class_names()\n        self.convert_label_column_to_int(data_dictionary, dk, class_names)\n        n_features = data_dictionary[\"train_features\"].shape[-1]\n        model = LogisticRegression(\n            input_dim=n_features\n        )\n        model.to(self.device)\n        optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate)\n        criterion = torch.nn.CrossEntropyLoss()\n        init_model = self.get_init_model(dk.pair)\n        trainer = PyTorchModelTrainer(\n            model=model,\n            optimizer=optimizer,\n            criterion=criterion,\n            model_meta_data={\"class_names\": class_names},\n            device=self.device,\n            init_model=init_model,\n            data_convertor=self.data_convertor,\n            **self.trainer_kwargs,\n        )\n        trainer.fit(data_dictionary, self.splits)\n        return trainer\n
    "},{"location":"freqai-configuration/#trainer","title":"Trainer","text":"

    The PyTorchModelTrainer performs the idiomatic PyTorch train loop: Define our model, loss function, and optimizer, and then move them to the appropriate device (GPU or CPU). Inside the loop, we iterate through the batches in the dataloader, move the data to the device, compute the prediction and loss, backpropagate, and update the model parameters using the optimizer.

    In addition, the trainer is responsible for the following: - saving and loading the model - converting the data from pandas.DataFrame to torch.Tensor.

    "},{"location":"freqai-configuration/#integration-with-freqai-module","title":"Integration with Freqai module","text":"

    Like all freqai models, PyTorch models inherit IFreqaiModel. IFreqaiModel declares three abstract methods: train, fit, and predict. we implement these methods in three levels of hierarchy. From top to bottom:

    1. BasePyTorchModel - Implements the train method. all BasePyTorch* inherit it. responsible for general data preparation (e.g., data normalization) and calling the fit method. Sets device attribute used by children classes. Sets model_type attribute used by the parent class.
    2. BasePyTorch* - Implements the predict method. Here, the * represents a group of algorithms, such as classifiers or regressors. responsible for data preprocessing, predicting, and postprocessing if needed.
    3. PyTorch*Classifier / PyTorch*Regressor - implements the fit method. responsible for the main train flaw, where we initialize the trainer and model objects.

    "},{"location":"freqai-configuration/#full-example","title":"Full example","text":"

    Building a PyTorch regressor using MLP (multilayer perceptron) model, MSELoss criterion, and AdamW optimizer.

    class PyTorchMLPRegressor(BasePyTorchRegressor):\n    def __init__(self, **kwargs) -> None:\n        super().__init__(**kwargs)\n        config = self.freqai_info.get(\"model_training_parameters\", {})\n        self.learning_rate: float = config.get(\"learning_rate\",  3e-4)\n        self.model_kwargs: Dict[str, Any] = config.get(\"model_kwargs\",  {})\n        self.trainer_kwargs: Dict[str, Any] = config.get(\"trainer_kwargs\",  {})\n\n    def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:\n        n_features = data_dictionary[\"train_features\"].shape[-1]\n        model = PyTorchMLPModel(\n            input_dim=n_features,\n            output_dim=1,\n            **self.model_kwargs\n        )\n        model.to(self.device)\n        optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate)\n        criterion = torch.nn.MSELoss()\n        init_model = self.get_init_model(dk.pair)\n        trainer = PyTorchModelTrainer(\n            model=model,\n            optimizer=optimizer,\n            criterion=criterion,\n            device=self.device,\n            init_model=init_model,\n            target_tensor_type=torch.float,\n            **self.trainer_kwargs,\n        )\n        trainer.fit(data_dictionary)\n        return trainer\n

    Here we create a PyTorchMLPRegressor class that implements the fit method. The fit method specifies the training building blocks: model, optimizer, criterion, and trainer. We inherit both BasePyTorchRegressor and BasePyTorchModel, where the former implements the predict method that is suitable for our regression task, and the latter implements the train method.

    Setting Class Names for Classifiers

    When using classifiers, the user must declare the class names (or targets) by overriding the IFreqaiModel.class_names attribute. This is achieved by setting self.freqai.class_names in the FreqAI strategy inside the set_freqai_targets method.

    For example, if you are using a binary classifier to predict price movements as up or down, you can set the class names as follows:

    def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:\n    self.freqai.class_names = [\"down\", \"up\"]\n    dataframe['&s-up_or_down'] = np.where(dataframe[\"close\"].shift(-100) >\n                                              dataframe[\"close\"], 'up', 'down')\n\n    return dataframe\n
    To see a full example, you can refer to the classifier test strategy class.

    "},{"location":"freqai-configuration/#improving-performance-with-torchcompile","title":"Improving performance with torch.compile()","text":"

    Torch provides a torch.compile() method that can be used to improve performance for specific GPU hardware. More details can be found here. In brief, you simply wrap your model in torch.compile():

            model = PyTorchMLPModel(\n            input_dim=n_features,\n            output_dim=1,\n            **self.model_kwargs\n        )\n        model.to(self.device)\n        model = torch.compile(model)\n

    Then proceed to use the model as normal. Keep in mind that doing this will remove eager execution, which means errors and tracebacks will not be informative.

    "},{"location":"freqai-developers/","title":"Development","text":""},{"location":"freqai-developers/#project-architecture","title":"Project architecture","text":"

    The architecture and functions of FreqAI are generalized to encourages development of unique features, functions, models, etc.

    The class structure and a detailed algorithmic overview is depicted in the following diagram:

    As shown, there are three distinct objects comprising FreqAI:

    • IFreqaiModel - A singular persistent object containing all the necessary logic to collect, store, and process data, engineer features, run training, and inference models.
    • FreqaiDataKitchen - A non-persistent object which is created uniquely for each unique asset/model. Beyond metadata, it also contains a variety of data processing tools.
    • FreqaiDataDrawer - A singular persistent object containing all the historical predictions, models, and save/load methods.

    There are a variety of built-in prediction models which inherit directly from IFreqaiModel. Each of these models have full access to all methods in IFreqaiModel and can therefore override any of those functions at will. However, advanced users will likely stick to overriding fit(), train(), predict(), and data_cleaning_train/predict().

    "},{"location":"freqai-developers/#data-handling","title":"Data handling","text":"

    FreqAI aims to organize model files, prediction data, and meta data in a way that simplifies post-processing and enhances crash resilience by automatic data reloading. The data is saved in a file structure,user_data_dir/models/, which contains all the data associated with the trainings and backtests. The FreqaiDataKitchen() relies heavily on the file structure for proper training and inferencing and should therefore not be manually modified.

    "},{"location":"freqai-developers/#file-structure","title":"File structure","text":"

    The file structure is automatically generated based on the model identifier set in the config. The following structure shows where the data is stored for post processing:

    Structure Description config_*.json A copy of the model specific configuration file. historic_predictions.pkl A file containing all historic predictions generated during the lifetime of the identifier model during live deployment. historic_predictions.pkl is used to reload the model after a crash or a config change. A backup file is always held in case of corruption on the main file. FreqAI automatically detects corruption and replaces the corrupted file with the backup. pair_dictionary.json A file containing the training queue as well as the on disk location of the most recently trained model. sub-train-*_TIMESTAMP A folder containing all the files associated with a single model, such as: *_metadata.json - Metadata for the model, such as normalization max/min, expected training feature list, etc. *_model.* - The model file saved to disk for reloading from a crash. Can be joblib (typical boosting libs), zip (stable_baselines), hd5 (keras type), etc. *_pca_object.pkl - The Principal component analysis (PCA) transform (if principal_component_analysis: True is set in the config) which will be used to transform unseen prediction features. *_svm_model.pkl - The Support Vector Machine (SVM) model (if use_SVM_to_remove_outliers: True is set in the config) which is used to detect outliers in unseen prediction features. *_trained_df.pkl - The dataframe containing all the training features used to train the identifier model. This is used for computing the Dissimilarity Index (DI) and can also be used for post-processing. *_trained_dates.df.pkl - The dates associated with the trained_df.pkl, which is useful for post-processing.

    The example file structure would look like this:

    \u251c\u2500\u2500 models\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 unique-id\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 config_freqai.example.json\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 historic_predictions.backup.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 historic_predictions.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 pair_dictionary.json\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 sub-train-1INCH_1662821319\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_metadata.json\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_pca_object.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_svm_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_trained_dates_df.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u2514\u2500\u2500 cb_1inch_1662821319_trained_df.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 sub-train-1INCH_1662821371\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_metadata.json\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_pca_object.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_svm_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_trained_dates_df.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u2514\u2500\u2500 cb_1inch_1662821371_trained_df.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 sub-train-ADA_1662821344\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_metadata.json\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_pca_object.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_svm_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_trained_dates_df.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u2514\u2500\u2500 cb_ada_1662821344_trained_df.pkl\n\u2502\u00a0\u00a0     \u2514\u2500\u2500 sub-train-ADA_1662821399\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_metadata.json\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_model.joblib\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_pca_object.pkl\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_svm_model.joblib\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_trained_dates_df.pkl\n\u2502\u00a0\u00a0         \u2514\u2500\u2500 cb_ada_1662821399_trained_df.pkl\n
    "},{"location":"freqai-feature-engineering/","title":"Feature engineering","text":""},{"location":"freqai-feature-engineering/#defining-the-features","title":"Defining the features","text":"

    Low level feature engineering is performed in the user strategy within a set of functions called feature_engineering_*. These function set the base features such as, RSI, MFI, EMA, SMA, time of day, volume, etc. The base features can be custom indicators or they can be imported from any technical-analysis library that you can find. FreqAI is equipped with a set of functions to simplify rapid large-scale feature engineering:

    Function Description feature_engineering_expand_all() This optional function will automatically expand the defined features on the config defined indicator_periods_candles, include_timeframes, include_shifted_candles, and include_corr_pairs. feature_engineering_expand_basic() This optional function will automatically expand the defined features on the config defined include_timeframes, include_shifted_candles, and include_corr_pairs. Note: this function does not expand across indicator_periods_candles. feature_engineering_standard() This optional function will be called once with the dataframe of the base timeframe. This is the final function to be called, which means that the dataframe entering this function will contain all the features and columns from the base asset created by the other feature_engineering_expand functions. This function is a good place to do custom exotic feature extractions (e.g. tsfresh). This function is also a good place for any feature that should not be auto-expanded upon (e.g., day of the week). set_freqai_targets() Required function to set the targets for the model. All targets must be prepended with & to be recognized by the FreqAI internals.

    Meanwhile, high level feature engineering is handled within \"feature_parameters\":{} in the FreqAI config. Within this file, it is possible to decide large scale feature expansions on top of the base_features such as \"including correlated pairs\" or \"including informative timeframes\" or even \"including recent candles.\"

    It is advisable to start from the template feature_engineering_* functions in the source provided example strategy (found in templates/FreqaiExampleStrategy.py) to ensure that the feature definitions are following the correct conventions. Here is an example of how to set the indicators and labels in the strategy:

        def feature_engineering_expand_all(self, dataframe: DataFrame, period, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and\n        `include_corr_pairs`. In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *\n        `include_corr_pairs` numbers of features added to the model.\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        Access metadata such as the current pair/timeframe/period with:\n\n        `metadata[\"pair\"]` `metadata[\"tf\"]`  `metadata[\"period\"]`\n\n        :param df: strategy dataframe which will receive the features\n        :param period: period of the indicator - usage example:\n        :param metadata: metadata of current pair\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n        \"\"\"\n\n        dataframe[\"%-rsi-period\"] = ta.RSI(dataframe, timeperiod=period)\n        dataframe[\"%-mfi-period\"] = ta.MFI(dataframe, timeperiod=period)\n        dataframe[\"%-adx-period\"] = ta.ADX(dataframe, timeperiod=period)\n        dataframe[\"%-sma-period\"] = ta.SMA(dataframe, timeperiod=period)\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n\n        bollinger = qtpylib.bollinger_bands(\n            qtpylib.typical_price(dataframe), window=period, stds=2.2\n        )\n        dataframe[\"bb_lowerband-period\"] = bollinger[\"lower\"]\n        dataframe[\"bb_middleband-period\"] = bollinger[\"mid\"]\n        dataframe[\"bb_upperband-period\"] = bollinger[\"upper\"]\n\n        dataframe[\"%-bb_width-period\"] = (\n            dataframe[\"bb_upperband-period\"]\n            - dataframe[\"bb_lowerband-period\"]\n        ) / dataframe[\"bb_middleband-period\"]\n        dataframe[\"%-close-bb_lower-period\"] = (\n            dataframe[\"close\"] / dataframe[\"bb_lowerband-period\"]\n        )\n\n        dataframe[\"%-roc-period\"] = ta.ROC(dataframe, timeperiod=period)\n\n        dataframe[\"%-relative_volume-period\"] = (\n            dataframe[\"volume\"] / dataframe[\"volume\"].rolling(period).mean()\n        )\n\n        return dataframe\n\n    def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.\n        In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `include_timeframes` * `include_shifted_candles` * `include_corr_pairs`\n        numbers of features added to the model.\n\n        Features defined here will *not* be automatically duplicated on user defined\n        `indicator_periods_candles`\n\n        Access metadata such as the current pair/timeframe with:\n\n        `metadata[\"pair\"]` `metadata[\"tf\"]`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        :param metadata: metadata of current pair\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-ema-200\"] = ta.EMA(dataframe, timeperiod=200)\n        \"\"\"\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-raw_volume\"] = dataframe[\"volume\"]\n        dataframe[\"%-raw_price\"] = dataframe[\"close\"]\n        return dataframe\n\n    def feature_engineering_standard(self, dataframe: DataFrame, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This optional function will be called once with the dataframe of the base timeframe.\n        This is the final function to be called, which means that the dataframe entering this\n        function will contain all the features and columns created by all other\n        freqai_feature_engineering_* functions.\n\n        This function is a good place to do custom exotic feature extractions (e.g. tsfresh).\n        This function is a good place for any feature that should not be auto-expanded upon\n        (e.g. day of the week).\n\n        Access metadata such as the current pair with:\n\n        `metadata[\"pair\"]`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        :param metadata: metadata of current pair\n        usage example: dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        \"\"\"\n        dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        dataframe[\"%-hour_of_day\"] = (dataframe[\"date\"].dt.hour + 1) / 25\n        return dataframe\n\n    def set_freqai_targets(self, dataframe: DataFrame, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        Access metadata such as the current pair with:\n\n        `metadata[\"pair\"]`\n\n        :param df: strategy dataframe which will receive the targets\n        :param metadata: metadata of current pair\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        dataframe[\"&-s_close\"] = (\n            dataframe[\"close\"]\n            .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .mean()\n            / dataframe[\"close\"]\n            - 1\n            )\n\n        return dataframe\n

    In the presented example, the user does not wish to pass the bb_lowerband as a feature to the model, and has therefore not prepended it with %. The user does, however, wish to pass bb_width to the model for training/prediction and has therefore prepended it with %.

    After having defined the base features, the next step is to expand upon them using the powerful feature_parameters in the configuration file:

        \"freqai\": {\n        //...\n        \"feature_parameters\" : {\n            \"include_timeframes\": [\"5m\",\"15m\",\"4h\"],\n            \"include_corr_pairlist\": [\n                \"ETH/USD\",\n                \"LINK/USD\",\n                \"BNB/USD\"\n            ],\n            \"label_period_candles\": 24,\n            \"include_shifted_candles\": 2,\n            \"indicator_periods_candles\": [10, 20]\n        },\n        //...\n    }\n

    The include_timeframes in the config above are the timeframes (tf) of each call to feature_engineering_expand_*() in the strategy. In the presented case, the user is asking for the 5m, 15m, and 4h timeframes of the rsi, mfi, roc, and bb_width to be included in the feature set.

    You can ask for each of the defined features to be included also for informative pairs using the include_corr_pairlist. This means that the feature set will include all the features from feature_engineering_expand_*() on all the include_timeframes for each of the correlated pairs defined in the config (ETH/USD, LINK/USD, and BNB/USD in the presented example).

    include_shifted_candles indicates the number of previous candles to include in the feature set. For example, include_shifted_candles: 2 tells FreqAI to include the past 2 candles for each of the features in the feature set.

    In total, the number of features the user of the presented example strategy has created is: length of include_timeframes * no. features in feature_engineering_expand_*() * length of include_corr_pairlist * no. include_shifted_candles * length of indicator_periods_candles \\(= 3 * 3 * 3 * 2 * 2 = 108\\).

    !!! note \"Learn more about creative feature engineering\" Check out our medium article geared toward helping users learn how to creatively engineer features.

    "},{"location":"freqai-feature-engineering/#gain-finer-control-over-feature_engineering_-functions-with-metadata","title":"Gain finer control over feature_engineering_* functions with metadata","text":"

    All feature_engineering_* and set_freqai_targets() functions are passed a metadata dictionary which contains information about the pair, tf (timeframe), and period that FreqAI is automating for feature building. As such, a user can use metadata inside feature_engineering_* functions as criteria for blocking/reserving features for certain timeframes, periods, pairs etc.

    def feature_engineering_expand_all(self, dataframe: DataFrame, period, metadata, **kwargs) -> DataFrame:\n    if metadata[\"tf\"] == \"1h\":\n        dataframe[\"%-roc-period\"] = ta.ROC(dataframe, timeperiod=period)\n

    This will block ta.ROC() from being added to any timeframes other than \"1h\".

    "},{"location":"freqai-feature-engineering/#returning-additional-info-from-training","title":"Returning additional info from training","text":"

    Important metrics can be returned to the strategy at the end of each model training by assigning them to dk.data['extra_returns_per_train']['my_new_value'] = XYZ inside the custom prediction model class.

    FreqAI takes the my_new_value assigned in this dictionary and expands it to fit the dataframe that is returned to the strategy. You can then use the returned metrics in your strategy through dataframe['my_new_value']. An example of how return values can be used in FreqAI are the &*_mean and &*_std values that are used to created a dynamic target threshold.

    Another example, where the user wants to use live metrics from the trade database, is shown below:

        \"freqai\": {\n        \"extra_returns_per_train\": {\"total_profit\": 4}\n    }\n

    You need to set the standard dictionary in the config so that FreqAI can return proper dataframe shapes. These values will likely be overridden by the prediction model, but in the case where the model has yet to set them, or needs a default initial value, the pre-set values are what will be returned.

    "},{"location":"freqai-feature-engineering/#weighting-features-for-temporal-importance","title":"Weighting features for temporal importance","text":"

    FreqAI allows you to set a weight_factor to weight recent data more strongly than past data via an exponential function:

    \\[ W_i = \\exp(\\frac{-i}{\\alpha*n}) \\]

    where \\(W_i\\) is the weight of data point \\(i\\) in a total set of \\(n\\) data points. Below is a figure showing the effect of different weight factors on the data points in a feature set.

    "},{"location":"freqai-feature-engineering/#building-the-data-pipeline","title":"Building the data pipeline","text":"

    By default, FreqAI builds a dynamic pipeline based on user configuration settings. The default settings are robust and designed to work with a variety of methods. These two steps are a MinMaxScaler(-1,1) and a VarianceThreshold which removes any column that has 0 variance. Users can activate other steps with more configuration parameters. For example if users add use_SVM_to_remove_outliers: true to the freqai config, then FreqAI will automatically add the SVMOutlierExtractor to the pipeline. Likewise, users can add principal_component_analysis: true to the freqai config to activate PCA. The DissimilarityIndex is activated with DI_threshold: 1. Finally, noise can also be added to the data with noise_standard_deviation: 0.1. Finally, users can add DBSCAN outlier removal with use_DBSCAN_to_remove_outliers: true.

    More information available

    Please review the parameter table for more information on these parameters.

    "},{"location":"freqai-feature-engineering/#customizing-the-pipeline","title":"Customizing the pipeline","text":"

    Users are encouraged to customize the data pipeline to their needs by building their own data pipeline. This can be done by simply setting dk.feature_pipeline to their desired Pipeline object inside their IFreqaiModel train() function, or if they prefer not to touch the train() function, they can override define_data_pipeline/define_label_pipeline functions in their IFreqaiModel:

    More information available

    FreqAI uses the DataSieve pipeline, which follows the SKlearn pipeline API, but adds, among other features, coherence between the X, y, and sample_weight vector point removals, feature removal, feature name following.

    from datasieve.transforms import SKLearnWrapper, DissimilarityIndex\nfrom datasieve.pipeline import Pipeline\nfrom sklearn.preprocessing import QuantileTransformer, StandardScaler\nfrom freqai.base_models import BaseRegressionModel\n\n\nclass MyFreqaiModel(BaseRegressionModel):\n    \"\"\"\n    Some cool custom model\n    \"\"\"\n    def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:\n        \"\"\"\n        My custom fit function\n        \"\"\"\n        model = cool_model.fit()\n        return model\n\n    def define_data_pipeline(self) -> Pipeline:\n        \"\"\"\n        User defines their custom feature pipeline here (if they wish)\n        \"\"\"\n        feature_pipeline = Pipeline([\n            ('qt', SKLearnWrapper(QuantileTransformer(output_distribution='normal'))),\n            ('di', ds.DissimilarityIndex(di_threshold=1))\n        ])\n\n        return feature_pipeline\n\n    def define_label_pipeline(self) -> Pipeline:\n        \"\"\"\n        User defines their custom label pipeline here (if they wish)\n        \"\"\"\n        label_pipeline = Pipeline([\n            ('qt', SKLearnWrapper(StandardScaler())),\n        ])\n\n        return label_pipeline\n

    Here, you are defining the exact pipeline that will be used for your feature set during training and prediction. You can use most SKLearn transformation steps by wrapping them in the SKLearnWrapper class as shown above. In addition, you can use any of the transformations available in the DataSieve library.

    You can easily add your own transformation by creating a class that inherits from the datasieve BaseTransform and implementing your fit(), transform() and inverse_transform() methods:

    from datasieve.transforms.base_transform import BaseTransform\n# import whatever else you need\n\nclass MyCoolTransform(BaseTransform):\n    def __init__(self, **kwargs):\n        self.param1 = kwargs.get('param1', 1)\n\n    def fit(self, X, y=None, sample_weight=None, feature_list=None, **kwargs):\n        # do something with X, y, sample_weight, or/and feature_list\n        return X, y, sample_weight, feature_list\n\n    def transform(self, X, y=None, sample_weight=None,\n                  feature_list=None, outlier_check=False, **kwargs):\n        # do something with X, y, sample_weight, or/and feature_list\n        return X, y, sample_weight, feature_list\n\n    def inverse_transform(self, X, y=None, sample_weight=None, feature_list=None, **kwargs):\n        # do/dont do something with X, y, sample_weight, or/and feature_list\n        return X, y, sample_weight, feature_list\n

    Hint

    You can define this custom class in the same file as your IFreqaiModel.

    "},{"location":"freqai-feature-engineering/#migrating-a-custom-ifreqaimodel-to-the-new-pipeline","title":"Migrating a custom IFreqaiModel to the new Pipeline","text":"

    If you have created your own custom IFreqaiModel with a custom train()/predict() function, and you still rely on data_cleaning_train/predict(), then you will need to migrate to the new pipeline. If your model does not rely on data_cleaning_train/predict(), then you do not need to worry about this migration.

    More details about the migration can be found here.

    "},{"location":"freqai-feature-engineering/#outlier-detection","title":"Outlier detection","text":"

    Equity and crypto markets suffer from a high level of non-patterned noise in the form of outlier data points. FreqAI implements a variety of methods to identify such outliers and hence mitigate risk.

    "},{"location":"freqai-feature-engineering/#identifying-outliers-with-the-dissimilarity-index-di","title":"Identifying outliers with the Dissimilarity Index (DI)","text":"

    The Dissimilarity Index (DI) aims to quantify the uncertainty associated with each prediction made by the model.

    You can tell FreqAI to remove outlier data points from the training/test data sets using the DI by including the following statement in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"DI_threshold\": 1\n        }\n    }\n

    Which will add DissimilarityIndex step to your feature_pipeline and set the threshold to 1. The DI allows predictions which are outliers (not existent in the model feature space) to be thrown out due to low levels of certainty. To do so, FreqAI measures the distance between each training data point (feature vector), \\(X_{a}\\), and all other training data points:

    \\[ d_{ab} = \\sqrt{\\sum_{j=1}^p(X_{a,j}-X_{b,j})^2} \\]

    where \\(d_{ab}\\) is the distance between the normalized points \\(a\\) and \\(b\\), and \\(p\\) is the number of features, i.e., the length of the vector \\(X\\). The characteristic distance, \\(\\overline{d}\\), for a set of training data points is simply the mean of the average distances:

    \\[ \\overline{d} = \\sum_{a=1}^n(\\sum_{b=1}^n(d_{ab}/n)/n) \\]

    \\(\\overline{d}\\) quantifies the spread of the training data, which is compared to the distance between a new prediction feature vectors, \\(X_k\\) and all the training data:

    \\[ d_k = \\arg \\min d_{k,i} \\]

    This enables the estimation of the Dissimilarity Index as:

    \\[ DI_k = d_k/\\overline{d} \\]

    You can tweak the DI through the DI_threshold to increase or decrease the extrapolation of the trained model. A higher DI_threshold means that the DI is more lenient and allows predictions further away from the training data to be used whilst a lower DI_threshold has the opposite effect and hence discards more predictions.

    Below is a figure that describes the DI for a 3D data set.

    "},{"location":"freqai-feature-engineering/#identifying-outliers-using-a-support-vector-machine-svm","title":"Identifying outliers using a Support Vector Machine (SVM)","text":"

    You can tell FreqAI to remove outlier data points from the training/test data sets using a Support Vector Machine (SVM) by including the following statement in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"use_SVM_to_remove_outliers\": true\n        }\n    }\n

    Which will add SVMOutlierExtractor step to your feature_pipeline. The SVM will be trained on the training data and any data point that the SVM deems to be beyond the feature space will be removed.

    You can elect to provide additional parameters for the SVM, such as shuffle, and nu via the feature_parameters.svm_params dictionary in the config.

    The parameter shuffle is by default set to False to ensure consistent results. If it is set to True, running the SVM multiple times on the same data set might result in different outcomes due to max_iter being to low for the algorithm to reach the demanded tol. Increasing max_iter solves this issue but causes the procedure to take longer time.

    The parameter nu, very broadly, is the amount of data points that should be considered outliers and should be between 0 and 1.

    "},{"location":"freqai-feature-engineering/#identifying-outliers-with-dbscan","title":"Identifying outliers with DBSCAN","text":"

    You can configure FreqAI to use DBSCAN to cluster and remove outliers from the training/test data set or incoming outliers from predictions, by activating use_DBSCAN_to_remove_outliers in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"use_DBSCAN_to_remove_outliers\": true\n        }\n    }\n

    Which will add the DataSieveDBSCAN step to your feature_pipeline. This is an unsupervised machine learning algorithm that clusters data without needing to know how many clusters there should be.

    Given a number of data points \\(N\\), and a distance \\(\\varepsilon\\), DBSCAN clusters the data set by setting all data points that have \\(N-1\\) other data points within a distance of \\(\\varepsilon\\) as core points. A data point that is within a distance of \\(\\varepsilon\\) from a core point but that does not have \\(N-1\\) other data points within a distance of \\(\\varepsilon\\) from itself is considered an edge point. A cluster is then the collection of core points and edge points. Data points that have no other data points at a distance \\(<\\varepsilon\\) are considered outliers. The figure below shows a cluster with \\(N = 3\\).

    FreqAI uses sklearn.cluster.DBSCAN (details are available on scikit-learn's webpage here (external website)) with min_samples (\\(N\\)) taken as \u00bc of the no. of time points (candles) in the feature set. eps (\\(\\varepsilon\\)) is computed automatically as the elbow point in the k-distance graph computed from the nearest neighbors in the pairwise distances of all data points in the feature set.

    "},{"location":"freqai-feature-engineering/#data-dimensionality-reduction-with-principal-component-analysis","title":"Data dimensionality reduction with Principal Component Analysis","text":"

    You can reduce the dimensionality of your features by activating the principal_component_analysis in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"principal_component_analysis\": true\n        }\n    }\n

    This will perform PCA on the features and reduce their dimensionality so that the explained variance of the data set is >= 0.999. Reducing data dimensionality makes training the model faster and hence allows for more up-to-date models.

    "},{"location":"freqai-parameter-table/","title":"Parameter table","text":"

    The table below will list all configuration parameters available for FreqAI. Some of the parameters are exemplified in config_examples/config_freqai.example.json.

    Mandatory parameters are marked as Required and have to be set in one of the suggested ways.

    "},{"location":"freqai-parameter-table/#general-configuration-parameters","title":"General configuration parameters","text":"Parameter Description General configuration parameters within the config.freqai tree freqai Required. The parent dictionary containing all the parameters for controlling FreqAI. Datatype: Dictionary. train_period_days Required. Number of days to use for the training data (width of the sliding window). Datatype: Positive integer. backtest_period_days Required. Number of days to inference from the trained model before sliding the train_period_days window defined above, and retraining the model during backtesting (more info here). This can be fractional days, but beware that the provided timerange will be divided by this number to yield the number of trainings necessary to complete the backtest. Datatype: Float. identifier Required. A unique ID for the current model. If models are saved to disk, the identifier allows for reloading specific pre-trained models/data. Datatype: String. live_retrain_hours Frequency of retraining during dry/live runs. Datatype: Float > 0. Default: 0 (models retrain as often as possible). expiration_hours Avoid making predictions if a model is more than expiration_hours old. Datatype: Positive integer. Default: 0 (models never expire). purge_old_models Number of models to keep on disk (not relevant to backtesting). Default is 2, which means that dry/live runs will keep the latest 2 models on disk. Setting to 0 keeps all models. This parameter also accepts a boolean to maintain backwards compatibility. Datatype: Integer. Default: 2. save_backtest_models Save models to disk when running backtesting. Backtesting operates most efficiently by saving the prediction data and reusing them directly for subsequent runs (when you wish to tune entry/exit parameters). Saving backtesting models to disk also allows to use the same model files for starting a dry/live instance with the same model identifier. Datatype: Boolean. Default: False (no models are saved). fit_live_predictions_candles Number of historical candles to use for computing target (label) statistics from prediction data, instead of from the training dataset (more information can be found here). Datatype: Positive integer. continual_learning Use the final state of the most recently trained model as starting point for the new model, allowing for incremental learning (more information can be found here). Beware that this is currently a naive approach to incremental learning, and it has a high probability of overfitting/getting stuck in local minima while the market moves away from your model. We have the connections here primarily for experimental purposes and so that it is ready for more mature approaches to continual learning in chaotic systems like the crypto market. Datatype: Boolean. Default: False. write_metrics_to_disk Collect train timings, inference timings and cpu usage in json file. Datatype: Boolean. Default: False data_kitchen_thread_count Designate the number of threads you want to use for data processing (outlier methods, normalization, etc.). This has no impact on the number of threads used for training. If user does not set it (default), FreqAI will use max number of threads - 2 (leaving 1 physical core available for Freqtrade bot and FreqUI) Datatype: Positive integer. activate_tensorboard Indicate whether or not to activate tensorboard for the tensorboard enabled modules (currently Reinforcment Learning, XGBoost, Catboost, and PyTorch). Tensorboard needs Torch installed, which means you will need the torch/RL docker image or you need to answer \"yes\" to the install question about whether or not you wish to install Torch. Datatype: Boolean. Default: True."},{"location":"freqai-parameter-table/#feature-parameters","title":"Feature parameters","text":"Parameter Description Feature parameters within the freqai.feature_parameters sub dictionary feature_parameters A dictionary containing the parameters used to engineer the feature set. Details and examples are shown here. Datatype: Dictionary. include_timeframes A list of timeframes that all indicators in feature_engineering_expand_*() will be created for. The list is added as features to the base indicators dataset. Datatype: List of timeframes (strings). include_corr_pairlist A list of correlated coins that FreqAI will add as additional features to all pair_whitelist coins. All indicators set in feature_engineering_expand_*() during feature engineering (see details here) will be created for each correlated coin. The correlated coins features are added to the base indicators dataset. Datatype: List of assets (strings). label_period_candles Number of candles into the future that the labels are created for. This can be used in set_freqai_targets() (see templates/FreqaiExampleStrategy.py for detailed usage). This parameter is not necessarily required, you can create custom labels and choose whether to make use of this parameter or not. Please see templates/FreqaiExampleStrategy.py to see the example usage. Datatype: Positive integer. include_shifted_candles Add features from previous candles to subsequent candles with the intent of adding historical information. If used, FreqAI will duplicate and shift all features from the include_shifted_candles previous candles so that the information is available for the subsequent candle. Datatype: Positive integer. weight_factor Weight training data points according to their recency (see details here). Datatype: Positive float (typically < 1). indicator_max_period_candles No longer used (#7325). Replaced by startup_candle_count which is set in the strategy. startup_candle_count is timeframe independent and defines the maximum period used in feature_engineering_*() for indicator creation. FreqAI uses this parameter together with the maximum timeframe in include_time_frames to calculate how many data points to download such that the first data point does not include a NaN. Datatype: Positive integer. indicator_periods_candles Time periods to calculate indicators for. The indicators are added to the base indicator dataset. Datatype: List of positive integers. principal_component_analysis Automatically reduce the dimensionality of the data set using Principal Component Analysis. See details about how it works here Datatype: Boolean. Default: False. plot_feature_importances Create a feature importance plot for each model for the top/bottom plot_feature_importances number of features. Plot is stored in user_data/models/<identifier>/sub-train-<COIN>_<timestamp>.html. Datatype: Integer. Default: 0. DI_threshold Activates the use of the Dissimilarity Index for outlier detection when set to > 0. See details about how it works here. Datatype: Positive float (typically < 1). use_SVM_to_remove_outliers Train a support vector machine to detect and remove outliers from the training dataset, as well as from incoming data points. See details about how it works here. Datatype: Boolean. svm_params All parameters available in Sklearn's SGDOneClassSVM(). See details about some select parameters here. Datatype: Dictionary. use_DBSCAN_to_remove_outliers Cluster data using the DBSCAN algorithm to identify and remove outliers from training and prediction data. See details about how it works here. Datatype: Boolean. noise_standard_deviation If set, FreqAI adds noise to the training features with the aim of preventing overfitting. FreqAI generates random deviates from a gaussian distribution with a standard deviation of noise_standard_deviation and adds them to all data points. noise_standard_deviation should be kept relative to the normalized space, i.e., between -1 and 1. In other words, since data in FreqAI is always normalized to be between -1 and 1, noise_standard_deviation: 0.05 would result in 32% of the data being randomly increased/decreased by more than 2.5% (i.e., the percent of data falling within the first standard deviation). Datatype: Integer. Default: 0. outlier_protection_percentage Enable to prevent outlier detection methods from discarding too much data. If more than outlier_protection_percentage % of points are detected as outliers by the SVM or DBSCAN, FreqAI will log a warning message and ignore outlier detection, i.e., the original dataset will be kept intact. If the outlier protection is triggered, no predictions will be made based on the training dataset. Datatype: Float. Default: 30. reverse_train_test_order Split the feature dataset (see below) and use the latest data split for training and test on historical split of the data. This allows the model to be trained up to the most recent data point, while avoiding overfitting. However, you should be careful to understand the unorthodox nature of this parameter before employing it. Datatype: Boolean. Default: False (no reversal). shuffle_after_split Split the data into train and test sets, and then shuffle both sets individually. Datatype: Boolean. Default: False. buffer_train_data_candles Cut buffer_train_data_candles off the beginning and end of the training data after the indicators were populated. The main example use is when predicting maxima and minima, the argrelextrema function cannot know the maxima/minima at the edges of the timerange. To improve model accuracy, it is best to compute argrelextrema on the full timerange and then use this function to cut off the edges (buffer) by the kernel. In another case, if the targets are set to a shifted price movement, this buffer is unnecessary because the shifted candles at the end of the timerange will be NaN and FreqAI will automatically cut those off of the training dataset. Datatype: Integer. Default: 0."},{"location":"freqai-parameter-table/#data-split-parameters","title":"Data split parameters","text":"Parameter Description Data split parameters within the freqai.data_split_parameters sub dictionary data_split_parameters Include any additional parameters available from scikit-learn test_train_split(), which are shown here (external website). Datatype: Dictionary. test_size The fraction of data that should be used for testing instead of training. Datatype: Positive float < 1. shuffle Shuffle the training data points during training. Typically, to not remove the chronological order of data in time-series forecasting, this is set to False. Datatype: Boolean. Default: False."},{"location":"freqai-parameter-table/#model-training-parameters","title":"Model training parameters","text":"Parameter Description Model training parameters within the freqai.model_training_parameters sub dictionary model_training_parameters A flexible dictionary that includes all parameters available by the selected model library. For example, if you use LightGBMRegressor, this dictionary can contain any parameter available by the LightGBMRegressor here (external website). If you select a different model, this dictionary can contain any parameter from that model. A list of the currently available models can be found here. Datatype: Dictionary. n_estimators The number of boosted trees to fit in the training of the model. Datatype: Integer. learning_rate Boosting learning rate during training of the model. Datatype: Float. n_jobs, thread_count, task_type Set the number of threads for parallel processing and the task_type (gpu or cpu). Different model libraries use different parameter names. Datatype: Float."},{"location":"freqai-parameter-table/#reinforcement-learning-parameters","title":"Reinforcement Learning parameters","text":"Parameter Description Reinforcement Learning Parameters within the freqai.rl_config sub dictionary rl_config A dictionary containing the control parameters for a Reinforcement Learning model. Datatype: Dictionary. train_cycles Training time steps will be set based on the `train_cycles * number of training data points. Datatype: Integer. max_trade_duration_candles Guides the agent training to keep trades below desired length. Example usage shown in prediction_models/ReinforcementLearner.py within the customizable calculate_reward() function. Datatype: int. model_type Model string from stable_baselines3 or SBcontrib. Available strings include: 'TRPO', 'ARS', 'RecurrentPPO', 'MaskablePPO', 'PPO', 'A2C', 'DQN'. User should ensure that model_training_parameters match those available to the corresponding stable_baselines3 model by visiting their documentation. PPO doc (external website) Datatype: string. policy_type One of the available policy types from stable_baselines3 Datatype: string. max_training_drawdown_pct The maximum drawdown that the agent is allowed to experience during training. Datatype: float. Default: 0.8 cpu_count Number of threads/cpus to dedicate to the Reinforcement Learning training process (depending on if ReinforcementLearning_multiproc is selected or not). Recommended to leave this untouched, by default, this value is set to the total number of physical cores minus 1. Datatype: int. model_reward_parameters Parameters used inside the customizable calculate_reward() function in ReinforcementLearner.py Datatype: int. add_state_info Tell FreqAI to include state information in the feature set for training and inferencing. The current state variables include trade duration, current profit, trade position. This is only available in dry/live runs, and is automatically switched to false for backtesting. Datatype: bool. Default: False. net_arch Network architecture which is well described in stable_baselines3 doc. In summary: [<shared layers>, dict(vf=[<non-shared value network layers>], pi=[<non-shared policy network layers>])]. By default this is set to [128, 128], which defines 2 shared hidden layers with 128 units each. randomize_starting_position Randomize the starting point of each episode to avoid overfitting. Datatype: bool. Default: False. drop_ohlc_from_features Do not include the normalized ohlc data in the feature set passed to the agent during training (ohlc will still be used for driving the environment in all cases) Datatype: Boolean. Default: False progress_bar Display a progress bar with the current progress, elapsed time and estimated remaining time. Datatype: Boolean. Default: False."},{"location":"freqai-parameter-table/#pytorch-parameters","title":"PyTorch parameters","text":""},{"location":"freqai-parameter-table/#general","title":"general","text":"Parameter Description Model training parameters within the freqai.model_training_parameters sub dictionary learning_rate Learning rate to be passed to the optimizer. Datatype: float. Default: 3e-4. model_kwargs Parameters to be passed to the model class. Datatype: dict. Default: {}. trainer_kwargs Parameters to be passed to the trainer class. Datatype: dict. Default: {}."},{"location":"freqai-parameter-table/#trainer_kwargs","title":"trainer_kwargs","text":"Parameter Description Model training parameters within the freqai.model_training_parameters.model_kwargs sub dictionary n_epochs The n_epochs parameter is a crucial setting in the PyTorch training loop that determines the number of times the entire training dataset will be used to update the model's parameters. An epoch represents one full pass through the entire training dataset. Overrides n_steps. Either n_epochs or n_steps must be set. Datatype: int. optional. Default: 10. n_steps An alternative way of setting n_epochs - the number of training iterations to run. Iteration here refer to the number of times we call optimizer.step(). Ignored if n_epochs is set. A simplified version of the function: n_epochs = n_steps / (n_obs / batch_size) The motivation here is that n_steps is easier to optimize and keep stable across different n_obs - the number of data points. Datatype: int. optional. Default: None. batch_size The size of the batches to use during training. Datatype: int. Default: 64."},{"location":"freqai-parameter-table/#additional-parameters","title":"Additional parameters","text":"Parameter Description Extraneous parameters freqai.keras If the selected model makes use of Keras (typical for TensorFlow-based prediction models), this flag needs to be activated so that the model save/loading follows Keras standards. Datatype: Boolean. Default: False. freqai.conv_width The width of a neural network input tensor. This replaces the need for shifting candles (include_shifted_candles) by feeding in historical data points as the second dimension of the tensor. Technically, this parameter can also be used for regressors, but it only adds computational overhead and does not change the model training/prediction. Datatype: Integer. Default: 2. freqai.reduce_df_footprint Recast all numeric columns to float32/int32, with the objective of reducing ram/disk usage and decreasing train/inference timing. This parameter is set in the main level of the Freqtrade configuration file (not inside FreqAI). Datatype: Boolean. Default: False."},{"location":"freqai-reinforcement-learning/","title":"Reinforcement Learning","text":"

    Installation size

    Reinforcement learning dependencies include large packages such as torch, which should be explicitly requested during ./setup.sh -i by answering \"y\" to the question \"Do you also want dependencies for freqai-rl (~700mb additional space required) [y/N]?\". Users who prefer docker should ensure they use the docker image appended with _freqairl.

    "},{"location":"freqai-reinforcement-learning/#background-and-terminology","title":"Background and terminology","text":""},{"location":"freqai-reinforcement-learning/#what-is-rl-and-why-does-freqai-need-it","title":"What is RL and why does FreqAI need it?","text":"

    Reinforcement learning involves two important components, the agent and the training environment. During agent training, the agent moves through historical data candle by candle, always making 1 of a set of actions: Long entry, long exit, short entry, short exit, neutral). During this training process, the environment tracks the performance of these actions and rewards the agent according to a custom user made calculate_reward() (here we offer a default reward for users to build on if they wish details here). The reward is used to train weights in a neural network.

    A second important component of the FreqAI RL implementation is the use of state information. State information is fed into the network at each step, including current profit, current position, and current trade duration. These are used to train the agent in the training environment, and to reinforce the agent in dry/live (this functionality is not available in backtesting). FreqAI + Freqtrade is a perfect match for this reinforcing mechanism since this information is readily available in live deployments.

    Reinforcement learning is a natural progression for FreqAI, since it adds a new layer of adaptivity and market reactivity that Classifiers and Regressors cannot match. However, Classifiers and Regressors have strengths that RL does not have such as robust predictions. Improperly trained RL agents may find \"cheats\" and \"tricks\" to maximize reward without actually winning any trades. For this reason, RL is more complex and demands a higher level of understanding than typical Classifiers and Regressors.

    "},{"location":"freqai-reinforcement-learning/#the-rl-interface","title":"The RL interface","text":"

    With the current framework, we aim to expose the training environment via the common \"prediction model\" file, which is a user inherited BaseReinforcementLearner object (e.g. freqai/prediction_models/ReinforcementLearner). Inside this user class, the RL environment is available and customized via MyRLEnv as shown below.

    We envision the majority of users focusing their effort on creative design of the calculate_reward() function details here, while leaving the rest of the environment untouched. Other users may not touch the environment at all, and they will only play with the configuration settings and the powerful feature engineering that already exists in FreqAI. Meanwhile, we enable advanced users to create their own model classes entirely.

    The framework is built on stable_baselines3 (torch) and OpenAI gym for the base environment class. But generally speaking, the model class is well isolated. Thus, the addition of competing libraries can be easily integrated into the existing framework. For the environment, it is inheriting from gym.Env which means that it is necessary to write an entirely new environment in order to switch to a different library.

    "},{"location":"freqai-reinforcement-learning/#important-considerations","title":"Important considerations","text":"

    As explained above, the agent is \"trained\" in an artificial trading \"environment\". In our case, that environment may seem quite similar to a real Freqtrade backtesting environment, but it is NOT. In fact, the RL training environment is much more simplified. It does not incorporate any of the complicated strategy logic, such as callbacks like custom_exit, custom_stoploss, leverage controls, etc. The RL environment is instead a very \"raw\" representation of the true market, where the agent has free will to learn the policy (read: stoploss, take profit, etc.) which is enforced by the calculate_reward(). Thus, it is important to consider that the agent training environment is not identical to the real world.

    "},{"location":"freqai-reinforcement-learning/#running-reinforcement-learning","title":"Running Reinforcement Learning","text":"

    Setting up and running a Reinforcement Learning model is the same as running a Regressor or Classifier. The same two flags, --freqaimodel and --strategy, must be defined on the command line:

    freqtrade trade --freqaimodel ReinforcementLearner --strategy MyRLStrategy --config config.json\n

    where ReinforcementLearner will use the templated ReinforcementLearner from freqai/prediction_models/ReinforcementLearner (or a custom user defined one located in user_data/freqaimodels). The strategy, on the other hand, follows the same base feature engineering with feature_engineering_* as a typical Regressor. The difference lies in the creation of the targets, Reinforcement Learning doesn't require them. However, FreqAI requires a default (neutral) value to be set in the action column:

        def set_freqai_targets(self, dataframe, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        More details about feature engineering available:\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering\n\n        :param df: strategy dataframe which will receive the targets\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        # For RL, there are no direct targets to set. This is filler (neutral)\n        # until the agent sends an action.\n        dataframe[\"&-action\"] = 0\n        return dataframe\n

    Most of the function remains the same as for typical Regressors, however, the function below shows how the strategy must pass the raw price data to the agent so that it has access to raw OHLCV in the training environment:

        def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        # The following features are necessary for RL models\n        dataframe[f\"%-raw_close\"] = dataframe[\"close\"]\n        dataframe[f\"%-raw_open\"] = dataframe[\"open\"]\n        dataframe[f\"%-raw_high\"] = dataframe[\"high\"]\n        dataframe[f\"%-raw_low\"] = dataframe[\"low\"]\n    return dataframe\n

    Finally, there is no explicit \"label\" to make - instead it is necessary to assign the &-action column which will contain the agent's actions when accessed in populate_entry/exit_trends(). In the present example, the neutral action to 0. This value should align with the environment used. FreqAI provides two environments, both use 0 as the neutral action.

    After users realize there are no labels to set, they will soon understand that the agent is making its \"own\" entry and exit decisions. This makes strategy construction rather simple. The entry and exit signals come from the agent in the form of an integer - which are used directly to decide entries and exits in the strategy:

        def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:\n\n        enter_long_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 1]\n\n        if enter_long_conditions:\n            df.loc[\n                reduce(lambda x, y: x & y, enter_long_conditions), [\"enter_long\", \"enter_tag\"]\n            ] = (1, \"long\")\n\n        enter_short_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 3]\n\n        if enter_short_conditions:\n            df.loc[\n                reduce(lambda x, y: x & y, enter_short_conditions), [\"enter_short\", \"enter_tag\"]\n            ] = (1, \"short\")\n\n        return df\n\n    def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:\n        exit_long_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 2]\n        if exit_long_conditions:\n            df.loc[reduce(lambda x, y: x & y, exit_long_conditions), \"exit_long\"] = 1\n\n        exit_short_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 4]\n        if exit_short_conditions:\n            df.loc[reduce(lambda x, y: x & y, exit_short_conditions), \"exit_short\"] = 1\n\n        return df\n

    It is important to consider that &-action depends on which environment they choose to use. The example above shows 5 actions, where 0 is neutral, 1 is enter long, 2 is exit long, 3 is enter short and 4 is exit short.

    "},{"location":"freqai-reinforcement-learning/#configuring-the-reinforcement-learner","title":"Configuring the Reinforcement Learner","text":"

    In order to configure the Reinforcement Learner the following dictionary must exist in the freqai config:

            \"rl_config\": {\n            \"train_cycles\": 25,\n            \"add_state_info\": true,\n            \"max_trade_duration_candles\": 300,\n            \"max_training_drawdown_pct\": 0.02,\n            \"cpu_count\": 8,\n            \"model_type\": \"PPO\",\n            \"policy_type\": \"MlpPolicy\",\n            \"model_reward_parameters\": {\n                \"rr\": 1,\n                \"profit_aim\": 0.025\n            }\n        }\n

    Parameter details can be found here, but in general the train_cycles decides how many times the agent should cycle through the candle data in its artificial environment to train weights in the model. model_type is a string which selects one of the available models in stable_baselines(external link).

    Note

    If you would like to experiment with continual_learning, then you should set that value to true in the main freqai configuration dictionary. This will tell the Reinforcement Learning library to continue training new models from the final state of previous models, instead of retraining new models from scratch each time a retrain is initiated.

    Note

    Remember that the general model_training_parameters dictionary should contain all the model hyperparameter customizations for the particular model_type. For example, PPO parameters can be found here.

    "},{"location":"freqai-reinforcement-learning/#creating-a-custom-reward-function","title":"Creating a custom reward function","text":"

    Not for production

    Warning! The reward function provided with the Freqtrade source code is a showcase of functionality designed to show/test as many possible environment control features as possible. It is also designed to run quickly on small computers. This is a benchmark, it is not for live production. Please beware that you will need to create your own custom_reward() function or use a template built by other users outside of the Freqtrade source code.

    As you begin to modify the strategy and the prediction model, you will quickly realize some important differences between the Reinforcement Learner and the Regressors/Classifiers. Firstly, the strategy does not set a target value (no labels!). Instead, you set the calculate_reward() function inside the MyRLEnv class (see below). A default calculate_reward() is provided inside prediction_models/ReinforcementLearner.py to demonstrate the necessary building blocks for creating rewards, but this is not designed for production. Users must create their own custom reinforcement learning model class or use a pre-built one from outside the Freqtrade source code and save it to user_data/freqaimodels. It is inside the calculate_reward() where creative theories about the market can be expressed. For example, you can reward your agent when it makes a winning trade, and penalize the agent when it makes a losing trade. Or perhaps, you wish to reward the agent for entering trades, and penalize the agent for sitting in trades too long. Below we show examples of how these rewards are all calculated:

    Hint

    The best reward functions are ones that are continuously differentiable, and well scaled. In other words, adding a single large negative penalty to a rare event is not a good idea, and the neural net will not be able to learn that function. Instead, it is better to add a small negative penalty to a common event. This will help the agent learn faster. Not only this, but you can help improve the continuity of your rewards/penalties by having them scale with severity according to some linear/exponential functions. In other words, you'd slowly scale the penalty as the duration of the trade increases. This is better than a single large penalty occurring at a single point in time.

    from freqtrade.freqai.prediction_models.ReinforcementLearner import ReinforcementLearner\nfrom freqtrade.freqai.RL.Base5ActionRLEnv import Actions, Base5ActionRLEnv, Positions\n\n\nclass MyCoolRLModel(ReinforcementLearner):\n    \"\"\"\n    User created RL prediction model.\n\n    Save this file to `freqtrade/user_data/freqaimodels`\n\n    then use it with:\n\n    freqtrade trade --freqaimodel MyCoolRLModel --config config.json --strategy SomeCoolStrat\n\n    Here the users can override any of the functions\n    available in the `IFreqaiModel` inheritance tree. Most importantly for RL, this\n    is where the user overrides `MyRLEnv` (see below), to define custom\n    `calculate_reward()` function, or to override any other parts of the environment.\n\n    This class also allows users to override any other part of the IFreqaiModel tree.\n    For example, the user can override `def fit()` or `def train()` or `def predict()`\n    to take fine-tuned control over these processes.\n\n    Another common override may be `def data_cleaning_predict()` where the user can\n    take fine-tuned control over the data handling pipeline.\n    \"\"\"\n    class MyRLEnv(Base5ActionRLEnv):\n        \"\"\"\n        User made custom environment. This class inherits from BaseEnvironment and gym.Env.\n        Users can override any functions from those parent classes. Here is an example\n        of a user customized `calculate_reward()` function.\n\n        Warning!\n        This is function is a showcase of functionality designed to show as many possible\n        environment control features as possible. It is also designed to run quickly\n        on small computers. This is a benchmark, it is *not* for live production.\n        \"\"\"\n        def calculate_reward(self, action: int) -> float:\n            # first, penalize if the action is not valid\n            if not self._is_valid(action):\n                return -2\n            pnl = self.get_unrealized_profit()\n\n            factor = 100\n\n            pair = self.pair.replace(':', '')\n\n            # you can use feature values from dataframe\n            # Assumes the shifted RSI indicator has been generated in the strategy.\n            rsi_now = self.raw_features[f\"%-rsi-period_10_shift-1_{pair}_\"\n                            f\"{self.config['timeframe']}\"].iloc[self._current_tick]\n\n            # reward agent for entering trades\n            if (action in (Actions.Long_enter.value, Actions.Short_enter.value)\n                    and self._position == Positions.Neutral):\n                if rsi_now < 40:\n                    factor = 40 / rsi_now\n                else:\n                    factor = 1\n                return 25 * factor\n\n            # discourage agent from not entering trades\n            if action == Actions.Neutral.value and self._position == Positions.Neutral:\n                return -1\n            max_trade_duration = self.rl_config.get('max_trade_duration_candles', 300)\n            trade_duration = self._current_tick - self._last_trade_tick\n            if trade_duration <= max_trade_duration:\n                factor *= 1.5\n            elif trade_duration > max_trade_duration:\n                factor *= 0.5\n            # discourage sitting in position\n            if self._position in (Positions.Short, Positions.Long) and \\\n            action == Actions.Neutral.value:\n                return -1 * trade_duration / max_trade_duration\n            # close long\n            if action == Actions.Long_exit.value and self._position == Positions.Long:\n                if pnl > self.profit_aim * self.rr:\n                    factor *= self.rl_config['model_reward_parameters'].get('win_reward_factor', 2)\n                return float(pnl * factor)\n            # close short\n            if action == Actions.Short_exit.value and self._position == Positions.Short:\n                if pnl > self.profit_aim * self.rr:\n                    factor *= self.rl_config['model_reward_parameters'].get('win_reward_factor', 2)\n                return float(pnl * factor)\n            return 0.\n
    "},{"location":"freqai-reinforcement-learning/#using-tensorboard","title":"Using Tensorboard","text":"

    Reinforcement Learning models benefit from tracking training metrics. FreqAI has integrated Tensorboard to allow users to track training and evaluation performance across all coins and across all retrainings. Tensorboard is activated via the following command:

    tensorboard --logdir user_data/models/unique-id\n

    where unique-id is the identifier set in the freqai configuration file. This command must be run in a separate shell to view the output in the browser at 127.0.0.1:6006 (6006 is the default port used by Tensorboard).

    "},{"location":"freqai-reinforcement-learning/#custom-logging","title":"Custom logging","text":"

    FreqAI also provides a built in episodic summary logger called self.tensorboard_log for adding custom information to the Tensorboard log. By default, this function is already called once per step inside the environment to record the agent actions. All values accumulated for all steps in a single episode are reported at the conclusion of each episode, followed by a full reset of all metrics to 0 in preparation for the subsequent episode.

    self.tensorboard_log can also be used anywhere inside the environment, for example, it can be added to the calculate_reward function to collect more detailed information about how often various parts of the reward were called:

        class MyRLEnv(Base5ActionRLEnv):\n        \"\"\"\n        User made custom environment. This class inherits from BaseEnvironment and gym.Env.\n        Users can override any functions from those parent classes. Here is an example\n        of a user customized `calculate_reward()` function.\n        \"\"\"\n        def calculate_reward(self, action: int) -> float:\n            if not self._is_valid(action):\n                self.tensorboard_log(\"invalid\")\n                return -2\n

    Note

    The self.tensorboard_log() function is designed for tracking incremented objects only i.e. events, actions inside the training environment. If the event of interest is a float, the float can be passed as the second argument e.g. self.tensorboard_log(\"float_metric1\", 0.23). In this case the metric values are not incremented.

    "},{"location":"freqai-reinforcement-learning/#choosing-a-base-environment","title":"Choosing a base environment","text":"

    FreqAI provides three base environments, Base3ActionRLEnvironment, Base4ActionEnvironment and Base5ActionEnvironment. As the names imply, the environments are customized for agents that can select from 3, 4 or 5 actions. The Base3ActionEnvironment is the simplest, the agent can select from hold, long, or short. This environment can also be used for long-only bots (it automatically follows the can_short flag from the strategy), where long is the enter condition and short is the exit condition. Meanwhile, in the Base4ActionEnvironment, the agent can enter long, enter short, hold neutral, or exit position. Finally, in the Base5ActionEnvironment, the agent has the same actions as Base4, but instead of a single exit action, it separates exit long and exit short. The main changes stemming from the environment selection include:

    • the actions available in the calculate_reward
    • the actions consumed by the user strategy

    All of the FreqAI provided environments inherit from an action/position agnostic environment object called the BaseEnvironment, which contains all shared logic. The architecture is designed to be easily customized. The simplest customization is the calculate_reward() (see details here). However, the customizations can be further extended into any of the functions inside the environment. You can do this by simply overriding those functions inside your MyRLEnv in the prediction model file. Or for more advanced customizations, it is encouraged to create an entirely new environment inherited from BaseEnvironment.

    Note

    Only the Base3ActionRLEnv can do long-only training/trading (set the user strategy attribute can_short = False).

    "},{"location":"freqai-running/","title":"Running FreqAI","text":"

    There are two ways to train and deploy an adaptive machine learning model - live deployment and historical backtesting. In both cases, FreqAI runs/simulates periodic retraining of models as shown in the following figure:

    "},{"location":"freqai-running/#live-deployments","title":"Live deployments","text":"

    FreqAI can be run dry/live using the following command:

    freqtrade trade --strategy FreqaiExampleStrategy --config config_freqai.example.json --freqaimodel LightGBMRegressor\n

    When launched, FreqAI will start training a new model, with a new identifier, based on the config settings. Following training, the model will be used to make predictions on incoming candles until a new model is available. New models are typically generated as often as possible, with FreqAI managing an internal queue of the coin pairs to try to keep all models equally up to date. FreqAI will always use the most recently trained model to make predictions on incoming live data. If you do not want FreqAI to retrain new models as often as possible, you can set live_retrain_hours to tell FreqAI to wait at least that number of hours before training a new model. Additionally, you can set expired_hours to tell FreqAI to avoid making predictions on models that are older than that number of hours.

    Trained models are by default saved to disk to allow for reuse during backtesting or after a crash. You can opt to purge old models to save disk space by setting \"purge_old_models\": true in the config.

    To start a dry/live run from a saved backtest model (or from a previously crashed dry/live session), you only need to specify the identifier of the specific model:

        \"freqai\": {\n        \"identifier\": \"example\",\n        \"live_retrain_hours\": 0.5\n    }\n

    In this case, although FreqAI will initiate with a pre-trained model, it will still check to see how much time has elapsed since the model was trained. If a full live_retrain_hours has elapsed since the end of the loaded model, FreqAI will start training a new model.

    "},{"location":"freqai-running/#automatic-data-download","title":"Automatic data download","text":"

    FreqAI automatically downloads the proper amount of data needed to ensure training of a model through the defined train_period_days and startup_candle_count (see the parameter table for detailed descriptions of these parameters).

    "},{"location":"freqai-running/#saving-prediction-data","title":"Saving prediction data","text":"

    All predictions made during the lifetime of a specific identifier model are stored in historic_predictions.pkl to allow for reloading after a crash or changes made to the config.

    "},{"location":"freqai-running/#purging-old-model-data","title":"Purging old model data","text":"

    FreqAI stores new model files after each successful training. These files become obsolete as new models are generated to adapt to new market conditions. If you are planning to leave FreqAI running for extended periods of time with high frequency retraining, you should enable purge_old_models in the config:

        \"freqai\": {\n        \"purge_old_models\": 4,\n    }\n

    This will automatically purge all models older than the four most recently trained ones to save disk space. Inputing \"0\" will never purge any models.

    "},{"location":"freqai-running/#backtesting","title":"Backtesting","text":"

    The FreqAI backtesting module can be executed with the following command:

    freqtrade backtesting --strategy FreqaiExampleStrategy --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --freqaimodel LightGBMRegressor --timerange 20210501-20210701\n

    If this command has never been executed with the existing config file, FreqAI will train a new model for each pair, for each backtesting window within the expanded --timerange.

    Backtesting mode requires downloading the necessary data before deployment (unlike in dry/live mode where FreqAI handles the data downloading automatically). You should be careful to consider that the time range of the downloaded data is more than the backtesting time range. This is because FreqAI needs data prior to the desired backtesting time range in order to train a model to be ready to make predictions on the first candle of the set backtesting time range. More details on how to calculate the data to download can be found here.

    Model reuse

    Once the training is completed, you can execute the backtesting again with the same config file and FreqAI will find the trained models and load them instead of spending time training. This is useful if you want to tweak (or even hyperopt) buy and sell criteria inside the strategy. If you want to retrain a new model with the same config file, you should simply change the identifier. This way, you can return to using any model you wish by simply specifying the identifier.

    Note

    Backtesting calls set_freqai_targets() one time for each backtest window (where the number of windows is the full backtest timerange divided by the backtest_period_days parameter). Doing this means that the targets simulate dry/live behavior without look ahead bias. However, the definition of the features in feature_engineering_*() is performed once on the entire training timerange. This means that you should be sure that features do not look-ahead into the future. More details about look-ahead bias can be found in Common Mistakes.

    "},{"location":"freqai-running/#saving-backtesting-prediction-data","title":"Saving backtesting prediction data","text":"

    To allow for tweaking your strategy (not the features!), FreqAI will automatically save the predictions during backtesting so that they can be reused for future backtests and live runs using the same identifier model. This provides a performance enhancement geared towards enabling high-level hyperopting of entry/exit criteria.

    An additional directory called backtesting_predictions, which contains all the predictions stored in feather format, will be created in the unique-id folder.

    To change your features, you must set a new identifier in the config to signal to FreqAI to train new models.

    To save the models generated during a particular backtest so that you can start a live deployment from one of them instead of training a new model, you must set save_backtest_models to True in the config.

    Note

    To ensure that the model can be reused, freqAI will call your strategy with a dataframe of length 1. If your strategy requires more data than this to generate the same features, you can't reuse backtest predictions for live deployment and need to update your identifier for each new backtest.

    "},{"location":"freqai-running/#backtest-live-collected-predictions","title":"Backtest live collected predictions","text":"

    FreqAI allow you to reuse live historic predictions through the backtest parameter --freqai-backtest-live-models. This can be useful when you want to reuse predictions generated in dry/run for comparison or other study.

    The --timerange parameter must not be informed, as it will be automatically calculated through the data in the historic predictions file.

    "},{"location":"freqai-running/#downloading-data-to-cover-the-full-backtest-period","title":"Downloading data to cover the full backtest period","text":"

    For live/dry deployments, FreqAI will download the necessary data automatically. However, to use backtesting functionality, you need to download the necessary data using download-data (details here). You need to pay careful attention to understanding how much additional data needs to be downloaded to ensure that there is a sufficient amount of training data before the start of the backtesting time range. The amount of additional data can be roughly estimated by moving the start date of the time range backwards by train_period_days and the startup_candle_count (see the parameter table for detailed descriptions of these parameters) from the beginning of the desired backtesting time range.

    As an example, to backtest the --timerange 20210501-20210701 using the example config which sets train_period_days to 30, together with startup_candle_count: 40 on a maximum include_timeframes of 1h, the start date for the downloaded data needs to be 20210501 - 30 days - 40 * 1h / 24 hours = 20210330 (31.7 days earlier than the start of the desired training time range).

    "},{"location":"freqai-running/#deciding-the-size-of-the-sliding-training-window-and-backtesting-duration","title":"Deciding the size of the sliding training window and backtesting duration","text":"

    The backtesting time range is defined with the typical --timerange parameter in the configuration file. The duration of the sliding training window is set by train_period_days, whilst backtest_period_days is the sliding backtesting window, both in number of days (backtest_period_days can be a float to indicate sub-daily retraining in live/dry mode). In the presented example config (found in config_examples/config_freqai.example.json), the user is asking FreqAI to use a training period of 30 days and backtest on the subsequent 7 days. After the training of the model, FreqAI will backtest the subsequent 7 days. The \"sliding window\" then moves one week forward (emulating FreqAI retraining once per week in live mode) and the new model uses the previous 30 days (including the 7 days used for backtesting by the previous model) to train. This is repeated until the end of --timerange. This means that if you set --timerange 20210501-20210701, FreqAI will have trained 8 separate models at the end of --timerange (because the full range comprises 8 weeks).

    Note

    Although fractional backtest_period_days is allowed, you should be aware that the --timerange is divided by this value to determine the number of models that FreqAI will need to train in order to backtest the full range. For example, by setting a --timerange of 10 days, and a backtest_period_days of 0.1, FreqAI will need to train 100 models per pair to complete the full backtest. Because of this, a true backtest of FreqAI adaptive training would take a very long time. The best way to fully test a model is to run it dry and let it train constantly. In this case, backtesting would take the exact same amount of time as a dry run.

    "},{"location":"freqai-running/#defining-model-expirations","title":"Defining model expirations","text":"

    During dry/live mode, FreqAI trains each coin pair sequentially (on separate threads/GPU from the main Freqtrade bot). This means that there is always an age discrepancy between models. If you are training on 50 pairs, and each pair requires 5 minutes to train, the oldest model will be over 4 hours old. This may be undesirable if the characteristic time scale (the trade duration target) for a strategy is less than 4 hours. You can decide to only make trade entries if the model is less than a certain number of hours old by setting the expiration_hours in the config file:

        \"freqai\": {\n        \"expiration_hours\": 0.5,\n    }\n

    In the presented example config, the user will only allow predictions on models that are less than \u00bd hours old.

    "},{"location":"freqai-running/#controlling-the-model-learning-process","title":"Controlling the model learning process","text":"

    Model training parameters are unique to the selected machine learning library. FreqAI allows you to set any parameter for any library using the model_training_parameters dictionary in the config. The example config (found in config_examples/config_freqai.example.json) shows some of the example parameters associated with Catboost and LightGBM, but you can add any parameters available in those libraries or any other machine learning library you choose to implement.

    Data split parameters are defined in data_split_parameters which can be any parameters associated with scikit-learn's train_test_split() function. train_test_split() has a parameters called shuffle which allows to shuffle the data or keep it unshuffled. This is particularly useful to avoid biasing training with temporally auto-correlated data. More details about these parameters can be found the scikit-learn website (external website).

    The FreqAI specific parameter label_period_candles defines the offset (number of candles into the future) used for the labels. In the presented example config, the user is asking for labels that are 24 candles in the future.

    "},{"location":"freqai-running/#continual-learning","title":"Continual learning","text":"

    You can choose to adopt a continual learning scheme by setting \"continual_learning\": true in the config. By enabling continual_learning, after training an initial model from scratch, subsequent trainings will start from the final model state of the preceding training. This gives the new model a \"memory\" of the previous state. By default, this is set to False which means that all new models are trained from scratch, without input from previous models.

    Continual learning enforces a constant parameter space

    Since continual_learning means that the model parameter space cannot change between trainings, principal_component_analysis is automatically disabled when continual_learning is enabled. Hint: PCA changes the parameter space and the number of features, learn more about PCA here.

    Experimental functionality

    Beware that this is currently a naive approach to incremental learning, and it has a high probability of overfitting/getting stuck in local minima while the market moves away from your model. We have the mechanics available in FreqAI primarily for experimental purposes and so that it is ready for more mature approaches to continual learning in chaotic systems like the crypto market.

    "},{"location":"freqai-running/#hyperopt","title":"Hyperopt","text":"

    You can hyperopt using the same command as for typical Freqtrade hyperopt:

    freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --timerange 20220428-20220507\n

    hyperopt requires you to have the data pre-downloaded in the same fashion as if you were doing backtesting. In addition, you must consider some restrictions when trying to hyperopt FreqAI strategies:

    • The --analyze-per-epoch hyperopt parameter is not compatible with FreqAI.
    • It's not possible to hyperopt indicators in the feature_engineering_*() and set_freqai_targets() functions. This means that you cannot optimize model parameters using hyperopt. Apart from this exception, it is possible to optimize all other spaces.
    • The backtesting instructions also apply to hyperopt.

    The best method for combining hyperopt and FreqAI is to focus on hyperopting entry/exit thresholds/criteria. You need to focus on hyperopting parameters that are not used in your features. For example, you should not try to hyperopt rolling window lengths in the feature creation, or any part of the FreqAI config which changes predictions. In order to efficiently hyperopt the FreqAI strategy, FreqAI stores predictions as dataframes and reuses them. Hence the requirement to hyperopt entry/exit thresholds/criteria only.

    A good example of a hyperoptable parameter in FreqAI is a threshold for the Dissimilarity Index (DI) DI_values beyond which we consider data points as outliers:

    di_max = IntParameter(low=1, high=20, default=10, space='buy', optimize=True, load=True)\ndataframe['outlier'] = np.where(dataframe['DI_values'] > self.di_max.value/10, 1, 0)\n

    This specific hyperopt would help you understand the appropriate DI_values for your particular parameter space.

    "},{"location":"freqai-running/#using-tensorboard","title":"Using Tensorboard","text":"

    Availability

    FreqAI includes tensorboard for a variety of models, including XGBoost, all PyTorch models, Reinforcement Learning, and Catboost. If you would like to see Tensorboard integrated into another model type, please open an issue on the Freqtrade GitHub

    Requirements

    Tensorboard logging requires the FreqAI torch installation/docker image.

    The easiest way to use tensorboard is to ensure freqai.activate_tensorboard is set to True (default setting) in your configuration file, run FreqAI, then open a separate shell and run:

    cd freqtrade\ntensorboard --logdir user_data/models/unique-id\n

    where unique-id is the identifier set in the freqai configuration file. This command must be run in a separate shell if you wish to view the output in your browser at 127.0.0.1:6060 (6060 is the default port used by Tensorboard).

    Deactivate for improved performance

    Tensorboard logging can slow down training and should be deactivated for production use.

    "},{"location":"freqai/","title":"Introduction","text":""},{"location":"freqai/#freqai","title":"FreqAI","text":""},{"location":"freqai/#introduction","title":"Introduction","text":"

    FreqAI is a software designed to automate a variety of tasks associated with training a predictive machine learning model to generate market forecasts given a set of input signals. In general, FreqAI aims to be a sandbox for easily deploying robust machine learning libraries on real-time data (details).

    Note

    FreqAI is, and always will be, a not-for-profit, open-source project. FreqAI does not have a crypto token, FreqAI does not sell signals, and FreqAI does not have a domain besides the present freqtrade documentation.

    Features include:

    • Self-adaptive retraining - Retrain models during live deployments to self-adapt to the market in a supervised manner
    • Rapid feature engineering - Create large rich feature sets (10k+ features) based on simple user-created strategies
    • High performance - Threading allows for adaptive model retraining on a separate thread (or on GPU if available) from model inferencing (prediction) and bot trade operations. Newest models and data are kept in RAM for rapid inferencing
    • Realistic backtesting - Emulate self-adaptive training on historic data with a backtesting module that automates retraining
    • Extensibility - The generalized and robust architecture allows for incorporating any machine learning library/method available in Python. Eight examples are currently available, including classifiers, regressors, and a convolutional neural network
    • Smart outlier removal - Remove outliers from training and prediction data sets using a variety of outlier detection techniques
    • Crash resilience - Store trained models to disk to make reloading from a crash fast and easy, and purge obsolete files for sustained dry/live runs
    • Automatic data normalization - Normalize the data in a smart and statistically safe way
    • Automatic data download - Compute timeranges for data downloads and update historic data (in live deployments)
    • Cleaning of incoming data - Handle NaNs safely before training and model inferencing
    • Dimensionality reduction - Reduce the size of the training data via Principal Component Analysis
    • Deploying bot fleets - Set one bot to train models while a fleet of consumers use signals.
    "},{"location":"freqai/#quick-start","title":"Quick start","text":"

    The easiest way to quickly test FreqAI is to run it in dry mode with the following command:

    freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates\n

    You will see the boot-up process of automatic data downloading, followed by simultaneous training and trading.

    Not for production

    The example strategy provided with the Freqtrade source code is designed for showcasing/testing a wide variety of FreqAI features. It is also designed to run on small computers so that it can be used as a benchmark between developers and users. It is not designed to be run in production.

    An example strategy, prediction model, and config to use as a starting points can be found in freqtrade/templates/FreqaiExampleStrategy.py, freqtrade/freqai/prediction_models/LightGBMRegressor.py, and config_examples/config_freqai.example.json, respectively.

    "},{"location":"freqai/#general-approach","title":"General approach","text":"

    You provide FreqAI with a set of custom base indicators (the same way as in a typical Freqtrade strategy) as well as target values (labels). For each pair in the whitelist, FreqAI trains a model to predict the target values based on the input of custom indicators. The models are then consistently retrained, with a predetermined frequency, to adapt to market conditions. FreqAI offers the ability to both backtest strategies (emulating reality with periodic retraining on historic data) and deploy dry/live runs. In dry/live conditions, FreqAI can be set to constant retraining in a background thread to keep models as up to date as possible.

    An overview of the algorithm, explaining the data processing pipeline and model usage, is shown below.

    "},{"location":"freqai/#important-machine-learning-vocabulary","title":"Important machine learning vocabulary","text":"

    Features - the parameters, based on historic data, on which a model is trained. All features for a single candle are stored as a vector. In FreqAI, you build a feature data set from anything you can construct in the strategy.

    Labels - the target values that the model is trained toward. Each feature vector is associated with a single label that is defined by you within the strategy. These labels intentionally look into the future and are what you are training the model to be able to predict.

    Training - the process of \"teaching\" the model to match the feature sets to the associated labels. Different types of models \"learn\" in different ways which means that one might be better than another for a specific application. More information about the different models that are already implemented in FreqAI can be found here.

    Train data - a subset of the feature data set that is fed to the model during training to \"teach\" the model how to predict the targets. This data directly influences weight connections in the model.

    Test data - a subset of the feature data set that is used to evaluate the performance of the model after training. This data does not influence nodal weights within the model.

    Inferencing - the process of feeding a trained model new unseen data on which it will make a prediction.

    "},{"location":"freqai/#install-prerequisites","title":"Install prerequisites","text":"

    The normal Freqtrade install process will ask if you wish to install FreqAI dependencies. You should reply \"yes\" to this question if you wish to use FreqAI. If you did not reply yes, you can manually install these dependencies after the install with:

    pip install -r requirements-freqai.txt\n

    Note

    Catboost will not be installed on low-powered arm devices (raspberry), since it does not provide wheels for this platform.

    "},{"location":"freqai/#usage-with-docker","title":"Usage with docker","text":"

    If you are using docker, a dedicated tag with FreqAI dependencies is available as :freqai. As such - you can replace the image line in your docker compose file with image: freqtradeorg/freqtrade:develop_freqai. This image contains the regular FreqAI dependencies. Similar to native installs, Catboost will not be available on ARM based devices. If you would like to use PyTorch or Reinforcement learning, you should use the torch or RL tags, image: freqtradeorg/freqtrade:develop_freqaitorch, image: freqtradeorg/freqtrade:develop_freqairl.

    docker-compose-freqai.yml

    We do provide an explicit docker-compose file for this in docker/docker-compose-freqai.yml - which can be used via docker compose -f docker/docker-compose-freqai.yml run ... - or can be copied to replace the original docker file. This docker-compose file also contains a (disabled) section to enable GPU resources within docker containers. This obviously assumes the system has GPU resources available.

    "},{"location":"freqai/#freqai-position-in-open-source-machine-learning-landscape","title":"FreqAI position in open-source machine learning landscape","text":"

    Forecasting chaotic time-series based systems, such as equity/cryptocurrency markets, requires a broad set of tools geared toward testing a wide range of hypotheses. Fortunately, a recent maturation of robust machine learning libraries (e.g. scikit-learn) has opened up a wide range of research possibilities. Scientists from a diverse range of fields can now easily prototype their studies on an abundance of established machine learning algorithms. Similarly, these user-friendly libraries enable \"citzen scientists\" to use their basic Python skills for data exploration. However, leveraging these machine learning libraries on historical and live chaotic data sources can be logistically difficult and expensive. Additionally, robust data collection, storage, and handling presents a disparate challenge. FreqAI aims to provide a generalized and extensible open-sourced framework geared toward live deployments of adaptive modeling for market forecasting. The FreqAI framework is effectively a sandbox for the rich world of open-source machine learning libraries. Inside the FreqAI sandbox, users find they can combine a wide variety of third-party libraries to test creative hypotheses on a free live 24/7 chaotic data source - cryptocurrency exchange data.

    "},{"location":"freqai/#citing-freqai","title":"Citing FreqAI","text":"

    FreqAI is published in the Journal of Open Source Software. If you find FreqAI useful in your research, please use the following citation:

    @article{Caulk2022, \n    doi = {10.21105/joss.04864},\n    url = {https://doi.org/10.21105/joss.04864},\n    year = {2022}, publisher = {The Open Journal},\n    volume = {7}, number = {80}, pages = {4864},\n    author = {Robert A. Caulk and Elin T\u00f6rnquist and Matthias Voppichler and Andrew R. Lawless and Ryan McMullan and Wagner Costa Santos and Timothy C. Pogue and Johan van der Vlugt and Stefan P. Gehring and Pascal Schmidt},\n    title = {FreqAI: generalizing adaptive modeling for chaotic time-series market forecasts},\n    journal = {Journal of Open Source Software} } \n
    "},{"location":"freqai/#common-pitfalls","title":"Common pitfalls","text":"

    FreqAI cannot be combined with dynamic VolumePairlists (or any pairlist filter that adds and removes pairs dynamically). This is for performance reasons - FreqAI relies on making quick predictions/retrains. To do this effectively, it needs to download all the training data at the beginning of a dry/live instance. FreqAI stores and appends new candles automatically for future retrains. This means that if new pairs arrive later in the dry run due to a volume pairlist, it will not have the data ready. However, FreqAI does work with the ShufflePairlist or a VolumePairlist which keeps the total pairlist constant (but reorders the pairs according to volume).

    "},{"location":"freqai/#additional-learning-materials","title":"Additional learning materials","text":"

    Here we compile some external materials that provide deeper looks into various components of FreqAI:

    • Real-time head-to-head: Adaptive modeling of financial market data using XGBoost and CatBoost
    • FreqAI - from price to prediction
    "},{"location":"freqai/#support","title":"Support","text":"

    You can find support for FreqAI in a variety of places, including the Freqtrade discord, the dedicated FreqAI discord, and in github issues.

    "},{"location":"freqai/#credits","title":"Credits","text":"

    FreqAI is developed by a group of individuals who all contribute specific skillsets to the project.

    Conception and software development: Robert Caulk @robcaulk

    Theoretical brainstorming and data analysis: Elin T\u00f6rnquist @th0rntwig

    Code review and software architecture brainstorming: @xmatthias

    Software development: Wagner Costa @wagnercosta Emre Suzen @aemr3 Timothy Pogue @wizrds

    Beta testing and bug reporting: Stefan Gehring @bloodhunter4rc, @longyu, Andrew Lawless @paranoidandy, Pascal Schmidt @smidelis, Ryan McMullan @smarmau, Juha Nyk\u00e4nen @suikula, Johan van der Vlugt @jooopiert, Rich\u00e1rd J\u00f3zsa @richardjosza

    "},{"location":"hyperopt/","title":"Hyperopt","text":"

    This page explains how to tune your strategy by finding the optimal parameters, a process called hyperparameter optimization. The bot uses algorithms included in the scikit-optimize package to accomplish this. The search will burn all your CPU cores, make your laptop sound like a fighter jet and still take a long time.

    In general, the search for best parameters starts with a few random combinations (see below for more details) and then uses Bayesian search with a ML regressor algorithm (currently ExtraTreesRegressor) to quickly find a combination of parameters in the search hyperspace that minimizes the value of the loss function.

    Hyperopt requires historic data to be available, just as backtesting does (hyperopt runs backtesting many times with different parameters). To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    Bug

    Hyperopt can crash when used with only 1 CPU Core as found out in Issue #1133

    Note

    Since 2021.4 release you no longer have to write a separate hyperopt class, but can configure the parameters directly in the strategy. The legacy method was supported up to 2021.8 and has been removed in 2021.9.

    "},{"location":"hyperopt/#install-hyperopt-dependencies","title":"Install hyperopt dependencies","text":"

    Since Hyperopt dependencies are not needed to run the bot itself, are heavy, can not be easily built on some platforms (like Raspberry PI), they are not installed by default. Before you run Hyperopt, you need to install the corresponding dependencies, as described in this section below.

    Note

    Since Hyperopt is a resource intensive process, running it on a Raspberry Pi is not recommended nor supported.

    "},{"location":"hyperopt/#docker","title":"Docker","text":"

    The docker-image includes hyperopt dependencies, no further action needed.

    "},{"location":"hyperopt/#easy-installation-script-setupsh-manual-installation","title":"Easy installation script (setup.sh) / Manual installation","text":"
    source .venv/bin/activate\npip install -r requirements-hyperopt.txt\n
    "},{"location":"hyperopt/#hyperopt-command-reference","title":"Hyperopt command reference","text":"
    usage: freqtrade hyperopt [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                          [--userdir PATH] [-s NAME] [--strategy-path PATH]\n                          [--recursive-strategy-search] [--freqaimodel NAME]\n                          [--freqaimodel-path PATH] [-i TIMEFRAME]\n                          [--timerange TIMERANGE]\n                          [--data-format-ohlcv {json,jsongz,hdf5}]\n                          [--max-open-trades INT]\n                          [--stake-amount STAKE_AMOUNT] [--fee FLOAT]\n                          [-p PAIRS [PAIRS ...]] [--hyperopt-path PATH]\n                          [--eps] [--dmmp] [--enable-protections]\n                          [--dry-run-wallet DRY_RUN_WALLET]\n                          [--timeframe-detail TIMEFRAME_DETAIL] [-e INT]\n                          [--spaces {all,buy,sell,roi,stoploss,trailing,protection,trades,default} [{all,buy,sell,roi,stoploss,trailing,protection,trades,default} ...]]\n                          [--print-all] [--no-color] [--print-json] [-j JOBS]\n                          [--random-state INT] [--min-trades INT]\n                          [--hyperopt-loss NAME] [--disable-param-export]\n                          [--ignore-missing-spaces] [--analyze-per-epoch]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --data-format-ohlcv {json,jsongz,hdf5}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `json`).\n  --max-open-trades INT\n                        Override the value of the `max_open_trades`\n                        configuration setting.\n  --stake-amount STAKE_AMOUNT\n                        Override the value of the `stake_amount` configuration\n                        setting.\n  --fee FLOAT           Specify fee ratio. Will be applied twice (on trade\n                        entry and exit).\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --hyperopt-path PATH  Specify additional lookup path for Hyperopt Loss\n                        functions.\n  --eps, --enable-position-stacking\n                        Allow buying the same pair multiple times (position\n                        stacking).\n  --dmmp, --disable-max-market-positions\n                        Disable applying `max_open_trades` during backtest\n                        (same as setting `max_open_trades` to a very high\n                        number).\n  --enable-protections, --enableprotections\n                        Enable protections for backtesting.Will slow\n                        backtesting down by a considerable amount, but will\n                        include configured protections\n  --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET\n                        Starting balance, used for backtesting / hyperopt and\n                        dry-runs.\n  --timeframe-detail TIMEFRAME_DETAIL\n                        Specify detail timeframe for backtesting (`1m`, `5m`,\n                        `30m`, `1h`, `1d`).\n  -e INT, --epochs INT  Specify number of epochs (default: 100).\n  --spaces {all,buy,sell,roi,stoploss,trailing,protection,trades,default} [{all,buy,sell,roi,stoploss,trailing,protection,trades,default} ...]\n                        Specify which parameters to hyperopt. Space-separated\n                        list.\n  --print-all           Print all results, not only the best ones.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n  --print-json          Print output in JSON format.\n  -j JOBS, --job-workers JOBS\n                        The number of concurrently running jobs for\n                        hyperoptimization (hyperopt worker processes). If -1\n                        (default), all CPUs are used, for -2, all CPUs but one\n                        are used, etc. If 1 is given, no parallel computing\n                        code is used at all.\n  --random-state INT    Set random state to some positive integer for\n                        reproducible hyperopt results.\n  --min-trades INT      Set minimal desired number of trades for evaluations\n                        in the hyperopt optimization path (default: 1).\n  --hyperopt-loss NAME, --hyperoptloss NAME\n                        Specify the class name of the hyperopt loss function\n                        class (IHyperOptLoss). Different functions can\n                        generate completely different results, since the\n                        target for optimization is different. Built-in\n                        Hyperopt-loss-functions are:\n                        ShortTradeDurHyperOptLoss, OnlyProfitHyperOptLoss,\n                        SharpeHyperOptLoss, SharpeHyperOptLossDaily,\n                        SortinoHyperOptLoss, SortinoHyperOptLossDaily,\n                        CalmarHyperOptLoss, MaxDrawDownHyperOptLoss,\n                        MaxDrawDownRelativeHyperOptLoss,\n                        ProfitDrawDownHyperOptLoss\n  --disable-param-export\n                        Disable automatic hyperopt parameter export.\n  --ignore-missing-spaces, --ignore-unparameterized-spaces\n                        Suppress errors for any requested Hyperopt spaces that\n                        do not contain any parameters.\n  --analyze-per-epoch   Run populate_indicators once per epoch.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n  --recursive-strategy-search\n                        Recursively search for a strategy in the strategies\n                        folder.\n  --freqaimodel NAME    Specify a custom freqaimodels.\n  --freqaimodel-path PATH\n                        Specify additional lookup path for freqaimodels.\n
    "},{"location":"hyperopt/#hyperopt-checklist","title":"Hyperopt checklist","text":"

    Checklist on all tasks / possibilities in hyperopt

    Depending on the space you want to optimize, only some of the below are required:

    • define parameters with space='buy' - for entry signal optimization
    • define parameters with space='sell' - for exit signal optimization

    Note

    populate_indicators needs to create all indicators any of the spaces may use, otherwise hyperopt will not work.

    Rarely you may also need to create a nested class named HyperOpt and implement

    • roi_space - for custom ROI optimization (if you need the ranges for the ROI parameters in the optimization hyperspace that differ from default)
    • generate_roi_table - for custom ROI optimization (if you need the ranges for the values in the ROI table that differ from default or the number of entries (steps) in the ROI table which differs from the default 4 steps)
    • stoploss_space - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default)
    • trailing_space - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default)
    • max_open_trades_space - for custom max_open_trades optimization (if you need the ranges for the max_open_trades parameter in the optimization hyperspace that differ from default)

    Quickly optimize ROI, stoploss and trailing stoploss

    You can quickly optimize the spaces roi, stoploss and trailing without changing anything in your strategy.

    # Have a working strategy at hand.\nfreqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi stoploss trailing --strategy MyWorkingStrategy --config config.json -e 100\n
    "},{"location":"hyperopt/#hyperopt-execution-logic","title":"Hyperopt execution logic","text":"

    Hyperopt will first load your data into memory and will then run populate_indicators() once per Pair to generate all indicators, unless --analyze-per-epoch is specified.

    Hyperopt will then spawn into different processes (number of processors, or -j <n>), and run backtesting over and over again, changing the parameters that are part of the --spaces defined.

    For every new set of parameters, freqtrade will run first populate_entry_trend() followed by populate_exit_trend(), and then run the regular backtesting process to simulate trades.

    After backtesting, the results are passed into the loss function, which will evaluate if this result was better or worse than previous results. Based on the loss function result, hyperopt will determine the next set of parameters to try in the next round of backtesting.

    "},{"location":"hyperopt/#configure-your-guards-and-triggers","title":"Configure your Guards and Triggers","text":"

    There are two places you need to change in your strategy file to add a new buy hyperopt for testing:

    • Define the parameters at the class level hyperopt shall be optimizing.
    • Within populate_entry_trend() - use defined parameter values instead of raw constants.

    There you have two different types of indicators: 1. guards and 2. triggers.

    1. Guards are conditions like \"never buy if ADX < 10\", or never buy if current price is over EMA10.
    2. Triggers are ones that actually trigger buy in specific moment, like \"buy when EMA5 crosses over EMA10\" or \"buy when close price touches lower Bollinger band\".

    Guards and Triggers

    Technically, there is no difference between Guards and Triggers. However, this guide will make this distinction to make it clear that signals should not be \"sticking\". Sticking signals are signals that are active for multiple candles. This can lead into entering a signal late (right before the signal disappears - which means that the chance of success is a lot lower than right at the beginning).

    Hyper-optimization will, for each epoch round, pick one trigger and possibly multiple guards.

    "},{"location":"hyperopt/#exit-signal-optimization","title":"Exit signal optimization","text":"

    Similar to the entry-signal above, exit-signals can also be optimized. Place the corresponding settings into the following methods

    • Define the parameters at the class level hyperopt shall be optimizing, either naming them sell_*, or by explicitly defining space='sell'.
    • Within populate_exit_trend() - use defined parameter values instead of raw constants.

    The configuration and rules are the same than for buy signals.

    "},{"location":"hyperopt/#solving-a-mystery","title":"Solving a Mystery","text":"

    Let's say you are curious: should you use MACD crossings or lower Bollinger Bands to trigger your long entries. And you also wonder should you use RSI or ADX to help with those decisions. If you decide to use RSI or ADX, which values should I use for them?

    So let's use hyperparameter optimization to solve this mystery.

    "},{"location":"hyperopt/#defining-indicators-to-be-used","title":"Defining indicators to be used","text":"

    We start by calculating the indicators our strategy is going to use.

    class MyAwesomeStrategy(IStrategy):\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Generate all indicators used by the strategy\n        \"\"\"\n        dataframe['adx'] = ta.ADX(dataframe)\n        dataframe['rsi'] = ta.RSI(dataframe)\n        macd = ta.MACD(dataframe)\n        dataframe['macd'] = macd['macd']\n        dataframe['macdsignal'] = macd['macdsignal']\n        dataframe['macdhist'] = macd['macdhist']\n\n        bollinger = ta.BBANDS(dataframe, timeperiod=20, nbdevup=2.0, nbdevdn=2.0)\n        dataframe['bb_lowerband'] = bollinger['lowerband']\n        dataframe['bb_middleband'] = bollinger['middleband']\n        dataframe['bb_upperband'] = bollinger['upperband']\n        return dataframe\n
    "},{"location":"hyperopt/#hyperoptable-parameters","title":"Hyperoptable parameters","text":"

    We continue to define hyperoptable parameters:

    class MyAwesomeStrategy(IStrategy):\n    buy_adx = DecimalParameter(20, 40, decimals=1, default=30.1, space=\"buy\")\n    buy_rsi = IntParameter(20, 40, default=30, space=\"buy\")\n    buy_adx_enabled = BooleanParameter(default=True, space=\"buy\")\n    buy_rsi_enabled = CategoricalParameter([True, False], default=False, space=\"buy\")\n    buy_trigger = CategoricalParameter([\"bb_lower\", \"macd_cross_signal\"], default=\"bb_lower\", space=\"buy\")\n

    The above definition says: I have five parameters I want to randomly combine to find the best combination. buy_rsi is an integer parameter, which will be tested between 20 and 40. This space has a size of 20. buy_adx is a decimal parameter, which will be evaluated between 20 and 40 with 1 decimal place (so values are 20.1, 20.2, ...). This space has a size of 200. Then we have three category variables. First two are either True or False. We use these to either enable or disable the ADX and RSI guards. The last one we call trigger and use it to decide which buy trigger we want to use.

    Parameter space assignment

    Parameters must either be assigned to a variable named buy_* or sell_* - or contain space='buy' | space='sell' to be assigned to a space correctly. If no parameter is available for a space, you'll receive the error that no space was found when running hyperopt. Parameters with unclear space (e.g. adx_period = IntParameter(4, 24, default=14) - no explicit nor implicit space) will not be detected and will therefore be ignored.

    So let's write the buy strategy using these values:

        def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        conditions = []\n        # GUARDS AND TRENDS\n        if self.buy_adx_enabled.value:\n            conditions.append(dataframe['adx'] > self.buy_adx.value)\n        if self.buy_rsi_enabled.value:\n            conditions.append(dataframe['rsi'] < self.buy_rsi.value)\n\n        # TRIGGERS\n        if self.buy_trigger.value == 'bb_lower':\n            conditions.append(dataframe['close'] < dataframe['bb_lowerband'])\n        if self.buy_trigger.value == 'macd_cross_signal':\n            conditions.append(qtpylib.crossed_above(\n                dataframe['macd'], dataframe['macdsignal']\n            ))\n\n        # Check that volume is not 0\n        conditions.append(dataframe['volume'] > 0)\n\n        if conditions:\n            dataframe.loc[\n                reduce(lambda x, y: x & y, conditions),\n                'enter_long'] = 1\n\n        return dataframe\n

    Hyperopt will now call populate_entry_trend() many times (epochs) with different value combinations. It will use the given historical data and simulate buys based on the buy signals generated with the above function. Based on the results, hyperopt will tell you which parameter combination produced the best results (based on the configured loss function).

    Note

    The above setup expects to find ADX, RSI and Bollinger Bands in the populated indicators. When you want to test an indicator that isn't used by the bot currently, remember to add it to the populate_indicators() method in your strategy or hyperopt file.

    "},{"location":"hyperopt/#parameter-types","title":"Parameter types","text":"

    There are four parameter types each suited for different purposes.

    • IntParameter - defines an integral parameter with upper and lower boundaries of search space.
    • DecimalParameter - defines a floating point parameter with a limited number of decimals (default 3). Should be preferred instead of RealParameter in most cases.
    • RealParameter - defines a floating point parameter with upper and lower boundaries and no precision limit. Rarely used as it creates a space with a near infinite number of possibilities.
    • CategoricalParameter - defines a parameter with a predetermined number of choices.
    • BooleanParameter - Shorthand for CategoricalParameter([True, False]) - great for \"enable\" parameters.
    "},{"location":"hyperopt/#parameter-options","title":"Parameter options","text":"

    There are two parameter options that can help you to quickly test various ideas:

    • optimize - when set to False, the parameter will not be included in optimization process. (Default: True)
    • load - when set to False, results of a previous hyperopt run (in buy_params and sell_params either in your strategy or the JSON output file) will not be used as the starting value for subsequent hyperopts. The default value specified in the parameter will be used instead. (Default: True)

    Effects of load=False on backtesting

    Be aware that setting the load option to False will mean backtesting will also use the default value specified in the parameter and not the value found through hyperoptimisation.

    Warning

    Hyperoptable parameters cannot be used in populate_indicators - as hyperopt does not recalculate indicators for each epoch, so the starting value would be used in this case.

    "},{"location":"hyperopt/#optimizing-an-indicator-parameter","title":"Optimizing an indicator parameter","text":"

    Assuming you have a simple strategy in mind - a EMA cross strategy (2 Moving averages crossing) - and you'd like to find the ideal parameters for this strategy. By default, we assume a stoploss of 5% - and a take-profit (minimal_roi) of 10% - which means freqtrade will sell the trade once 10% profit has been reached.

    from pandas import DataFrame\nfrom functools import reduce\n\nimport talib.abstract as ta\n\nfrom freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, \n                                IStrategy, IntParameter)\nimport freqtrade.vendor.qtpylib.indicators as qtpylib\n\nclass MyAwesomeStrategy(IStrategy):\n    stoploss = -0.05\n    timeframe = '15m'\n    minimal_roi = {\n        \"0\":  0.10\n    }\n    # Define the parameter spaces\n    buy_ema_short = IntParameter(3, 50, default=5)\n    buy_ema_long = IntParameter(15, 200, default=50)\n\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"Generate all indicators used by the strategy\"\"\"\n\n        # Calculate all ema_short values\n        for val in self.buy_ema_short.range:\n            dataframe[f'ema_short_{val}'] = ta.EMA(dataframe, timeperiod=val)\n\n        # Calculate all ema_long values\n        for val in self.buy_ema_long.range:\n            dataframe[f'ema_long_{val}'] = ta.EMA(dataframe, timeperiod=val)\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        conditions = []\n        conditions.append(qtpylib.crossed_above(\n                dataframe[f'ema_short_{self.buy_ema_short.value}'], dataframe[f'ema_long_{self.buy_ema_long.value}']\n            ))\n\n        # Check that volume is not 0\n        conditions.append(dataframe['volume'] > 0)\n\n        if conditions:\n            dataframe.loc[\n                reduce(lambda x, y: x & y, conditions),\n                'enter_long'] = 1\n        return dataframe\n\n    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        conditions = []\n        conditions.append(qtpylib.crossed_above(\n                dataframe[f'ema_long_{self.buy_ema_long.value}'], dataframe[f'ema_short_{self.buy_ema_short.value}']\n            ))\n\n        # Check that volume is not 0\n        conditions.append(dataframe['volume'] > 0)\n\n        if conditions:\n            dataframe.loc[\n                reduce(lambda x, y: x & y, conditions),\n                'exit_long'] = 1\n        return dataframe\n

    Breaking it down:

    Using self.buy_ema_short.range will return a range object containing all entries between the Parameters low and high value. In this case (IntParameter(3, 50, default=5)), the loop would run for all numbers between 3 and 50 ([3, 4, 5, ... 49, 50]). By using this in a loop, hyperopt will generate 48 new columns (['buy_ema_3', 'buy_ema_4', ... , 'buy_ema_50']).

    Hyperopt itself will then use the selected value to create the buy and sell signals.

    While this strategy is most likely too simple to provide consistent profit, it should serve as an example how optimize indicator parameters.

    Note

    self.buy_ema_short.range will act differently between hyperopt and other modes. For hyperopt, the above example may generate 48 new columns, however for all other modes (backtesting, dry/live), it will only generate the column for the selected value. You should therefore avoid using the resulting column with explicit values (values other than self.buy_ema_short.value).

    Note

    range property may also be used with DecimalParameter and CategoricalParameter. RealParameter does not provide this property due to infinite search space.

    Performance tip

    During normal hyperopting, indicators are calculated once and supplied to each epoch, linearly increasing RAM usage as a factor of increasing cores. As this also has performance implications, there are two alternatives to reduce RAM usage

    • Move ema_short and ema_long calculations from populate_indicators() to populate_entry_trend(). Since populate_entry_trend() will be calculated every epoch, you don't need to use .range functionality.
    • hyperopt provides --analyze-per-epoch which will move the execution of populate_indicators() to the epoch process, calculating a single value per parameter per epoch instead of using the .range functionality. In this case, .range functionality will only return the actually used value.

    These alternatives will reduce RAM usage, but increase CPU usage. However, your hyperopting run will be less likely to fail due to Out Of Memory (OOM) issues.

    Whether you are using .range functionality or the alternatives above, you should try to use space ranges as small as possible since this will improve CPU/RAM usage.

    "},{"location":"hyperopt/#optimizing-protections","title":"Optimizing protections","text":"

    Freqtrade can also optimize protections. How you optimize protections is up to you, and the following should be considered as example only.

    The strategy will simply need to define the \"protections\" entry as property returning a list of protection configurations.

    from pandas import DataFrame\nfrom functools import reduce\n\nimport talib.abstract as ta\n\nfrom freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, \n                                IStrategy, IntParameter)\nimport freqtrade.vendor.qtpylib.indicators as qtpylib\n\nclass MyAwesomeStrategy(IStrategy):\n    stoploss = -0.05\n    timeframe = '15m'\n    # Define the parameter spaces\n    cooldown_lookback = IntParameter(2, 48, default=5, space=\"protection\", optimize=True)\n    stop_duration = IntParameter(12, 200, default=5, space=\"protection\", optimize=True)\n    use_stop_protection = BooleanParameter(default=True, space=\"protection\", optimize=True)\n\n\n    @property\n    def protections(self):\n        prot = []\n\n        prot.append({\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": self.cooldown_lookback.value\n        })\n        if self.use_stop_protection.value:\n            prot.append({\n                \"method\": \"StoplossGuard\",\n                \"lookback_period_candles\": 24 * 3,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": self.stop_duration.value,\n                \"only_per_pair\": False\n            })\n\n        return prot\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # ...\n

    You can then run hyperopt as follows: freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy MyAwesomeStrategy --spaces protection

    Note

    The protection space is not part of the default space, and is only available with the Parameters Hyperopt interface, not with the legacy hyperopt interface (which required separate hyperopt files). Freqtrade will also automatically change the \"--enable-protections\" flag if the protection space is selected.

    Warning

    If protections are defined as property, entries from the configuration will be ignored. It is therefore recommended to not define protections in the configuration.

    "},{"location":"hyperopt/#migrating-from-previous-property-setups","title":"Migrating from previous property setups","text":"

    A migration from a previous setup is pretty simple, and can be accomplished by converting the protections entry to a property. In simple terms, the following configuration will be converted to the below.

    class MyAwesomeStrategy(IStrategy):\n    protections = [\n        {\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": 4\n        }\n    ]\n

    Result

    class MyAwesomeStrategy(IStrategy):\n\n    @property\n    def protections(self):\n        return [\n            {\n                \"method\": \"CooldownPeriod\",\n                \"stop_duration_candles\": 4\n            }\n        ]\n

    You will then obviously also change potential interesting entries to parameters to allow hyper-optimization.

    "},{"location":"hyperopt/#optimizing-max_entry_position_adjustment","title":"Optimizing max_entry_position_adjustment","text":"

    While max_entry_position_adjustment is not a separate space, it can still be used in hyperopt by using the property approach shown above.

    from pandas import DataFrame\nfrom functools import reduce\n\nimport talib.abstract as ta\n\nfrom freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, \n                                IStrategy, IntParameter)\nimport freqtrade.vendor.qtpylib.indicators as qtpylib\n\nclass MyAwesomeStrategy(IStrategy):\n    stoploss = -0.05\n    timeframe = '15m'\n\n    # Define the parameter spaces\n    max_epa = CategoricalParameter([-1, 0, 1, 3, 5, 10], default=1, space=\"buy\", optimize=True)\n\n    @property\n    def max_entry_position_adjustment(self):\n        return self.max_epa.value\n\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # ...\n
    Using IntParameter

    You can also use the IntParameter for this optimization, but you must explicitly return an integer:

    max_epa = IntParameter(-1, 10, default=1, space=\"buy\", optimize=True)\n\n@property\ndef max_entry_position_adjustment(self):\n    return int(self.max_epa.value)\n

    "},{"location":"hyperopt/#loss-functions","title":"Loss-functions","text":"

    Each hyperparameter tuning requires a target. This is usually defined as a loss function (sometimes also called objective function), which should decrease for more desirable results, and increase for bad results.

    A loss function must be specified via the --hyperopt-loss <Class-name> argument (or optionally via the configuration under the \"hyperopt_loss\" key). This class should be in its own file within the user_data/hyperopts/ directory.

    Currently, the following loss functions are builtin:

    • ShortTradeDurHyperOptLoss - (default legacy Freqtrade hyperoptimization loss function) - Mostly for short trade duration and avoiding losses.
    • OnlyProfitHyperOptLoss - takes only amount of profit into consideration.
    • SharpeHyperOptLoss - optimizes Sharpe Ratio calculated on trade returns relative to standard deviation.
    • SharpeHyperOptLossDaily - optimizes Sharpe Ratio calculated on daily trade returns relative to standard deviation.
    • SortinoHyperOptLoss - optimizes Sortino Ratio calculated on trade returns relative to downside standard deviation.
    • SortinoHyperOptLossDaily - optimizes Sortino Ratio calculated on daily trade returns relative to downside standard deviation.
    • MaxDrawDownHyperOptLoss - Optimizes Maximum absolute drawdown.
    • MaxDrawDownRelativeHyperOptLoss - Optimizes both maximum absolute drawdown while also adjusting for maximum relative drawdown.
    • CalmarHyperOptLoss - Optimizes Calmar Ratio calculated on trade returns relative to max drawdown.
    • ProfitDrawDownHyperOptLoss - Optimizes by max Profit & min Drawdown objective. DRAWDOWN_MULT variable within the hyperoptloss file can be adjusted to be stricter or more flexible on drawdown purposes.

    Creation of a custom loss function is covered in the Advanced Hyperopt part of the documentation.

    "},{"location":"hyperopt/#execute-hyperopt","title":"Execute Hyperopt","text":"

    Once you have updated your hyperopt configuration you can run it. Because hyperopt tries a lot of combinations to find the best parameters it will take time to get a good result.

    We strongly recommend to use screen or tmux to prevent any connection loss.

    freqtrade hyperopt --config config.json --hyperopt-loss <hyperoptlossname> --strategy <strategyname> -e 500 --spaces all\n

    The -e option will set how many evaluations hyperopt will do. Since hyperopt uses Bayesian search, running too many epochs at once may not produce greater results. Experience has shown that best results are usually not improving much after 500-1000 epochs. Doing multiple runs (executions) with a few 1000 epochs and different random state will most likely produce different results.

    The --spaces all option determines that all possible parameters should be optimized. Possibilities are listed below.

    Note

    Hyperopt will store hyperopt results with the timestamp of the hyperopt start time. Reading commands (hyperopt-list, hyperopt-show) can use --hyperopt-filename <filename> to read and display older hyperopt results. You can find a list of filenames with ls -l user_data/hyperopt_results/.

    "},{"location":"hyperopt/#execute-hyperopt-with-different-historical-data-source","title":"Execute Hyperopt with different historical data source","text":"

    If you would like to hyperopt parameters using an alternate historical data set that you have on-disk, use the --datadir PATH option. By default, hyperopt uses data from directory user_data/data.

    "},{"location":"hyperopt/#running-hyperopt-with-a-smaller-test-set","title":"Running Hyperopt with a smaller test-set","text":"

    Use the --timerange argument to change how much of the test-set you want to use. For example, to use one month of data, pass --timerange 20210101-20210201 (from january 2021 - february 2021) to the hyperopt call.

    Full command:

    freqtrade hyperopt --strategy <strategyname> --timerange 20210101-20210201\n
    "},{"location":"hyperopt/#running-hyperopt-with-smaller-search-space","title":"Running Hyperopt with Smaller Search Space","text":"

    Use the --spaces option to limit the search space used by hyperopt. Letting Hyperopt optimize everything is a huuuuge search space. Often it might make more sense to start by just searching for initial buy algorithm. Or maybe you just want to optimize your stoploss or roi table for that awesome new buy strategy you have.

    Legal values are:

    • all: optimize everything
    • buy: just search for a new buy strategy
    • sell: just search for a new sell strategy
    • roi: just optimize the minimal profit table for your strategy
    • stoploss: search for the best stoploss value
    • trailing: search for the best trailing stop values
    • trades: search for the best max open trades values
    • protection: search for the best protection parameters (read the protections section on how to properly define these)
    • default: all except trailing and protection
    • space-separated list of any of the above values for example --spaces roi stoploss

    The default Hyperopt Search Space, used when no --space command line option is specified, does not include the trailing hyperspace. We recommend you to run optimization for the trailing hyperspace separately, when the best parameters for other hyperspaces were found, validated and pasted into your custom strategy.

    "},{"location":"hyperopt/#understand-the-hyperopt-result","title":"Understand the Hyperopt Result","text":"

    Once Hyperopt is completed you can use the result to update your strategy. Given the following result from hyperopt:

    Best result:\n\n    44/100:    135 trades. Avg profit  0.57%. Total profit  0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367\n\n    # Buy hyperspace params:\n    buy_params = {\n        'buy_adx': 44,\n        'buy_rsi': 29,\n        'buy_adx_enabled': False,\n        'buy_rsi_enabled': True,\n        'buy_trigger': 'bb_lower'\n    }\n

    You should understand this result like:

    • The buy trigger that worked best was bb_lower.
    • You should not use ADX because 'buy_adx_enabled': False.
    • You should consider using the RSI indicator ('buy_rsi_enabled': True) and the best value is 29.0 ('buy_rsi': 29.0)
    "},{"location":"hyperopt/#automatic-parameter-application-to-the-strategy","title":"Automatic parameter application to the strategy","text":"

    When using Hyperoptable parameters, the result of your hyperopt-run will be written to a json file next to your strategy (so for MyAwesomeStrategy.py, the file would be MyAwesomeStrategy.json). This file is also updated when using the hyperopt-show sub-command, unless --disable-param-export is provided to either of the 2 commands.

    Your strategy class can also contain these results explicitly. Simply copy hyperopt results block and paste them at class level, replacing old parameters (if any). New parameters will automatically be loaded next time strategy is executed.

    Transferring your whole hyperopt result to your strategy would then look like:

    class MyAwesomeStrategy(IStrategy):\n    # Buy hyperspace params:\n    buy_params = {\n        'buy_adx': 44,\n        'buy_rsi': 29,\n        'buy_adx_enabled': False,\n        'buy_rsi_enabled': True,\n        'buy_trigger': 'bb_lower'\n    }\n

    Note

    Values in the configuration file will overwrite Parameter-file level parameters - and both will overwrite parameters within the strategy. The prevalence is therefore: config > parameter file > strategy *_params > parameter default

    "},{"location":"hyperopt/#understand-hyperopt-roi-results","title":"Understand Hyperopt ROI results","text":"

    If you are optimizing ROI (i.e. if optimization search-space contains 'all', 'default' or 'roi'), your result will look as follows and include a ROI table:

    Best result:\n\n    44/100:    135 trades. Avg profit  0.57%. Total profit  0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367\n\n    # ROI table:\n    minimal_roi = {\n        0: 0.10674,\n        21: 0.09158,\n        78: 0.03634,\n        118: 0\n    }\n

    In order to use this best ROI table found by Hyperopt in backtesting and for live trades/dry-run, copy-paste it as the value of the minimal_roi attribute of your custom strategy:

        # Minimal ROI designed for the strategy.\n    # This attribute will be overridden if the config file contains \"minimal_roi\"\n    minimal_roi = {\n        0: 0.10674,\n        21: 0.09158,\n        78: 0.03634,\n        118: 0\n    }\n

    As stated in the comment, you can also use it as the value of the minimal_roi setting in the configuration file.

    "},{"location":"hyperopt/#default-roi-search-space","title":"Default ROI Search Space","text":"

    If you are optimizing ROI, Freqtrade creates the 'roi' optimization hyperspace for you -- it's the hyperspace of components for the ROI tables. By default, each ROI table generated by the Freqtrade consists of 4 rows (steps). Hyperopt implements adaptive ranges for ROI tables with ranges for values in the ROI steps that depend on the timeframe used. By default the values vary in the following ranges (for some of the most used timeframes, values are rounded to 3 digits after the decimal point):

    # step 1m 5m 1h 1d 1 0 0.011...0.119 0 0.03...0.31 0 0.068...0.711 0 0.121...1.258 2 2...8 0.007...0.042 10...40 0.02...0.11 120...480 0.045...0.252 2880...11520 0.081...0.446 3 4...20 0.003...0.015 20...100 0.01...0.04 240...1200 0.022...0.091 5760...28800 0.040...0.162 4 6...44 0.0 30...220 0.0 360...2640 0.0 8640...63360 0.0

    These ranges should be sufficient in most cases. The minutes in the steps (ROI dict keys) are scaled linearly depending on the timeframe used. The ROI values in the steps (ROI dict values) are scaled logarithmically depending on the timeframe used.

    If you have the generate_roi_table() and roi_space() methods in your custom hyperopt, remove them in order to utilize these adaptive ROI tables and the ROI hyperoptimization space generated by Freqtrade by default.

    Override the roi_space() method if you need components of the ROI tables to vary in other ranges. Override the generate_roi_table() and roi_space() methods and implement your own custom approach for generation of the ROI tables during hyperoptimization if you need a different structure of the ROI tables or other amount of rows (steps).

    A sample for these methods can be found in the overriding pre-defined spaces section.

    Reduced search space

    To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however overriding pre-defined spaces to change this to your needs.

    "},{"location":"hyperopt/#understand-hyperopt-stoploss-results","title":"Understand Hyperopt Stoploss results","text":"

    If you are optimizing stoploss values (i.e. if optimization search-space contains 'all', 'default' or 'stoploss'), your result will look as follows and include stoploss:

    Best result:\n\n    44/100:    135 trades. Avg profit  0.57%. Total profit  0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367\n\n    # Buy hyperspace params:\n    buy_params = {\n        'buy_adx': 44,\n        'buy_rsi': 29,\n        'buy_adx_enabled': False,\n        'buy_rsi_enabled': True,\n        'buy_trigger': 'bb_lower'\n    }\n\n    stoploss: -0.27996\n

    In order to use this best stoploss value found by Hyperopt in backtesting and for live trades/dry-run, copy-paste it as the value of the stoploss attribute of your custom strategy:

        # Optimal stoploss designed for the strategy\n    # This attribute will be overridden if the config file contains \"stoploss\"\n    stoploss = -0.27996\n

    As stated in the comment, you can also use it as the value of the stoploss setting in the configuration file.

    "},{"location":"hyperopt/#default-stoploss-search-space","title":"Default Stoploss Search Space","text":"

    If you are optimizing stoploss values, Freqtrade creates the 'stoploss' optimization hyperspace for you. By default, the stoploss values in that hyperspace vary in the range -0.35...-0.02, which is sufficient in most cases.

    If you have the stoploss_space() method in your custom hyperopt file, remove it in order to utilize Stoploss hyperoptimization space generated by Freqtrade by default.

    Override the stoploss_space() method and define the desired range in it if you need stoploss values to vary in other range during hyperoptimization. A sample for this method can be found in the overriding pre-defined spaces section.

    Reduced search space

    To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however overriding pre-defined spaces to change this to your needs.

    "},{"location":"hyperopt/#understand-hyperopt-trailing-stop-results","title":"Understand Hyperopt Trailing Stop results","text":"

    If you are optimizing trailing stop values (i.e. if optimization search-space contains 'all' or 'trailing'), your result will look as follows and include trailing stop parameters:

    Best result:\n\n    45/100:    606 trades. Avg profit  1.04%. Total profit  0.31555614 BTC ( 630.48%). Avg duration 150.3 mins. Objective: -1.10161\n\n    # Trailing stop:\n    trailing_stop = True\n    trailing_stop_positive = 0.02001\n    trailing_stop_positive_offset = 0.06038\n    trailing_only_offset_is_reached = True\n

    In order to use these best trailing stop parameters found by Hyperopt in backtesting and for live trades/dry-run, copy-paste them as the values of the corresponding attributes of your custom strategy:

        # Trailing stop\n    # These attributes will be overridden if the config file contains corresponding values.\n    trailing_stop = True\n    trailing_stop_positive = 0.02001\n    trailing_stop_positive_offset = 0.06038\n    trailing_only_offset_is_reached = True\n

    As stated in the comment, you can also use it as the values of the corresponding settings in the configuration file.

    "},{"location":"hyperopt/#default-trailing-stop-search-space","title":"Default Trailing Stop Search Space","text":"

    If you are optimizing trailing stop values, Freqtrade creates the 'trailing' optimization hyperspace for you. By default, the trailing_stop parameter is always set to True in that hyperspace, the value of the trailing_only_offset_is_reached vary between True and False, the values of the trailing_stop_positive and trailing_stop_positive_offset parameters vary in the ranges 0.02...0.35 and 0.01...0.1 correspondingly, which is sufficient in most cases.

    Override the trailing_space() method and define the desired range in it if you need values of the trailing stop parameters to vary in other ranges during hyperoptimization. A sample for this method can be found in the overriding pre-defined spaces section.

    Reduced search space

    To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however overriding pre-defined spaces to change this to your needs.

    "},{"location":"hyperopt/#reproducible-results","title":"Reproducible results","text":"

    The search for optimal parameters starts with a few (currently 30) random combinations in the hyperspace of parameters, random Hyperopt epochs. These random epochs are marked with an asterisk character (*) in the first column in the Hyperopt output.

    The initial state for generation of these random values (random state) is controlled by the value of the --random-state command line option. You can set it to some arbitrary value of your choice to obtain reproducible results.

    If you have not set this value explicitly in the command line options, Hyperopt seeds the random state with some random value for you. The random state value for each Hyperopt run is shown in the log, so you can copy and paste it into the --random-state command line option to repeat the set of the initial random epochs used.

    If you have not changed anything in the command line options, configuration, timerange, Strategy and Hyperopt classes, historical data and the Loss Function -- you should obtain same hyper-optimization results with same random state value used.

    "},{"location":"hyperopt/#output-formatting","title":"Output formatting","text":"

    By default, hyperopt prints colorized results -- epochs with positive profit are printed in the green color. This highlighting helps you find epochs that can be interesting for later analysis. Epochs with zero total profit or with negative profits (losses) are printed in the normal color. If you do not need colorization of results (for instance, when you are redirecting hyperopt output to a file) you can switch colorization off by specifying the --no-color option in the command line.

    You can use the --print-all command line option if you would like to see all results in the hyperopt output, not only the best ones. When --print-all is used, current best results are also colorized by default -- they are printed in bold (bright) style. This can also be switched off with the --no-color command line option.

    Windows and color output

    Windows does not support color-output natively, therefore it is automatically disabled. To have color-output for hyperopt running under windows, please consider using WSL.

    "},{"location":"hyperopt/#position-stacking-and-disabling-max-market-positions","title":"Position stacking and disabling max market positions","text":"

    In some situations, you may need to run Hyperopt (and Backtesting) with the --eps/--enable-position-staking and --dmmp/--disable-max-market-positions arguments.

    By default, hyperopt emulates the behavior of the Freqtrade Live Run/Dry Run, where only one open trade is allowed for every traded pair. The total number of trades open for all pairs is also limited by the max_open_trades setting. During Hyperopt/Backtesting this may lead to some potential trades to be hidden (or masked) by previously open trades.

    The --eps/--enable-position-stacking argument allows emulation of buying the same pair multiple times, while --dmmp/--disable-max-market-positions disables applying max_open_trades during Hyperopt/Backtesting (which is equal to setting max_open_trades to a very high number).

    Note

    Dry/live runs will NOT use position stacking - therefore it does make sense to also validate the strategy without this as it's closer to reality.

    You can also enable position stacking in the configuration file by explicitly setting \"position_stacking\"=true.

    "},{"location":"hyperopt/#out-of-memory-errors","title":"Out of Memory errors","text":"

    As hyperopt consumes a lot of memory (the complete data needs to be in memory once per parallel backtesting process), it's likely that you run into \"out of memory\" errors. To combat these, you have multiple options:

    • Reduce the amount of pairs.
    • Reduce the timerange used (--timerange <timerange>).
    • Avoid using --timeframe-detail (this loads a lot of additional data into memory).
    • Reduce the number of parallel processes (-j <n>).
    • Increase the memory of your machine.
    • Use --analyze-per-epoch if you're using a lot of parameters with .range functionality.
    "},{"location":"hyperopt/#the-objective-has-been-evaluated-at-this-point-before","title":"The objective has been evaluated at this point before.","text":"

    If you see The objective has been evaluated at this point before. - then this is a sign that your space has been exhausted, or is close to that. Basically all points in your space have been hit (or a local minima has been hit) - and hyperopt does no longer find points in the multi-dimensional space it did not try yet. Freqtrade tries to counter the \"local minima\" problem by using new, randomized points in this case.

    Example:

    buy_ema_short = IntParameter(5, 20, default=10, space=\"buy\", optimize=True)\n# This is the only parameter in the buy space\n

    The buy_ema_short space has 15 possible values (5, 6, ... 19, 20). If you now run hyperopt for the buy space, hyperopt will only have 15 values to try before running out of options. Your epochs should therefore be aligned to the possible values - or you should be ready to interrupt a run if you norice a lot of The objective has been evaluated at this point before. warnings.

    "},{"location":"hyperopt/#show-details-of-hyperopt-results","title":"Show details of Hyperopt results","text":"

    After you run Hyperopt for the desired amount of epochs, you can later list all results for analysis, select only best or profitable once, and show the details for any of the epochs previously evaluated. This can be done with the hyperopt-list and hyperopt-show sub-commands. The usage of these sub-commands is described in the Utils chapter.

    "},{"location":"hyperopt/#validate-backtesting-results","title":"Validate backtesting results","text":"

    Once the optimized strategy has been implemented into your strategy, you should backtest this strategy to make sure everything is working as expected.

    To achieve same the results (number of trades, their durations, profit, etc.) as during Hyperopt, please use the same configuration and parameters (timerange, timeframe, ...) used for hyperopt --dmmp/--disable-max-market-positions and --eps/--enable-position-stacking for Backtesting.

    "},{"location":"hyperopt/#why-do-my-backtest-results-not-match-my-hyperopt-results","title":"Why do my backtest results not match my hyperopt results?","text":"

    Should results not match, check the following factors:

    • You may have added parameters to hyperopt in populate_indicators() where they will be calculated only once for all epochs. If you are, for example, trying to optimise multiple SMA timeperiod values, the hyperoptable timeperiod parameter should be placed in populate_entry_trend() which is calculated every epoch. See Optimizing an indicator parameter.
    • If you have disabled the auto-export of hyperopt parameters into the JSON parameters file, double-check to make sure you transferred all hyperopted values into your strategy correctly.
    • Check the logs to verify what parameters are being set and what values are being used.
    • Pay special care to the stoploss, max_open_trades and trailing stoploss parameters, as these are often set in configuration files, which override changes to the strategy. Check the logs of your backtest to ensure that there were no parameters inadvertently set by the configuration (like stoploss, max_open_trades or trailing_stop).
    • Verify that you do not have an unexpected parameters JSON file overriding the parameters or the default hyperopt settings in your strategy.
    • Verify that any protections that are enabled in backtesting are also enabled when hyperopting, and vice versa. When using --space protection, protections are auto-enabled for hyperopting.
    "},{"location":"installation/","title":"Installation","text":"

    This page explains how to prepare your environment for running the bot.

    The freqtrade documentation describes various ways to install freqtrade

    • Docker images (separate page)
    • Script Installation
    • Manual Installation
    • Installation with Conda

    Please consider using the prebuilt docker images to get started quickly while evaluating how freqtrade works.

    "},{"location":"installation/#information","title":"Information","text":"

    For Windows installation, please use the windows installation guide.

    The easiest way to install and run Freqtrade is to clone the bot Github repository and then run the ./setup.sh script, if it's available for your platform.

    Version considerations

    When cloning the repository the default working branch has the name develop. This branch contains all last features (can be considered as relatively stable, thanks to automated tests). The stable branch contains the code of the last release (done usually once per month on an approximately one week old snapshot of the develop branch to prevent packaging bugs, so potentially it's more stable).

    Note

    Python3.9 or higher and the corresponding pip are assumed to be available. The install-script will warn you and stop if that's not the case. git is also needed to clone the Freqtrade repository. Also, python headers (python<yourversion>-dev / python<yourversion>-devel) must be available for the installation to complete successfully.

    Up-to-date clock

    The clock on the system running the bot must be accurate, synchronized to a NTP server frequently enough to avoid problems with communication to the exchanges.

    "},{"location":"installation/#requirements","title":"Requirements","text":"

    These requirements apply to both Script Installation and Manual Installation.

    ARM64 systems

    If you are running an ARM64 system (like a MacOS M1 or an Oracle VM), please use docker to run freqtrade. While native installation is possible with some manual effort, this is not supported at the moment.

    "},{"location":"installation/#install-guide","title":"Install guide","text":"
    • Python >= 3.9
    • pip
    • git
    • virtualenv (Recommended)
    • TA-Lib (install instructions below)
    "},{"location":"installation/#install-code","title":"Install code","text":"

    We've included/collected install instructions for Ubuntu, MacOS, and Windows. These are guidelines and your success may vary with other distros. OS Specific steps are listed first, the common section below is necessary for all systems.

    Note

    Python3.9 or higher and the corresponding pip are assumed to be available.

    Debian/UbuntuRaspberryPi/Raspbian

    The following assumes the latest Raspbian Buster lite image. This image comes with python3.9 preinstalled, making it easy to get freqtrade up and running.

    Tested using a Raspberry Pi 3 with the Raspbian Buster lite image, all updates applied.

    sudo apt-get install python3-venv libatlas-base-dev cmake curl\n# Use pywheels.org to speed up installation\nsudo echo \"[global]\\nextra-index-url=https://www.piwheels.org/simple\" > tee /etc/pip.conf\n\ngit clone https://github.com/freqtrade/freqtrade.git\ncd freqtrade\n\nbash setup.sh -i\n

    Installation duration

    Depending on your internet speed and the Raspberry Pi version, installation can take multiple hours to complete. Due to this, we recommend to use the pre-build docker-image for Raspberry, by following the Docker quickstart documentation

    Note

    The above does not install hyperopt dependencies. To install these, please use python3 -m pip install -e .[hyperopt]. We do not advise to run hyperopt on a Raspberry Pi, since this is a very resource-heavy operation, which should be done on powerful machine.

    "},{"location":"installation/#install-necessary-dependencies","title":"Install necessary dependencies","text":"
    # update repository\nsudo apt-get update\n\n# install packages\nsudo apt install -y python3-pip python3-venv python3-dev python3-pandas git curl\n
    "},{"location":"installation/#freqtrade-repository","title":"Freqtrade repository","text":"

    Freqtrade is an open source crypto-currency trading bot, whose code is hosted on github.com

    # Download `develop` branch of freqtrade repository\ngit clone https://github.com/freqtrade/freqtrade.git\n\n# Enter downloaded directory\ncd freqtrade\n\n# your choice (1): novice user\ngit checkout stable\n\n# your choice (2): advanced user\ngit checkout develop\n

    (1) This command switches the cloned repository to the use of the stable branch. It's not needed, if you wish to stay on the (2) develop branch.

    You may later switch between branches at any time with the git checkout stable/git checkout develop commands.

    Install from pypi

    An alternative way to install Freqtrade is from pypi. The downside is that this method requires ta-lib to be correctly installed beforehand, and is therefore currently not the recommended way to install Freqtrade.

    pip install freqtrade\n
    "},{"location":"installation/#script-installation","title":"Script Installation","text":"

    First of the ways to install Freqtrade, is to use provided the Linux/MacOS ./setup.sh script, which install all dependencies and help you configure the bot.

    Make sure you fulfill the Requirements and have downloaded the Freqtrade repository.

    "},{"location":"installation/#use-setupsh-install-linuxmacos","title":"Use /setup.sh -install (Linux/MacOS)","text":"

    If you are on Debian, Ubuntu or MacOS, freqtrade provides the script to install freqtrade.

    # --install, Install freqtrade from scratch\n./setup.sh -i\n
    "},{"location":"installation/#activate-your-virtual-environment","title":"Activate your virtual environment","text":"

    Each time you open a new terminal, you must run source .venv/bin/activate to activate your virtual environment.

    # activate virtual environment\nsource ./.venv/bin/activate\n
    "},{"location":"installation/#congratulations","title":"Congratulations","text":"

    You are ready, and run the bot

    "},{"location":"installation/#other-options-of-setupsh-script","title":"Other options of /setup.sh script","text":"

    You can as well update, configure and reset the codebase of your bot with ./script.sh

    # --update, Command git pull to update.\n./setup.sh -u\n# --reset, Hard reset your develop/stable branch.\n./setup.sh -r\n
    ** --install **\n\nWith this option, the script will install the bot and most dependencies:\nYou will need to have git and python3.9+ installed beforehand for this to work.\n\n* Mandatory software as: `ta-lib`\n* Setup your virtualenv under `.venv/`\n\nThis option is a combination of installation tasks and `--reset`\n\n** --update **\n\nThis option will pull the last version of your current branch and update your virtualenv. Run the script with this option periodically to update your bot.\n\n** --reset **\n\nThis option will hard reset your branch (only if you are on either `stable` or `develop`) and recreate your virtualenv.\n
    "},{"location":"installation/#manual-installation","title":"Manual Installation","text":"

    Make sure you fulfill the Requirements and have downloaded the Freqtrade repository.

    "},{"location":"installation/#install-ta-lib","title":"Install TA-Lib","text":""},{"location":"installation/#ta-lib-script-installation","title":"TA-Lib script installation","text":"
    sudo ./build_helpers/install_ta-lib.sh\n

    Note

    This will use the ta-lib tar.gz included in this repository.

    "},{"location":"installation/#ta-lib-manual-installation","title":"TA-Lib manual installation","text":"

    Official installation guide

    wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz\ntar xvzf ta-lib-0.4.0-src.tar.gz\ncd ta-lib\nsed -i.bak \"s|0.00000001|0.000000000000000001 |g\" src/ta_func/ta_utility.h\n./configure --prefix=/usr/local\nmake\nsudo make install\n# On debian based systems (debian, ubuntu, ...) - updating ldconfig might be necessary.\nsudo ldconfig  \ncd ..\nrm -rf ./ta-lib*\n
    "},{"location":"installation/#setup-python-virtual-environment-virtualenv","title":"Setup Python virtual environment (virtualenv)","text":"

    You will run freqtrade in separated virtual environment

    # create virtualenv in directory /freqtrade/.venv\npython3 -m venv .venv\n\n# run virtualenv\nsource .venv/bin/activate\n
    "},{"location":"installation/#install-python-dependencies","title":"Install python dependencies","text":"
    python3 -m pip install --upgrade pip\npython3 -m pip install -r requirements.txt\npython3 -m pip install -e .\n
    "},{"location":"installation/#congratulations_1","title":"Congratulations","text":"

    You are ready, and run the bot

    "},{"location":"installation/#optional-post-installation-tasks","title":"(Optional) Post-installation Tasks","text":"

    Note

    If you run the bot on a server, you should consider using Docker or a terminal multiplexer like screen or tmux to avoid that the bot is stopped on logout.

    On Linux with software suite systemd, as an optional post-installation task, you may wish to setup the bot to run as a systemd service or configure it to send the log messages to the syslog/rsyslog or journald daemons. See Advanced Logging for details.

    "},{"location":"installation/#installation-with-conda","title":"Installation with Conda","text":"

    Freqtrade can also be installed with Miniconda or Anaconda. We recommend using Miniconda as it's installation footprint is smaller. Conda will automatically prepare and manage the extensive library-dependencies of the Freqtrade program.

    "},{"location":"installation/#what-is-conda","title":"What is Conda?","text":"

    Conda is a package, dependency and environment manager for multiple programming languages: conda docs

    "},{"location":"installation/#installation-with-conda_1","title":"Installation with conda","text":""},{"location":"installation/#install-conda","title":"Install Conda","text":"

    Installing on linux

    Installing on windows

    Answer all questions. After installation, it is mandatory to turn your terminal OFF and ON again.

    "},{"location":"installation/#freqtrade-download","title":"Freqtrade download","text":"

    Download and install freqtrade.

    # download freqtrade\ngit clone https://github.com/freqtrade/freqtrade.git\n\n# enter downloaded directory 'freqtrade'\ncd freqtrade      \n
    "},{"location":"installation/#freqtrade-install-conda-environment","title":"Freqtrade install: Conda Environment","text":"
    conda create --name freqtrade python=3.12\n

    Creating Conda Environment

    The conda command create -n automatically installs all nested dependencies for the selected libraries, general structure of installation command is:

    # choose your own packages\nconda env create -n [name of the environment] [python version] [packages]\n
    "},{"location":"installation/#enterexit-freqtrade-environment","title":"Enter/exit freqtrade environment","text":"

    To check available environments, type

    conda env list\n

    Enter installed environment

    # enter conda environment\nconda activate freqtrade\n\n# exit conda environment - don't do it now\nconda deactivate\n

    Install last python dependencies with pip

    python3 -m pip install --upgrade pip\npython3 -m pip install -r requirements.txt\npython3 -m pip install -e .\n

    Patch conda libta-lib (Linux only)

    # Ensure that the environment is active!\nconda activate freqtrade\n\ncd build_helpers\nbash install_ta-lib.sh ${CONDA_PREFIX} nosudo\n
    "},{"location":"installation/#congratulations_2","title":"Congratulations","text":"

    You are ready, and run the bot

    "},{"location":"installation/#important-shortcuts","title":"Important shortcuts","text":"
    # list installed conda environments\nconda env list\n\n# activate base environment\nconda activate\n\n# activate freqtrade environment\nconda activate freqtrade\n\n#deactivate any conda environments\nconda deactivate                              \n
    "},{"location":"installation/#further-info-on-anaconda","title":"Further info on anaconda","text":"

    New heavy packages

    It may happen that creating a new Conda environment, populated with selected packages at the moment of creation takes less time than installing a large, heavy library or application, into previously set environment.

    pip install within conda

    The documentation of conda says that pip should NOT be used within conda, because internal problems can occur. However, they are rare. Anaconda Blogpost

    Nevertheless, that is why, the conda-forge channel is preferred:

    • more libraries are available (less need for pip)
    • conda-forge works better with pip
    • the libraries are newer

    Happy trading!

    "},{"location":"installation/#you-are-ready","title":"You are ready","text":"

    You've made it this far, so you have successfully installed freqtrade.

    "},{"location":"installation/#initialize-the-configuration","title":"Initialize the configuration","text":"
    # Step 1 - Initialize user folder\nfreqtrade create-userdir --userdir user_data\n\n# Step 2 - Create a new configuration file\nfreqtrade new-config --config user_data/config.json\n

    You are ready to run, read Bot Configuration, remember to start with dry_run: True and verify that everything is working.

    To learn how to setup your configuration, please refer to the Bot Configuration documentation page.

    "},{"location":"installation/#start-the-bot","title":"Start the Bot","text":"
    freqtrade trade --config user_data/config.json --strategy SampleStrategy\n

    Warning

    You should read through the rest of the documentation, backtest the strategy you're going to use, and use dry-run before enabling trading with real money.

    "},{"location":"installation/#troubleshooting","title":"Troubleshooting","text":""},{"location":"installation/#common-problem-command-not-found","title":"Common problem: \"command not found\"","text":"

    If you used (1)Script or (2)Manual installation, you need to run the bot in virtual environment. If you get error as below, make sure venv is active.

    # if:\nbash: freqtrade: command not found\n\n# then activate your virtual environment\nsource ./.venv/bin/activate\n
    "},{"location":"installation/#macos-installation-error","title":"MacOS installation error","text":"

    Newer versions of MacOS may have installation failed with errors like error: command 'g++' failed with exit status 1.

    This error will require explicit installation of the SDK Headers, which are not installed by default in this version of MacOS. For MacOS 10.14, this can be accomplished with the below command.

    open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg\n

    If this file is inexistent, then you're probably on a different version of MacOS, so you may need to consult the internet for specific resolution details.

    "},{"location":"leverage/","title":"Trading with Leverage","text":"

    Beta feature

    This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.

    Multiple bots on one account

    You can't run 2 bots on the same account with leverage. For leveraged / margin trading, freqtrade assumes it's the only user of the account, and all liquidation levels are calculated based on this assumption.

    Trading with leverage is very risky

    Do not trade with a leverage > 1 using a strategy that hasn't shown positive results in a live run using the spot market. Check the stoploss of your strategy. With a leverage of 2, a stoploss of 0.5 (50%) would be too low, and these trades would be liquidated before reaching that stoploss. We do not assume any responsibility for eventual losses that occur from using this software or this mode.

    Please only use advanced trading modes when you know how freqtrade (and your strategy) works. Also, never risk more than what you can afford to lose.

    If you already have an existing strategy, please read the strategy migration guide to migrate your strategy from a freqtrade v2 strategy, to strategy of version 3 which can short and trade futures.

    "},{"location":"leverage/#shorting","title":"Shorting","text":"

    Shorting is not possible when trading with trading_mode set to spot. To short trade, trading_mode must be set to margin(currently unavailable) or futures, with margin_mode set to cross(currently unavailable) or isolated

    For a strategy to short, the strategy class must set the class variable can_short = True

    Please read strategy customization for instructions on how to set signals to enter and exit short trades.

    "},{"location":"leverage/#understand-trading_mode","title":"Understand trading_mode","text":"

    The possible values are: spot (default), margin(Currently unavailable) or futures.

    "},{"location":"leverage/#spot","title":"Spot","text":"

    Regular trading mode (low risk)

    • Long trades only (No short trades).
    • No leverage.
    • No Liquidation.
    • Profits gained/lost are equal to the change in value of the assets (minus trading fees).
    "},{"location":"leverage/#leverage-trading-modes","title":"Leverage trading modes","text":"

    With leverage, a trader borrows capital from the exchange. The capital must be re-payed fully to the exchange (potentially with interest), and the trader keeps any profits, or pays any losses, from any trades made using the borrowed capital.

    Because the capital must always be re-payed, exchanges will liquidate (forcefully sell the traders assets) a trade made using borrowed capital when the total value of assets in the leverage account drops to a certain point (a point where the total value of losses is less than the value of the collateral that the trader actually owns in the leverage account), in order to ensure that the trader has enough capital to pay the borrowed assets back to the exchange. The exchange will also charge a liquidation fee, adding to the traders losses.

    For this reason, DO NOT TRADE WITH LEVERAGE IF YOU DON'T KNOW EXACTLY WHAT YOUR DOING. LEVERAGE TRADING IS HIGH RISK, AND CAN RESULT IN THE VALUE OF YOUR ASSETS DROPPING TO 0 VERY QUICKLY, WITH NO CHANCE OF INCREASING IN VALUE AGAIN.

    "},{"location":"leverage/#margin-currently-unavailable","title":"Margin (currently unavailable)","text":"

    Trading occurs on the spot market, but the exchange lends currency to you in an amount equal to the chosen leverage. You pay the amount lent to you back to the exchange with interest, and your profits/losses are multiplied by the leverage specified.

    "},{"location":"leverage/#futures","title":"Futures","text":"

    Perpetual swaps (also known as Perpetual Futures) are contracts traded at a price that is closely tied to the underlying asset they are based off of (ex.). You are not trading the actual asset but instead are trading a derivative contract. Perpetual swap contracts can last indefinitely, in contrast to futures or option contracts.

    In addition to the gains/losses from the change in price of the futures contract, traders also exchange funding fees, which are gains/losses worth an amount that is derived from the difference in price between the futures contract and the underlying asset. The difference in price between a futures contract and the underlying asset varies between exchanges.

    To trade in futures markets, you'll have to set trading_mode to \"futures\". You will also have to pick a \"margin mode\" (explanation below) - with freqtrade currently only supporting isolated margin.

    \"trading_mode\": \"futures\",\n\"margin_mode\": \"isolated\"\n
    "},{"location":"leverage/#pair-namings","title":"Pair namings","text":"

    Freqtrade follows the ccxt naming conventions for futures. A futures pair will therefore have the naming of base/quote:settle (e.g. ETH/USDT:USDT).

    "},{"location":"leverage/#margin-mode","title":"Margin mode","text":"

    On top of trading_mode - you will also have to configure your margin_mode. While freqtrade currently only supports one margin mode, this will change, and by configuring it now you're all set for future updates.

    The possible values are: isolated, or cross(currently unavailable).

    "},{"location":"leverage/#isolated-margin-mode","title":"Isolated margin mode","text":"

    Each market(trading pair), keeps collateral in a separate account

    \"margin_mode\": \"isolated\"\n
    "},{"location":"leverage/#cross-margin-mode-currently-unavailable","title":"Cross margin mode (currently unavailable)","text":"

    One account is used to share collateral between markets (trading pairs). Margin is taken from total account balance to avoid liquidation when needed.

    \"margin_mode\": \"cross\"\n

    Please read the exchange specific notes for exchanges that support this mode and how they differ.

    "},{"location":"leverage/#set-leverage-to-use","title":"Set leverage to use","text":"

    Different strategies and risk profiles will require different levels of leverage. While you could configure one static leverage value - freqtrade offers you the flexibility to adjust this via strategy leverage callback - which allows you to use different leverages by pair, or based on some other factor benefitting your strategy result.

    If not implemented, leverage defaults to 1x (no leverage).

    Warning

    Higher leverage also equals higher risk - be sure you fully understand the implications of using leverage!

    "},{"location":"leverage/#understand-liquidation_buffer","title":"Understand liquidation_buffer","text":"

    Defaults to 0.05

    A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price. This artificial liquidation price is calculated as:

    freqtrade_liquidation_price = liquidation_price \u00b1 (abs(open_rate - liquidation_price) * liquidation_buffer)

    • \u00b1 = + for long trades
    • \u00b1 = - for short trades

    Possible values are any floats between 0.0 and 0.99

    ex: If a trade is entered at a price of 10 coin/USDT, and the liquidation price of this trade is 8 coin/USDT, then with liquidation_buffer set to 0.05 the minimum stoploss for this trade would be \\(8 + ((10 - 8) * 0.05) = 8 + 0.1 = 8.1\\)

    A liquidation_buffer of 0.0, or a low liquidation_buffer is likely to result in liquidations, and liquidation fees

    Currently Freqtrade is able to calculate liquidation prices, but does not calculate liquidation fees. Setting your liquidation_buffer to 0.0, or using a low liquidation_buffer could result in your positions being liquidated. Freqtrade does not track liquidation fees, so liquidations will result in inaccurate profit/loss results for your bot. If you use a low liquidation_buffer, it is recommended to use stoploss_on_exchange if your exchange supports this.

    "},{"location":"leverage/#unavailable-funding-rates","title":"Unavailable funding rates","text":"

    For futures data, exchanges commonly provide the futures candles, the marks, and the funding rates. However, it is common that whilst candles and marks might be available, the funding rates are not. This can affect backtesting timeranges, i.e. you may only be able to test recent timeranges and not earlier, experiencing the No data found. Terminating. error. To get around this, add the futures_funding_rate config option as listed in configuration.md, and it is recommended that you set this to 0, unless you know a given specific funding rate for your pair, exchange and timerange. Setting this to anything other than 0 can have drastic effects on your profit calculations within strategy, e.g. within the custom_exit, custom_stoploss, etc functions.

    This will mean your backtests are inaccurate.

    This will not overwrite funding rates that are available from the exchange, but bear in mind that setting a false funding rate will mean backtesting results will be inaccurate for historical timeranges where funding rates are not available.

    "},{"location":"leverage/#developer","title":"Developer","text":""},{"location":"leverage/#margin-mode_1","title":"Margin mode","text":"

    For shorts, the currency which pays the interest fee for the borrowed currency is purchased at the same time of the closing trade (This means that the amount purchased in short closing trades is greater than the amount sold in short opening trades).

    For longs, the currency which pays the interest fee for the borrowed will already be owned by the user and does not need to be purchased. The interest is subtracted from the close_value of the trade.

    All Fees are included in current_profit calculations during the trade.

    "},{"location":"leverage/#futures-mode","title":"Futures mode","text":"

    Funding fees are either added or subtracted from the total amount of a trade

    "},{"location":"lookahead-analysis/","title":"Lookahead analysis","text":"

    This page explains how to validate your strategy in terms of look ahead bias.

    Checking look ahead bias is the bane of any strategy since it is sometimes very easy to introduce backtest bias - but very hard to detect.

    Backtesting initializes all timestamps at once and calculates all indicators in the beginning. This means that if your indicators or entry/exit signals could look into future candles and falsify your backtest.

    Lookahead-analysis requires historic data to be available. To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    This command is built upon backtesting since it internally chains backtests and pokes at the strategy to provoke it to show look ahead bias. This is done by not looking at the strategy itself - but at the results it returned. The results are things like changed indicator-values and moved entries/exits compared to the full backtest.

    You can use commands of Backtesting. It also supports the lookahead-analysis of freqai strategies.

    • --cache is forced to \"none\".
    • --max-open-trades is forced to be at least equal to the number of pairs.
    • --dry-run-wallet is forced to be basically infinite (1 billion).
    • --stake-amount is forced to be a static 10000 (10k).
    • --enable-protections is forced to be off.

    Those are set to avoid users accidentally generating false positives.

    "},{"location":"lookahead-analysis/#lookahead-analysis-command-reference","title":"Lookahead-analysis command reference","text":"
    usage: freqtrade lookahead-analysis [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                    [-d PATH] [--userdir PATH] [-s NAME]\n                                    [--strategy-path PATH]\n                                    [--recursive-strategy-search]\n                                    [--freqaimodel NAME]\n                                    [--freqaimodel-path PATH] [-i TIMEFRAME]\n                                    [--timerange TIMERANGE]\n                                    [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                                    [--max-open-trades INT]\n                                    [--stake-amount STAKE_AMOUNT]\n                                    [--fee FLOAT] [-p PAIRS [PAIRS ...]]\n                                    [--dry-run-wallet DRY_RUN_WALLET]\n                                    [--timeframe-detail TIMEFRAME_DETAIL]\n                                    [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]\n                                    [--export {none,trades,signals}]\n                                    [--export-filename PATH]\n                                    [--breakdown {day,week,month} [{day,week,month} ...]]\n                                    [--cache {none,day,week,month}]\n                                    [--freqai-backtest-live-models]\n                                    [--minimum-trade-amount INT]\n                                    [--targeted-trade-amount INT]\n                                    [--lookahead-analysis-exportfilename LOOKAHEAD_ANALYSIS_EXPORTFILENAME]\n\noptions:\n  --minimum-trade-amount INT\n                        Minimum trade amount for lookahead-analysis\n  --targeted-trade-amount INT\n                        Targeted trade amount for lookahead analysis\n  --lookahead-analysis-exportfilename LOOKAHEAD_ANALYSIS_EXPORTFILENAME\n                        Use this csv-filename to store lookahead-analysis-\n                        results\n

    The above Output was reduced to options lookahead-analysis adds on top of regular backtesting commands.

    "},{"location":"lookahead-analysis/#summary","title":"Summary","text":"

    Checks a given strategy for look ahead bias via lookahead-analysis Look ahead bias means that the backtest uses data from future candles thereby not making it viable beyond backtesting and producing false hopes for the one backtesting.

    "},{"location":"lookahead-analysis/#introduction","title":"Introduction","text":"

    Many strategies - without the programmer knowing - have fallen prey to look ahead bias.

    Any backtest will populate the full dataframe including all time stamps at the beginning. If the programmer is not careful or oblivious how things work internally (which sometimes can be really hard to find out) then it will just look into the future making the strategy amazing but not realistic.

    This command is made to try to verify the validity in the form of the aforementioned look ahead bias.

    "},{"location":"lookahead-analysis/#how-does-the-command-work","title":"How does the command work?","text":"

    It will start with a backtest of all pairs to generate a baseline for indicators and entries/exits. After the backtest ran, it will look if the minimum-trade-amount is met and if not cancel the lookahead-analysis for this strategy.

    After setting the baseline it will then do additional runs for every entry and exit separately. When a verification-backtest is done, it will compare the indicators as the signal (either entry or exit) and report the bias. After all signals have been verified or falsified a result-table will be generated for the user to see.

    "},{"location":"lookahead-analysis/#caveats","title":"Caveats","text":"
    • lookahead-analysis can only verify / falsify the trades it calculated and verified. If the strategy has many different signals / signal types, it's up to you to select appropriate parameters to ensure that all signals have triggered at least once. Not triggered signals will not have been verified. This could lead to a false-negative (the strategy will then be reported as non-biased).
    • lookahead-analysis has access to everything that backtesting has too. Please don't provoke any configs like enabling position stacking. If you decide to do so, then make doubly sure that you won't ever run out of max_open_trades amount and neither leftover money in your wallet.
    "},{"location":"plotting/","title":"Plotting","text":"

    This page explains how to plot prices, indicators and profits.

    Deprecated

    The commands described in this page (plot-dataframe, plot-profit) should be considered deprecated and are in maintenance mode. This is mostly for the performance problems even medium sized plots can cause, but also because \"store a file and open it in a browser\" isn't very intuitive from a UI perspective.

    While there are no immediate plans to remove them, they are not actively maintained - and may be removed short-term should major changes be required to keep them working.

    Please use FreqUI for plotting needs, which doesn't struggle with the same performance problems.

    "},{"location":"plotting/#installation-setup","title":"Installation / Setup","text":"

    Plotting modules use the Plotly library. You can install / upgrade this by running the following command:

    pip install -U -r requirements-plot.txt\n
    "},{"location":"plotting/#plot-price-and-indicators","title":"Plot price and indicators","text":"

    The freqtrade plot-dataframe subcommand shows an interactive graph with three subplots:

    • Main plot with candlesticks and indicators following price (sma/ema)
    • Volume bars
    • Additional indicators as specified by --indicators2

    Possible arguments:

    usage: freqtrade plot-dataframe [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                [-d PATH] [--userdir PATH] [-s NAME]\n                                [--strategy-path PATH] [-p PAIRS [PAIRS ...]]\n                                [--indicators1 INDICATORS1 [INDICATORS1 ...]]\n                                [--indicators2 INDICATORS2 [INDICATORS2 ...]]\n                                [--plot-limit INT] [--db-url PATH]\n                                [--trade-source {DB,file}] [--export EXPORT]\n                                [--export-filename PATH]\n                                [--timerange TIMERANGE] [-i TIMEFRAME]\n                                [--no-trades]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --indicators1 INDICATORS1 [INDICATORS1 ...]\n                        Set indicators from your strategy you want in the\n                        first row of the graph. Space-separated list. Example:\n                        `ema3 ema5`. Default: `['sma', 'ema3', 'ema5']`.\n  --indicators2 INDICATORS2 [INDICATORS2 ...]\n                        Set indicators from your strategy you want in the\n                        third row of the graph. Space-separated list. Example:\n                        `fastd fastk`. Default: `['macd', 'macdsignal']`.\n  --plot-limit INT      Specify tick limit for plotting. Notice: too high\n                        values cause huge files. Default: 750.\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --trade-source {DB,file}\n                        Specify the source for trades (Can be DB or file\n                        (backtest file)) Default: file\n  --export EXPORT       Export backtest results, argument are: trades.\n                        Example: `--export=trades`\n  --export-filename PATH\n                        Save backtest results to the file with this filename.\n                        Requires `--export` to be set as well. Example:\n                        `--export-filename=user_data/backtest_results/backtest\n                        _today.json`\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --no-trades           Skip using trades from backtesting file and DB.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n

    Example:

    freqtrade plot-dataframe -p BTC/ETH --strategy AwesomeStrategy\n

    The -p/--pairs argument can be used to specify pairs you would like to plot.

    Note

    The freqtrade plot-dataframe subcommand generates one plot-file per pair.

    Specify custom indicators. Use --indicators1 for the main plot and --indicators2 for the subplot below (if values are in a different range than prices).

    freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --indicators1 sma ema --indicators2 macd\n
    "},{"location":"plotting/#further-usage-examples","title":"Further usage examples","text":"

    To plot multiple pairs, separate them with a space:

    freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH XRP/ETH\n

    To plot a timerange (to zoom in)

    freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805\n

    To plot trades stored in a database use --db-url in combination with --trade-source DB:

    freqtrade plot-dataframe --strategy AwesomeStrategy --db-url sqlite:///tradesv3.dry_run.sqlite -p BTC/ETH --trade-source DB\n

    To plot trades from a backtesting result, use --export-filename <filename>

    freqtrade plot-dataframe --strategy AwesomeStrategy --export-filename user_data/backtest_results/backtest-result.json -p BTC/ETH\n
    "},{"location":"plotting/#plot-dataframe-basics","title":"Plot dataframe basics","text":"

    The plot-dataframe subcommand requires backtesting data, a strategy and either a backtesting-results file or a database, containing trades corresponding to the strategy.

    The resulting plot will have the following elements:

    • Green triangles: Buy signals from the strategy. (Note: not every buy signal generates a trade, compare to cyan circles.)
    • Red triangles: Sell signals from the strategy. (Also, not every sell signal terminates a trade, compare to red and green squares.)
    • Cyan circles: Trade entry points.
    • Red squares: Trade exit points for trades with loss or 0% profit.
    • Green squares: Trade exit points for profitable trades.
    • Indicators with values corresponding to the candle scale (e.g. SMA/EMA), as specified with --indicators1.
    • Volume (bar chart at the bottom of the main chart).
    • Indicators with values in different scales (e.g. MACD, RSI) below the volume bars, as specified with --indicators2.

    Bollinger Bands

    Bollinger bands are automatically added to the plot if the columns bb_lowerband and bb_upperband exist, and are painted as a light blue area spanning from the lower band to the upper band.

    "},{"location":"plotting/#advanced-plot-configuration","title":"Advanced plot configuration","text":"

    An advanced plot configuration can be specified in the strategy in the plot_config parameter.

    Additional features when using plot_config include:

    • Specify colors per indicator
    • Specify additional subplots
    • Specify indicator pairs to fill area in between

    The sample plot configuration below specifies fixed colors for the indicators. Otherwise, consecutive plots may produce different color schemes each time, making comparisons difficult. It also allows multiple subplots to display both MACD and RSI at the same time.

    Plot type can be configured using type key. Possible types are:

    • scatter corresponding to plotly.graph_objects.Scatter class (default).
    • bar corresponding to plotly.graph_objects.Bar class.

    Extra parameters to plotly.graph_objects.* constructor can be specified in plotly dict.

    Sample configuration with inline comments explaining the process:

    @property\ndef plot_config(self):\n    \"\"\"\n        There are a lot of solutions how to build the return dictionary.\n        The only important point is the return value.\n        Example:\n            plot_config = {'main_plot': {}, 'subplots': {}}\n\n    \"\"\"\n    plot_config = {}\n    plot_config['main_plot'] = {\n        # Configuration for main plot indicators.\n        # Assumes 2 parameters, emashort and emalong to be specified.\n        f'ema_{self.emashort.value}': {'color': 'red'},\n        f'ema_{self.emalong.value}': {'color': '#CCCCCC'},\n        # By omitting color, a random color is selected.\n        'sar': {},\n        # fill area between senkou_a and senkou_b\n        'senkou_a': {\n            'color': 'green', #optional\n            'fill_to': 'senkou_b',\n            'fill_label': 'Ichimoku Cloud', #optional\n            'fill_color': 'rgba(255,76,46,0.2)', #optional\n        },\n        # plot senkou_b, too. Not only the area to it.\n        'senkou_b': {}\n    }\n    plot_config['subplots'] = {\n         # Create subplot MACD\n        \"MACD\": {\n            'macd': {'color': 'blue', 'fill_to': 'macdhist'},\n            'macdsignal': {'color': 'orange'},\n            'macdhist': {'type': 'bar', 'plotly': {'opacity': 0.9}}\n        },\n        # Additional subplot RSI\n        \"RSI\": {\n            'rsi': {'color': 'red'}\n        }\n    }\n\n    return plot_config\n
    As attribute (former method)

    Assigning plot_config is also possible as Attribute (this used to be the default way). This has the disadvantage that strategy parameters are not available, preventing certain configurations from working.

        plot_config = {\n        'main_plot': {\n            # Configuration for main plot indicators.\n            # Specifies `ema10` to be red, and `ema50` to be a shade of gray\n            'ema10': {'color': 'red'},\n            'ema50': {'color': '#CCCCCC'},\n            # By omitting color, a random color is selected.\n            'sar': {},\n        # fill area between senkou_a and senkou_b\n        'senkou_a': {\n            'color': 'green', #optional\n            'fill_to': 'senkou_b',\n            'fill_label': 'Ichimoku Cloud', #optional\n            'fill_color': 'rgba(255,76,46,0.2)', #optional\n        },\n        # plot senkou_b, too. Not only the area to it.\n        'senkou_b': {}\n        },\n        'subplots': {\n            # Create subplot MACD\n            \"MACD\": {\n                'macd': {'color': 'blue', 'fill_to': 'macdhist'},\n                'macdsignal': {'color': 'orange'},\n                'macdhist': {'type': 'bar', 'plotly': {'opacity': 0.9}}\n            },\n            # Additional subplot RSI\n            \"RSI\": {\n                'rsi': {'color': 'red'}\n            }\n        }\n    }\n

    Note

    The above configuration assumes that ema10, ema50, senkou_a, senkou_b, macd, macdsignal, macdhist and rsi are columns in the DataFrame created by the strategy.

    Warning

    plotly arguments are only supported with plotly library and will not work with freq-ui.

    Trade position adjustments

    If position_adjustment_enable / adjust_trade_position() is used, the trade initial buy price is averaged over multiple orders and the trade start price will most likely appear outside the candle range.

    "},{"location":"plotting/#plot-profit","title":"Plot profit","text":"

    The plot-profit subcommand shows an interactive graph with three plots:

    • Average closing price for all pairs.
    • The summarized profit made by backtesting. Note that this is not the real-world profit, but more of an estimate.
    • Profit for each individual pair.
    • Parallelism of trades.
    • Underwater (Periods of drawdown).

    The first graph is good to get a grip of how the overall market progresses.

    The second graph will show if your algorithm works or doesn't. Perhaps you want an algorithm that steadily makes small profits, or one that acts less often, but makes big swings. This graph will also highlight the start (and end) of the Max drawdown period.

    The third graph can be useful to spot outliers, events in pairs that cause profit spikes.

    The forth graph can help you analyze trade parallelism, showing how often max_open_trades have been maxed out.

    Possible options for the freqtrade plot-profit subcommand:

    usage: freqtrade plot-profit [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                             [-d PATH] [--userdir PATH] [-s NAME]\n                             [--strategy-path PATH] [-p PAIRS [PAIRS ...]]\n                             [--timerange TIMERANGE] [--export EXPORT]\n                             [--export-filename PATH] [--db-url PATH]\n                             [--trade-source {DB,file}] [-i TIMEFRAME]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --export EXPORT       Export backtest results, argument are: trades.\n                        Example: `--export=trades`\n  --export-filename PATH, --backtest-filename PATH\n                        Use backtest results from this filename.\n                        Requires `--export` to be set as well. Example:\n                        `--export-filename=user_data/backtest_results/backtest\n                        _today.json`\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --trade-source {DB,file}\n                        Specify the source for trades (Can be DB or file\n                        (backtest file)) Default: file\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --auto-open           Automatically open generated plot.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n

    The -p/--pairs argument, can be used to limit the pairs that are considered for this calculation.

    Examples:

    Use custom backtest-export file

    freqtrade plot-profit  -p LTC/BTC --export-filename user_data/backtest_results/backtest-result.json\n

    Use custom database

    freqtrade plot-profit  -p LTC/BTC --db-url sqlite:///tradesv3.sqlite --trade-source DB\n
    freqtrade --datadir user_data/data/binance_save/ plot-profit -p LTC/BTC\n
    "},{"location":"plugins/","title":"Plugins","text":""},{"location":"plugins/#pairlists-and-pairlist-handlers","title":"Pairlists and Pairlist Handlers","text":"

    Pairlist Handlers define the list of pairs (pairlist) that the bot should trade. They are configured in the pairlists section of the configuration settings.

    In your configuration, you can use Static Pairlist (defined by the StaticPairList Pairlist Handler) and Dynamic Pairlist (defined by the VolumePairList and PercentChangePairList Pairlist Handlers).

    Additionally, AgeFilter, PrecisionFilter, PriceFilter, ShuffleFilter, SpreadFilter and VolatilityFilter act as Pairlist Filters, removing certain pairs and/or moving their positions in the pairlist.

    If multiple Pairlist Handlers are used, they are chained and a combination of all Pairlist Handlers forms the resulting pairlist the bot uses for trading and backtesting. Pairlist Handlers are executed in the sequence they are configured. You can define either StaticPairList, VolumePairList, ProducerPairList, RemotePairList, MarketCapPairList or PercentChangePairList as the starting Pairlist Handler.

    Inactive markets are always removed from the resulting pairlist. Explicitly blacklisted pairs (those in the pair_blacklist configuration setting) are also always removed from the resulting pairlist.

    "},{"location":"plugins/#pair-blacklist","title":"Pair blacklist","text":"

    The pair blacklist (configured via exchange.pair_blacklist in the configuration) disallows certain pairs from trading. This can be as simple as excluding DOGE/BTC - which will remove exactly this pair.

    The pair-blacklist does also support wildcards (in regex-style) - so BNB/.* will exclude ALL pairs that start with BNB. You may also use something like .*DOWN/BTC or .*UP/BTC to exclude leveraged tokens (check Pair naming conventions for your exchange!)

    "},{"location":"plugins/#available-pairlist-handlers","title":"Available Pairlist Handlers","text":"
    • StaticPairList (default, if not configured differently)
    • VolumePairList
    • PercentChangePairList
    • ProducerPairList
    • RemotePairList
    • MarketCapPairList
    • AgeFilter
    • FullTradesFilter
    • OffsetFilter
    • PerformanceFilter
    • PrecisionFilter
    • PriceFilter
    • ShuffleFilter
    • SpreadFilter
    • RangeStabilityFilter
    • VolatilityFilter

    Testing pairlists

    Pairlist configurations can be quite tricky to get right. Best use the test-pairlist utility sub-command to test your configuration quickly.

    "},{"location":"plugins/#static-pair-list","title":"Static Pair List","text":"

    By default, the StaticPairList method is used, which uses a statically defined pair whitelist from the configuration. The pairlist also supports wildcards (in regex-style) - so .*/BTC will include all pairs with BTC as a stake.

    It uses configuration from exchange.pair_whitelist and exchange.pair_blacklist.

    \"pairlists\": [\n    {\"method\": \"StaticPairList\"}\n],\n

    By default, only currently enabled pairs are allowed. To skip pair validation against active markets, set \"allow_inactive\": true within the StaticPairList configuration. This can be useful for backtesting expired pairs (like quarterly spot-markets). This option must be configured along with exchange.skip_pair_validation in the exchange configuration.

    When used in a \"follow-up\" position (e.g. after VolumePairlist), all pairs in 'pair_whitelist' will be added to the end of the pairlist.

    "},{"location":"plugins/#volume-pair-list","title":"Volume Pair List","text":"

    VolumePairList employs sorting/filtering of pairs by their trading volume. It selects number_assets top pairs with sorting based on the sort_key (which can only be quoteVolume).

    When used in the chain of Pairlist Handlers in a non-leading position (after StaticPairList and other Pairlist Filters), VolumePairList considers outputs of previous Pairlist Handlers, adding its sorting/selection of the pairs by the trading volume.

    When used in the leading position of the chain of Pairlist Handlers, the pair_whitelist configuration setting is ignored. Instead, VolumePairList selects the top assets from all available markets with matching stake-currency on the exchange.

    The refresh_period setting allows to define the period (in seconds), at which the pairlist will be refreshed. Defaults to 1800s (30 minutes). The pairlist cache (refresh_period) on VolumePairList is only applicable to generating pairlists. Filtering instances (not the first position in the list) will not apply any cache (beyond caching candles for the duration of the candle in advanced mode) and will always use up-to-date data.

    VolumePairList is per default based on the ticker data from exchange, as reported by the ccxt library:

    • The quoteVolume is the amount of quote (stake) currency traded (bought or sold) in last 24 hours.
    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"max_value\": 8000000,\n        \"refresh_period\": 1800\n    }\n],\n

    You can define a minimum volume with min_value - which will filter out pairs with a volume lower than the specified value in the specified timerange. In addition to that, you can also define a maximum volume with max_value - which will filter out pairs with a volume higher than the specified value in the specified timerange.

    "},{"location":"plugins/#volumepairlist-advanced-mode","title":"VolumePairList Advanced mode","text":"

    VolumePairList can also operate in an advanced mode to build volume over a given timerange of specified candle size. It utilizes exchange historical candle data, builds a typical price (calculated by (open+high+low)/3) and multiplies the typical price with every candle's volume. The sum is the quoteVolume over the given range. This allows different scenarios, for a more smoothened volume, when using longer ranges with larger candle sizes, or the opposite when using a short range with small candles.

    For convenience lookback_days can be specified, which will imply that 1d candles will be used for the lookback. In the example below the pairlist would be created based on the last 7 days:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 7\n    }\n],\n

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range based volume can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with VolumeFilter to narrow the pairlist down for further range volume calculation.

    Unsupported exchanges

    On some exchanges (like Gemini), regular VolumePairList does not work as the api does not natively provide 24h volume. This can be worked around by using candle data to build the volume. To roughly simulate 24h volume, you can use the following configuration. Please note that These pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    More sophisticated approach can be used, by using lookback_timeframe for candle size and lookback_period which specifies the amount of candles. This example will build the volume pairs based on a rolling period of 3 days of 1h candles:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    Note

    VolumePairList does not support backtesting mode.

    "},{"location":"plugins/#percent-change-pair-list","title":"Percent Change Pair List","text":"

    PercentChangePairList filters and sorts pairs based on the percentage change in their price over the last 24 hours or any defined timeframe as part of advanced options. This allows traders to focus on assets that have experienced significant price movements, either positive or negative.

    Configuration Options

    • number_assets: Specifies the number of top pairs to select based on the 24-hour percentage change.
    • min_value: Sets a minimum percentage change threshold. Pairs with a percentage change below this value will be filtered out.
    • max_value: Sets a maximum percentage change threshold. Pairs with a percentage change above this value will be filtered out.
    • sort_direction: Specifies the order in which pairs are sorted based on their percentage change. Accepts two values: asc for ascending order and desc for descending order.
    • refresh_period: Defines the interval (in seconds) at which the pairlist will be refreshed. The default is 1800 seconds (30 minutes).
    • lookback_days: Number of days to look back. When lookback_days is selected, the lookback_timeframe is defaulted to 1 day.
    • lookback_timeframe: Timeframe to use for the lookback period.
    • lookback_period: Number of periods to look back at.

    When PercentChangePairList is used after other Pairlist Handlers, it will operate on the outputs of those handlers. If it is the leading Pairlist Handler, it will select pairs from all available markets with the specified stake currency.

    PercentChangePairList uses ticker data from the exchange, provided via the ccxt library: The percentage change is calculated as the change in price over the last 24 hours.

    Unsupported exchanges

    On some exchanges (like HTX), regular PercentChangePairList does not work as the api does not natively provide 24h percent change in price. This can be worked around by using candle data to calculate the percentage change. To roughly simulate 24h percent change, you can use the following configuration. Please note that these pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 20,\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    Example Configuration to Read from Ticker

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"min_value\": -10,\n        \"max_value\": 50\n    }\n],\n

    In this configuration:

    1. The top 15 pairs are selected based on the highest percentage change in price over the last 24 hours.
    2. Only pairs with a percentage change between -10% and 50% are considered.

    Example Configuration to Read from Candles

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"sort_key\": \"percentage\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    This example builds the percent change pairs based on a rolling period of 3 days of 1-hour candles by using lookback_timeframe for candle size and lookback_period which specifies the number of candles.

    The percent change in price is calculated using the following formula, which expresses the percentage difference between the current candle's close price and the previous candle's close price, as defined by the specified timeframe and lookback period:

    \\[ Percent Change = (\\frac{Current Close - Previous Close}{Previous Close}) * 100 \\]

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range-based percent change can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with PercentChangePairList to narrow the pairlist down for further percent-change calculation.

    Backtesting

    PercentChangePairList does not support backtesting mode.

    "},{"location":"plugins/#producerpairlist","title":"ProducerPairList","text":"

    With ProducerPairList, you can reuse the pairlist from a Producer without explicitly defining the pairlist on each consumer.

    Consumer mode is required for this pairlist to work.

    The pairlist will perform a check on active pairs against the current exchange configuration to avoid attempting to trade on invalid markets.

    You can limit the length of the pairlist with the optional parameter number_assets. Using \"number_assets\"=0 or omitting this key will result in the reuse of all producer pairs valid for the current setup.

    \"pairlists\": [\n    {\n        \"method\": \"ProducerPairList\",\n        \"number_assets\": 5,\n        \"producer_name\": \"default\",\n    }\n],\n

    Combining pairlists

    This pairlist can be combined with all other pairlists and filters for further pairlist reduction, and can also act as an \"additional\" pairlist, on top of already defined pairs. ProducerPairList can also be used multiple times in sequence, combining the pairs from multiple producers. Obviously in complex such configurations, the Producer may not provide data for all pairs, so the strategy must be fit for this.

    "},{"location":"plugins/#remotepairlist","title":"RemotePairList","text":"

    It allows the user to fetch a pairlist from a remote server or a locally stored json file within the freqtrade directory, enabling dynamic updates and customization of the trading pairlist.

    The RemotePairList is defined in the pairlists section of the configuration settings. It uses the following configuration options:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"processing_mode\": \"filter\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"bearer_token\": \"my-bearer-token\",\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    The optional mode option specifies if the pairlist should be used as a blacklist or as a whitelist. The default value is \"whitelist\".

    The optional processing_mode option in the RemotePairList configuration determines how the retrieved pairlist is processed. It can have two values: \"filter\" or \"append\". The default value is \"filter\".

    In \"filter\" mode, the retrieved pairlist is used as a filter. Only the pairs present in both the original pairlist and the retrieved pairlist are included in the final pairlist. Other pairs are filtered out.

    In \"append\" mode, the retrieved pairlist is added to the original pairlist. All pairs from both lists are included in the final pairlist without any filtering.

    The pairlist_url option specifies the URL of the remote server where the pairlist is located, or the path to a local file (if file:/// is prepended). This allows the user to use either a remote server or a local file as the source for the pairlist.

    The save_to_file option, when provided with a valid filename, saves the processed pairlist to that file in JSON format. This option is optional, and by default, the pairlist is not saved to a file.

    Multi bot with shared pairlist example

    save_to_file can be used to save the pairlist to a file with Bot1:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    This saved pairlist file can be loaded by Bot2, or any additional bot with this configuration:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"file:///user_data/filename.json\",\n        \"number_assets\": 10,\n        \"refresh_period\": 10,\n        \"keep_pairlist_on_failure\": true,\n    }\n]\n

    The user is responsible for providing a server or local file that returns a JSON object with the following structure:

    {\n    \"pairs\": [\"XRP/USDT\", \"ETH/USDT\", \"LTC/USDT\"],\n    \"refresh_period\": 1800\n}\n

    The pairs property should contain a list of strings with the trading pairs to be used by the bot. The refresh_period property is optional and specifies the number of seconds that the pairlist should be cached before being refreshed.

    The optional keep_pairlist_on_failure specifies whether the previous received pairlist should be used if the remote server is not reachable or returns an error. The default value is true.

    The optional read_timeout specifies the maximum amount of time (in seconds) to wait for a response from the remote source, The default value is 60.

    The optional bearer_token will be included in the requests Authorization Header.

    Note

    In case of a server error the last received pairlist will be kept if keep_pairlist_on_failure is set to true, when set to false a empty pairlist is returned.

    "},{"location":"plugins/#marketcappairlist","title":"MarketCapPairList","text":"

    MarketCapPairList employs sorting/filtering of pairs by their marketcap rank based of CoinGecko. It will only recognize coins up to the coin placed at rank 250. The returned pairlist will be sorted based of their marketcap ranks.

    \"pairlists\": [\n    {\n        \"method\": \"MarketCapPairList\",\n        \"number_assets\": 20,\n        \"max_rank\": 50,\n        \"refresh_period\": 86400\n    }\n]\n

    number_assets defines the maximum number of pairs returned by the pairlist. max_rank will determine the maximum rank used in creating/filtering the pairlist. It's expected that some coins within the top max_rank marketcap will not be included in the resulting pairlist since not all pairs will have active trading pairs in your preferred market/stake/exchange combination.

    refresh_period setting defines the period (in seconds) at which the marketcap rank data will be refreshed. Defaults to 86,400s (1 day). The pairlist cache (refresh_period) is applicable on both generating pairlists (first position in the list) and filtering instances (not the first position in the list).

    "},{"location":"plugins/#agefilter","title":"AgeFilter","text":"

    Removes pairs that have been listed on the exchange for less than min_days_listed days (defaults to 10) or more than max_days_listed days (defaults None mean infinity).

    When pairs are first listed on an exchange they can suffer huge price drops and volatility in the first few days while the pair goes through its price-discovery period. Bots can often be caught out buying before the pair has finished dropping in price.

    This filter allows freqtrade to ignore pairs until they have been listed for at least min_days_listed days and listed before max_days_listed.

    "},{"location":"plugins/#fulltradesfilter","title":"FullTradesFilter","text":"

    Shrink whitelist to consist only in-trade pairs when the trade slots are full (when max_open_trades isn't being set to -1 in the config).

    When the trade slots are full, there is no need to calculate indicators of the rest of the pairs (except informative pairs) since no new trade can be opened. By shrinking the whitelist to just the in-trade pairs, you can improve calculation speeds and reduce CPU usage. When a trade slot is free (either a trade is closed or max_open_trades value in config is increased), then the whitelist will return to normal state.

    When multiple pairlist filters are being used, it's recommended to put this filter at second position directly below the primary pairlist, so when the trade slots are full, the bot doesn't have to download data for the rest of the filters.

    Backtesting

    FullTradesFilter does not support backtesting mode.

    "},{"location":"plugins/#offsetfilter","title":"OffsetFilter","text":"

    Offsets an incoming pairlist by a given offset value.

    As an example it can be used in conjunction with VolumeFilter to remove the top X volume pairs. Or to split a larger pairlist on two bot instances.

    Example to remove the first 10 pairs from the pairlist, and takes the next 20 (taking items 10-30 of the initial list):

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"OffsetFilter\",\n        \"offset\": 10,\n        \"number_assets\": 20\n    }\n],\n

    Warning

    When OffsetFilter is used to split a larger pairlist among multiple bots in combination with VolumeFilter it can not be guaranteed that pairs won't overlap due to slightly different refresh intervals for the VolumeFilter.

    Note

    An offset larger than the total length of the incoming pairlist will result in an empty pairlist.

    "},{"location":"plugins/#performancefilter","title":"PerformanceFilter","text":"

    Sorts pairs by past trade performance, as follows:

    1. Positive performance.
    2. No closed trades yet.
    3. Negative performance.

    Trade count is used as a tie breaker.

    You can use the minutes parameter to only consider performance of the past X minutes (rolling window). Not defining this parameter (or setting it to 0) will use all-time performance.

    The optional min_profit (as ratio -> a setting of 0.01 corresponds to 1%) parameter defines the minimum profit a pair must have to be considered. Pairs below this level will be filtered out. Using this parameter without minutes is highly discouraged, as it can lead to an empty pairlist without a way to recover.

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"PerformanceFilter\",\n        \"minutes\": 1440,  // rolling 24h\n        \"min_profit\": 0.01  // minimal profit 1%\n    }\n],\n

    As this Filter uses past performance of the bot, it'll have some startup-period - and should only be used after the bot has a few 100 trades in the database.

    Backtesting

    PerformanceFilter does not support backtesting mode.

    "},{"location":"plugins/#precisionfilter","title":"PrecisionFilter","text":"

    Filters low-value coins which would not allow setting stoplosses.

    Namely, pairs are blacklisted if a variance of one percent or more in the stop price would be caused by precision rounding on the exchange, i.e. rounded(stop_price) <= rounded(stop_price * 0.99). The idea is to avoid coins with a value VERY close to their lower trading boundary, not allowing setting of proper stoploss.

    PrecisionFilter is pointless for futures trading

    The above does not apply to shorts. And for longs, in theory the trade will be liquidated first.

    Backtesting

    PrecisionFilter does not support backtesting mode using multiple strategies.

    "},{"location":"plugins/#pricefilter","title":"PriceFilter","text":"

    The PriceFilter allows filtering of pairs by price. Currently the following price filters are supported:

    • min_price
    • max_price
    • max_value
    • low_price_ratio

    The min_price setting removes pairs where the price is below the specified price. This is useful if you wish to avoid trading very low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_price setting removes pairs where the price is above the specified price. This is useful if you wish to trade only low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_value setting removes pairs where the minimum value change is above a specified value. This is useful when an exchange has unbalanced limits. For example, if step-size = 1 (so you can only buy 1, or 2, or 3, but not 1.1 Coins) - and the price is pretty high (like 20$) as the coin has risen sharply since the last limit adaption. As a result of the above, you can only buy for 20$, or 40$ - but not for 25$. On exchanges that deduct fees from the receiving currency (e.g. binance) - this can result in high value coins / amounts that are unsellable as the amount is slightly below the limit.

    The low_price_ratio setting removes pairs where a raise of 1 price unit (pip) is above the low_price_ratio ratio. This option is disabled by default, and will only apply if set to > 0.

    For PriceFilter at least one of its min_price, max_price or low_price_ratio settings must be applied.

    Calculation example:

    Min price precision for SHITCOIN/BTC is 8 decimals. If its price is 0.00000011 - one price step above would be 0.00000012, which is ~9% higher than the previous price value. You may filter out this pair by using PriceFilter with low_price_ratio set to 0.09 (9%) or with min_price set to 0.00000011, correspondingly.

    Low priced pairs

    Low priced pairs with high \"1 pip movements\" are dangerous since they are often illiquid and it may also be impossible to place the desired stoploss, which can often result in high losses since price needs to be rounded to the next tradable price - so instead of having a stoploss of -5%, you could end up with a stoploss of -9% simply due to price rounding.

    "},{"location":"plugins/#shufflefilter","title":"ShuffleFilter","text":"

    Shuffles (randomizes) pairs in the pairlist. It can be used for preventing the bot from trading some of the pairs more frequently then others when you want all pairs be treated with the same priority.

    By default, ShuffleFilter will shuffle pairs once per candle. To shuffle on every iteration, set \"shuffle_frequency\" to \"iteration\" instead of the default of \"candle\".

        {\n        \"method\": \"ShuffleFilter\", \n        \"shuffle_frequency\": \"candle\",\n        \"seed\": 42\n    }\n

    Tip

    You may set the seed value for this Pairlist to obtain reproducible results, which can be useful for repeated backtesting sessions. If seed is not set, the pairs are shuffled in the non-repeatable random order. ShuffleFilter will automatically detect runmodes and apply the seed only for backtesting modes - if a seed value is set.

    "},{"location":"plugins/#spreadfilter","title":"SpreadFilter","text":"

    Removes pairs that have a difference between asks and bids above the specified ratio, max_spread_ratio (defaults to 0.005).

    Example:

    If DOGE/BTC maximum bid is 0.00000026 and minimum ask is 0.00000027, the ratio is calculated as: 1 - bid/ask ~= 0.037 which is > 0.005 and this pair will be filtered out.

    "},{"location":"plugins/#rangestabilityfilter","title":"RangeStabilityFilter","text":"

    Removes pairs where the difference between lowest low and highest high over lookback_days days is below min_rate_of_change or above max_rate_of_change. Since this is a filter that requires additional data, the results are cached for refresh_period.

    In the below example: If the trading range over the last 10 days is <1% or >99%, remove the pair from the whitelist.

    \"pairlists\": [\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"max_rate_of_change\": 0.99,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting for this pairlist.

    Tip

    This Filter can be used to automatically remove stable coin pairs, which have a very low trading range, and are therefore extremely difficult to trade with profit. Additionally, it can also be used to automatically remove pairs with extreme high/low variance over a given amount of time.

    "},{"location":"plugins/#volatilityfilter","title":"VolatilityFilter","text":"

    Volatility is the degree of historical variation of a pairs over time, it is measured by the standard deviation of logarithmic daily returns. Returns are assumed to be normally distributed, although actual distribution might be different. In a normal distribution, 68% of observations fall within one standard deviation and 95% of observations fall within two standard deviations. Assuming a volatility of 0.05 means that the expected returns for 20 out of 30 days is expected to be less than 5% (one standard deviation). Volatility is a positive ratio of the expected deviation of return and can be greater than 1.00. Please refer to the wikipedia definition of volatility.

    This filter removes pairs if the average volatility over a lookback_days days is below min_volatility or above max_volatility. Since this is a filter that requires additional data, the results are cached for refresh_period.

    This filter can be used to narrow down your pairs to a certain volatility or avoid very volatile pairs.

    In the below example: If the volatility over the last 10 days is not in the range of 0.05-0.50, remove the pair from the whitelist. The filter is applied every 24h.

    \"pairlists\": [\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting mode for this pairlist.

    "},{"location":"plugins/#full-example-of-pairlist-handlers","title":"Full example of Pairlist Handlers","text":"

    The below example blacklists BNB/BTC, uses VolumePairList with 20 assets, sorting pairs by quoteVolume and applies PrecisionFilter and PriceFilter, filtering all assets where 1 price unit is > 1%. Then the SpreadFilter and VolatilityFilter is applied and pairs are finally shuffled with the random seed set to some predefined value.

    \"exchange\": {\n    \"pair_whitelist\": [],\n    \"pair_blacklist\": [\"BNB/BTC\"]\n},\n\"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\"\n    },\n    {\"method\": \"AgeFilter\", \"min_days_listed\": 10},\n    {\"method\": \"PrecisionFilter\"},\n    {\"method\": \"PriceFilter\", \"low_price_ratio\": 0.01},\n    {\"method\": \"SpreadFilter\", \"max_spread_ratio\": 0.005},\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"refresh_period\": 86400\n    },\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    },\n    {\"method\": \"ShuffleFilter\", \"seed\": 42}\n],\n
    "},{"location":"plugins/#protections","title":"Protections","text":"

    Beta feature

    This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.

    Protections will protect your strategy from unexpected events and market conditions by temporarily stop trading for either one pair, or for all pairs. All protection end times are rounded up to the next candle to avoid sudden, unexpected intra-candle buys.

    Note

    Not all Protections will work for all strategies, and parameters will need to be tuned for your strategy to improve performance.

    Tip

    Each Protection can be configured multiple times with different parameters, to allow different levels of protection (short-term / long-term).

    Backtesting

    Protections are supported by backtesting and hyperopt, but must be explicitly enabled by using the --enable-protections flag.

    Setting protections from the configuration

    Setting protections from the configuration via \"protections\": [], key should be considered deprecated and will be removed in a future version. It is also no longer guaranteed that your protections apply to the strategy in cases where the strategy defines protections as property.

    "},{"location":"plugins/#available-protections","title":"Available Protections","text":"
    • StoplossGuard Stop trading if a certain amount of stoploss occurred within a certain time window.
    • MaxDrawdown Stop trading if max-drawdown is reached.
    • LowProfitPairs Lock pairs with low profits
    • CooldownPeriod Don't enter a trade right after selling a trade.
    "},{"location":"plugins/#common-settings-to-all-protections","title":"Common settings to all Protections","text":"Parameter Description method Protection name to use. Datatype: String, selected from available Protections stop_duration_candles For how many candles should the lock be set? Datatype: Positive integer (in candles) stop_duration how many minutes should protections be locked. Cannot be used together with stop_duration_candles. Datatype: Float (in minutes) lookback_period_candles Only trades that completed within the last lookback_period_candles candles will be considered. This setting may be ignored by some Protections. Datatype: Positive integer (in candles). lookback_period Only trades that completed after current_time - lookback_period will be considered. Cannot be used together with lookback_period_candles. This setting may be ignored by some Protections. Datatype: Float (in minutes) trade_limit Number of trades required at minimum (not used by all Protections). Datatype: Positive integer unlock_at Time when trading will be unlocked regularly (not used by all Protections). Datatype: string Input Format: \"HH:MM\" (24-hours)

    Durations

    Durations (stop_duration* and lookback_period* can be defined in either minutes or candles). For more flexibility when testing different timeframes, all below examples will use the \"candle\" definition.

    "},{"location":"plugins/#stoploss-guard","title":"Stoploss Guard","text":"

    StoplossGuard selects all trades within lookback_period in minutes (or in candles when using lookback_period_candles). If trade_limit or more trades resulted in stoploss, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    This applies across all pairs, unless only_per_pair is set to true, which will then only look at one pair at a time.

    Similarly, this protection will by default look at all trades (long and short). For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long stoplosses.

    required_profit will determine the required relative profit (or loss) for stoplosses to consider. This should normally not be set and defaults to 0.0 - which means all losing stoplosses will be triggering a block.

    The below example stops trading for all pairs for 4 candles after the last trade if the bot hit stoploss 4 times within the last 24 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"StoplossGuard\",\n            \"lookback_period_candles\": 24,\n            \"trade_limit\": 4,\n            \"stop_duration_candles\": 4,\n            \"required_profit\": 0.0,\n            \"only_per_pair\": False,\n            \"only_per_side\": False\n        }\n    ]\n

    Note

    StoplossGuard considers all trades with the results \"stop_loss\", \"stoploss_on_exchange\" and \"trailing_stop_loss\" if the resulting profit was negative. trade_limit and lookback_period will need to be tuned for your strategy.

    "},{"location":"plugins/#maxdrawdown","title":"MaxDrawdown","text":"

    MaxDrawdown uses all trades within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the maximum drawdown. If the drawdown is below max_allowed_drawdown, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles) after the last trade - assuming that the bot needs some time to let markets recover.

    The below sample stops trading for 12 candles if max-drawdown is > 20% considering all pairs - with a minimum of trade_limit trades - within the last 48 candles. If desired, lookback_period and/or stop_duration can be used.

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"MaxDrawdown\",\n            \"lookback_period_candles\": 48,\n            \"trade_limit\": 20,\n            \"stop_duration_candles\": 12,\n            \"max_allowed_drawdown\": 0.2\n        },\n    ]\n
    "},{"location":"plugins/#low-profit-pairs","title":"Low Profit Pairs","text":"

    LowProfitPairs uses all trades for a pair within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the overall profit ratio. If that ratio is below required_profit, that pair will be locked for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long losses.

    The below example will stop trading a pair for 60 minutes if the pair does not have a required profit of 2% (and a minimum of 2 trades) within the last 6 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"LowProfitPairs\",\n            \"lookback_period_candles\": 6,\n            \"trade_limit\": 2,\n            \"stop_duration\": 60,\n            \"required_profit\": 0.02,\n            \"only_per_pair\": False,\n        }\n    ]\n
    "},{"location":"plugins/#cooldown-period","title":"Cooldown Period","text":"

    CooldownPeriod locks a pair for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at) after exiting, avoiding a re-entry for this pair for stop_duration minutes.

    The below example will stop trading a pair for 2 candles after closing a trade, allowing this pair to \"cool down\".

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": 2\n        }\n    ]\n

    Note

    This Protection applies only at pair-level, and will never lock all pairs globally. This Protection does not consider lookback_period as it only looks at the latest trade.

    "},{"location":"plugins/#full-example-of-protections","title":"Full example of Protections","text":"

    All protections can be combined at will, also with different parameters, creating a increasing wall for under-performing pairs. All protections are evaluated in the sequence they are defined.

    The below example assumes a timeframe of 1 hour:

    • Locks each pair after selling for an additional 5 candles (CooldownPeriod), giving other pairs a chance to get filled.
    • Stops trading for 4 hours (4 * 1h candles) if the last 2 days (48 * 1h candles) had 20 trades, which caused a max-drawdown of more than 20%. (MaxDrawdown).
    • Stops trading if more than 4 stoploss occur for all pairs within a 1 day (24 * 1h candles) limit (StoplossGuard).
    • Locks all pairs that had 2 Trades within the last 6 hours (6 * 1h candles) with a combined profit ratio of below 0.02 (<2%) (LowProfitPairs).
    • Locks all pairs for 2 candles that had a profit of below 0.01 (<1%) within the last 24h (24 * 1h candles), a minimum of 4 trades.
    from freqtrade.strategy import IStrategy\n\nclass AwesomeStrategy(IStrategy)\n    timeframe = '1h'\n\n    @property\n    def protections(self):\n        return [\n            {\n                \"method\": \"CooldownPeriod\",\n                \"stop_duration_candles\": 5\n            },\n            {\n                \"method\": \"MaxDrawdown\",\n                \"lookback_period_candles\": 48,\n                \"trade_limit\": 20,\n                \"stop_duration_candles\": 4,\n                \"max_allowed_drawdown\": 0.2\n            },\n            {\n                \"method\": \"StoplossGuard\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"only_per_pair\": False\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 6,\n                \"trade_limit\": 2,\n                \"stop_duration_candles\": 60,\n                \"required_profit\": 0.02\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"required_profit\": 0.01\n            }\n        ]\n    # ...\n
    "},{"location":"producer-consumer/","title":"Producer / Consumer mode","text":"

    freqtrade provides a mechanism whereby an instance (also called consumer) may listen to messages from an upstream freqtrade instance (also called producer) using the message websocket. Mainly, analyzed_df and whitelist messages. This allows the reuse of computed indicators (and signals) for pairs in multiple bots without needing to compute them multiple times.

    See Message Websocket in the Rest API docs for setting up the api_server configuration for your message websocket (this will be your producer).

    Note

    We strongly recommend to set ws_token to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"producer-consumer/#configuration","title":"Configuration","text":"

    Enable subscribing to an instance by adding the external_message_consumer section to the consumer's config file.

    {\n    //...\n   \"external_message_consumer\": {\n        \"enabled\": true,\n        \"producers\": [\n            {\n                \"name\": \"default\", // This can be any name you'd like, default is \"default\"\n                \"host\": \"127.0.0.1\", // The host from your producer's api_server config\n                \"port\": 8080, // The port from your producer's api_server config\n                \"secure\": false, // Use a secure websockets connection, default false\n                \"ws_token\": \"sercet_Ws_t0ken\" // The ws_token from your producer's api_server config\n            }\n        ],\n        // The following configurations are optional, and usually not required\n        // \"wait_timeout\": 300,\n        // \"ping_timeout\": 10,\n        // \"sleep_time\": 10,\n        // \"remove_entry_exit_signals\": false,\n        // \"message_size_limit\": 8\n    }\n    //...\n}\n
    Parameter Description enabled Required. Enable consumer mode. If set to false, all other settings in this section are ignored.Defaults to false. Datatype: boolean . producers Required. List of producers Datatype: Array. producers.name Required. Name of this producer. This name must be used in calls to get_producer_pairs() and get_producer_df() if more than one producer is used. Datatype: string producers.host Required. The hostname or IP address from your producer. Datatype: string producers.port Required. The port matching the above host.Defaults to 8080. Datatype: Integer producers.secure Optional. Use ssl in websockets connection. Default False. Datatype: string producers.ws_token Required. ws_token as configured on the producer. Datatype: string Optional settings wait_timeout Timeout until we ping again if no message is received. Defaults to 300. Datatype: Integer - in seconds. ping_timeout Ping timeout Defaults to 10. Datatype: Integer - in seconds. sleep_time Sleep time before retrying to connect.Defaults to 10. Datatype: Integer - in seconds. remove_entry_exit_signals Remove signal columns from the dataframe (set them to 0) on dataframe receipt.Defaults to false. Datatype: Boolean. message_size_limit Size limit per messageDefaults to 8. Datatype: Integer - Megabytes.

    Instead of (or as well as) calculating indicators in populate_indicators() the follower instance listens on the connection to a producer instance's messages (or multiple producer instances in advanced configurations) and requests the producer's most recently analyzed dataframes for each pair in the active whitelist.

    A consumer instance will then have a full copy of the analyzed dataframes without the need to calculate them itself.

    "},{"location":"producer-consumer/#examples","title":"Examples","text":""},{"location":"producer-consumer/#example-producer-strategy","title":"Example - Producer Strategy","text":"

    A simple strategy with multiple indicators. No special considerations are required in the strategy itself.

    class ProducerStrategy(IStrategy):\n    #...\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Calculate indicators in the standard freqtrade way which can then be broadcast to other instances\n        \"\"\"\n        dataframe['rsi'] = ta.RSI(dataframe)\n        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)\n        dataframe['bb_lowerband'] = bollinger['lower']\n        dataframe['bb_middleband'] = bollinger['mid']\n        dataframe['bb_upperband'] = bollinger['upper']\n        dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Populates the entry signal for the given dataframe\n        \"\"\"\n        dataframe.loc[\n            (\n                (qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value)) &\n                (dataframe['tema'] <= dataframe['bb_middleband']) &\n                (dataframe['tema'] > dataframe['tema'].shift(1)) &\n                (dataframe['volume'] > 0)\n            ),\n            'enter_long'] = 1\n\n        return dataframe\n

    FreqAI

    You can use this to setup FreqAI on a powerful machine, while you run consumers on simple machines like raspberries, which can interpret the signals generated from the producer in different ways.

    "},{"location":"producer-consumer/#example-consumer-strategy","title":"Example - Consumer Strategy","text":"

    A logically equivalent strategy which calculates no indicators itself, but will have the same analyzed dataframes available to make trading decisions based on the indicators calculated in the producer. In this example the consumer has the same entry criteria, however this is not necessary. The consumer may use different logic to enter/exit trades, and only use the indicators as specified.

    class ConsumerStrategy(IStrategy):\n    #...\n    process_only_new_candles = False # required for consumers\n\n    _columns_to_expect = ['rsi_default', 'tema_default', 'bb_middleband_default']\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Use the websocket api to get pre-populated indicators from another freqtrade instance.\n        Use `self.dp.get_producer_df(pair)` to get the dataframe\n        \"\"\"\n        pair = metadata['pair']\n        timeframe = self.timeframe\n\n        producer_pairs = self.dp.get_producer_pairs()\n        # You can specify which producer to get pairs from via:\n        # self.dp.get_producer_pairs(\"my_other_producer\")\n\n        # This func returns the analyzed dataframe, and when it was analyzed\n        producer_dataframe, _ = self.dp.get_producer_df(pair)\n        # You can get other data if the producer makes it available:\n        # self.dp.get_producer_df(\n        #   pair,\n        #   timeframe=\"1h\",\n        #   candle_type=CandleType.SPOT,\n        #   producer_name=\"my_other_producer\"\n        # )\n\n        if not producer_dataframe.empty:\n            # If you plan on passing the producer's entry/exit signal directly,\n            # specify ffill=False or it will have unintended results\n            merged_dataframe = merge_informative_pair(dataframe, producer_dataframe,\n                                                      timeframe, timeframe,\n                                                      append_timeframe=False,\n                                                      suffix=\"default\")\n            return merged_dataframe\n        else:\n            dataframe[self._columns_to_expect] = 0\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Populates the entry signal for the given dataframe\n        \"\"\"\n        # Use the dataframe columns as if we calculated them ourselves\n        dataframe.loc[\n            (\n                (qtpylib.crossed_above(dataframe['rsi_default'], self.buy_rsi.value)) &\n                (dataframe['tema_default'] <= dataframe['bb_middleband_default']) &\n                (dataframe['tema_default'] > dataframe['tema_default'].shift(1)) &\n                (dataframe['volume'] > 0)\n            ),\n            'enter_long'] = 1\n\n        return dataframe\n

    Using upstream signals

    By setting remove_entry_exit_signals=false, you can also use the producer's signals directly. They should be available as enter_long_default (assuming suffix=\"default\" was used) - and can be used as either signal directly, or as additional indicator.

    "},{"location":"recursive-analysis/","title":"Recursive analysis","text":"

    This page explains how to validate your strategy for inaccuracies due to recursive issues with certain indicators.

    A recursive formula defines any term of a sequence relative to its preceding term(s). An example of a recursive formula is an = an-1 + b.

    Why does this matter for Freqtrade? In backtesting, the bot will get full data of the pairs according to the timerange specified. But in a dry/live run, the bot will be limited by the amount of data each exchanges gives.

    For example, to calculate a very basic indicator called steps, the first row's value is always 0, while the following rows' values are equal to the value of the previous row plus 1. If I were to calculate it using the latest 1000 candles, then the steps value of the first row is 0, and the steps value at the last closed candle is 999.

    What happens if the calculation is using only the latest 500 candles? Then instead of 999, the steps value at last closed candle is 499. The difference of the value means your backtest result can differ from your dry/live run result.

    The recursive-analysis command requires historic data to be available. To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    This command is built upon preparing different lengths of data and calculates indicators based on them. This does not backtest the strategy itself, but rather only calculates the indicators. After calculating the indicators of different startup candle values (startup_candle_count) are done, the values of last rows across all specified startup_candle_count are compared to see how much variance they show compared to the base calculation.

    Command settings:

    • Use the -p option to set your desired pair to analyze. Since we are only looking at indicator values, using more than one pair is redundant. Preferably use a pair with a relatively high price and at least moderate volatility, such as BTC or ETH, to avoid rounding issues that can make the results inaccurate. If no pair is set on the command, the pair used for this analysis is the first pair in the whitelist.
    • It is recommended to set a long timerange (at least 5000 candles) so that the initial indicators' calculation that is going to be used as a benchmark has very small or no recursive issues itself. For example, for a 5m timeframe, a timerange of 5000 candles would be equal to 18 days.
    • --cache is forced to \"none\" to avoid loading previous indicators calculation automatically.

    In addition to the recursive formula check, this command also carries out a simple lookahead bias check on the indicator values only. For a full lookahead check, use Lookahead-analysis.

    "},{"location":"recursive-analysis/#recursive-analysis-command-reference","title":"Recursive-analysis command reference","text":"
    usage: freqtrade recursive-analysis [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                    [-d PATH] [--userdir PATH] [-s NAME]\n                                    [--strategy-path PATH]\n                                    [--recursive-strategy-search]\n                                    [--freqaimodel NAME]\n                                    [--freqaimodel-path PATH] [-i TIMEFRAME]\n                                    [--timerange TIMERANGE]\n                                    [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                                    [-p PAIR]\n                                    [--freqai-backtest-live-models]\n                                    [--startup-candle STARTUP_CANDLES [STARTUP_CANDLES ...]]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  -p PAIR, --pairs PAIR\n                        Limit command to this pair.\n  --startup-candle STARTUP_CANDLE [STARTUP_CANDLE ...]\n                        Provide a space-separated list of startup_candle_count to\n                        be checked. Default : `199 399 499 999 1999`.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n
    "},{"location":"recursive-analysis/#why-are-odd-numbered-default-startup-candles-used","title":"Why are odd-numbered default startup candles used?","text":"

    The default value for startup candles are odd numbers. When the bot fetches candle data from the exchange's API, the last candle is the one being checked by the bot and the rest of the data are the \"startup candles\".

    For example, Binance allows 1000 candles per API call. When the bot receives 1000 candles, the last candle is the \"current candle\", and the preceding 999 candles are the \"startup candles\". By setting the startup candle count as 1000 instead of 999, the bot will try to fetch 1001 candles instead. The exchange API will then send candle data in a paginated form, i.e. in case of the Binance API, this will be two groups- one of length 1000 and another of length 1. This results in the bot thinking the strategy needs 1001 candles of data, and so it will download 2000 candles worth of data instead, which means there will be 1 \"current candle\" and 1999 \"startup candles\".

    Furthermore, exchanges limit the number of consecutive bulk API calls, e.g. Binance allows 5 calls. In this case, only 5000 candles can be downloaded from Binance API without hitting the API rate limit, which means the max startup_candle_count you can have is 4999.

    Please note that this candle limit may be changed in the future by the exchanges without any prior notice.

    "},{"location":"recursive-analysis/#how-does-the-command-work","title":"How does the command work?","text":"
    • Firstly an initial indicator calculation is carried out using the supplied timerange to generate a benchmark for indicator values.
    • After setting the benchmark it will then carry out additional runs for each of the different startup candle count values.
    • The command will then compare the indicator values at the last candle rows and report the differences in a table.
    "},{"location":"recursive-analysis/#understanding-the-recursive-analysis-output","title":"Understanding the recursive-analysis output","text":"

    This is an example of an output results table where at least one indicator has a recursive formula issue:

    | indicators   | 20      | 40      | 80     | 100    | 150     | 300     | 999    |\n|--------------+---------+---------+--------+--------+---------+---------+--------|\n| rsi_30       | nan%    | -6.025% | 0.612% | 0.828% | -0.140% | 0.000%  | 0.000% |\n| rsi_14       | 24.141% | -0.876% | 0.070% | 0.007% | -0.000% | -0.000% | -      |\n

    The column headers indicate the different startup_candle_count used in the analysis. The values in the table indicate the variance of the calculated indicators compared to the benchmark value.

    nan% means the value of that indicator cannot be calculated due to lack of data. In this example, you cannot calculate RSI with length 30 with just 21 candles (1 current candle + 20 startup candles).

    Users should assess the table per indicator to decide if the specified startup_candle_count results in a sufficiently small variance so that the indicator does not have any effect on entries and/or exits.

    As such, aiming for absolute zero variance (shown by - value) might not be the best option, because some indicators might require you to use such a long startup_candle_count to have zero variance.

    "},{"location":"recursive-analysis/#caveats","title":"Caveats","text":"
    • recursive-analysis will only calculate and compare the indicator values at the last row. The output table reports the percentage differences between the different startup candle count calculations and the original benchmark calculation. Whether it has any actual impact on your entries and exits is not included.
    • The ideal scenario is that indicators will have no variance (or at least very close to 0%) despite the startup candle being varied. In reality, indicators such as EMA are using a recursive formula to calculate indicator values, so the goal is not necessarily to have zero percentage variance, but to have the variance low enough (and therefore startup_candle_count high enough) that the recursion inherent in the indicator will not have any real impact on trading decisions.
    • recursive-analysis will only run calculations on populate_indicators and @informative decorator(s). If you put any indicator calculation on populate_entry_trend or populate_exit_trend, it won't be calculated.
    "},{"location":"rest-api/","title":"REST API","text":""},{"location":"rest-api/#frequi","title":"FreqUI","text":"

    FreqUI now has it's own dedicated documentation section - please refer to that section for all information regarding the FreqUI.

    "},{"location":"rest-api/#configuration","title":"Configuration","text":"

    Enable the rest API by adding the api_server section to your configuration and setting api_server.enabled to true.

    Sample configuration:

        \"api_server\": {\n        \"enabled\": true,\n        \"listen_ip_address\": \"127.0.0.1\",\n        \"listen_port\": 8080,\n        \"verbosity\": \"error\",\n        \"enable_openapi\": false,\n        \"jwt_secret_key\": \"somethingrandom\",\n        \"CORS_origins\": [],\n        \"username\": \"Freqtrader\",\n        \"password\": \"SuperSecret1!\",\n        \"ws_token\": \"sercet_Ws_t0ken\"\n    },\n

    Security warning

    By default, the configuration listens on localhost only (so it's not reachable from other systems). We strongly recommend to not expose this API to the internet and choose a strong, unique password, since others will potentially be able to control your bot.

    API/UI Access on a remote servers

    If you're running on a VPS, you should consider using either a ssh tunnel, or setup a VPN (openVPN, wireguard) to connect to your bot. This will ensure that freqUI is not directly exposed to the internet, which is not recommended for security reasons (freqUI does not support https out of the box). Setup of these tools is not part of this tutorial, however many good tutorials can be found on the internet.

    You can then access the API by going to http://127.0.0.1:8080/api/v1/ping in a browser to check if the API is running correctly. This should return the response:

    {\"status\":\"pong\"}\n

    All other endpoints return sensitive info and require authentication and are therefore not available through a web browser.

    "},{"location":"rest-api/#security","title":"Security","text":"

    To generate a secure password, best use a password manager, or use the below code.

    import secrets\nsecrets.token_hex()\n

    JWT token

    Use the same method to also generate a JWT secret key (jwt_secret_key).

    Password selection

    Please make sure to select a very strong, unique password to protect your bot from unauthorized access. Also change jwt_secret_key to something random (no need to remember this, but it'll be used to encrypt your session, so it better be something unique!).

    "},{"location":"rest-api/#configuration-with-docker","title":"Configuration with docker","text":"

    If you run your bot using docker, you'll need to have the bot listen to incoming connections. The security is then handled by docker.

        \"api_server\": {\n        \"enabled\": true,\n        \"listen_ip_address\": \"0.0.0.0\",\n        \"listen_port\": 8080,\n        \"username\": \"Freqtrader\",\n        \"password\": \"SuperSecret1!\",\n        //...\n    },\n

    Make sure that the following 2 lines are available in your docker-compose file:

        ports:\n      - \"127.0.0.1:8080:8080\"\n

    Security warning

    By using \"8080:8080\" (or \"0.0.0.0:8080:8080\") in the docker port mapping, the API will be available to everyone connecting to the server under the correct port, so others may be able to control your bot. This may be safe if you're running the bot in a secure environment (like your home network), but it's not recommended to expose the API to the internet.

    "},{"location":"rest-api/#rest-api_1","title":"Rest API","text":""},{"location":"rest-api/#consuming-the-api","title":"Consuming the API","text":"

    You can consume the API by using freqtrade-client (also available as scripts/rest_client.py). This command can be installed independent of the bot by using pip install freqtrade-client.

    This module is designed to be lightweight, and only depends on the requests and python-rapidjson modules, skipping all heavy dependencies freqtrade otherwise needs.

    freqtrade-client <command> [optional parameters]\n

    By default, the script assumes 127.0.0.1 (localhost) and port 8080 to be used, however you can specify a configuration file to override this behaviour.

    "},{"location":"rest-api/#minimalistic-client-config","title":"Minimalistic client config","text":"
    {\n    \"api_server\": {\n        \"enabled\": true,\n        \"listen_ip_address\": \"0.0.0.0\",\n        \"listen_port\": 8080,\n        \"username\": \"Freqtrader\",\n        \"password\": \"SuperSecret1!\",\n        //...\n    }\n}\n
    freqtrade-client --config rest_config.json <command> [optional parameters]\n

    Commands with many arguments may require keyword arguments (for clarity) - which can be provided as follows:

    freqtrade-client --config rest_config.json forceenter BTC/USDT long enter_tag=GutFeeling\n

    This method will work for all arguments - check the \"show\" command for a list of available parameters.

    Programmatic use

    The freqtrade-client package (installable independent of freqtrade) can be used in your own scripts to interact with the freqtrade API. to do so, please use the following:

    from freqtrade_client import FtRestClient\n\n\nclient = FtRestClient(server_url, username, password)\n\n# Get the status of the bot\nping = client.ping()\nprint(ping)\n# ... \n

    For a full list of available commands, please refer to the list below.

    "},{"location":"rest-api/#available-endpoints","title":"Available endpoints","text":"Command Description ping Simple command testing the API Readiness - requires no authentication. start Starts the trader. stop Stops the trader. stopbuy Stops the trader from opening new trades. Gracefully closes open trades according to their rules. reload_config Reloads the configuration file. trades List last trades. Limited to 500 trades per call. trade/<tradeid> Get specific trade. trades/<tradeid> DELETE - Remove trade from the database. Tries to close open orders. Requires manual handling of this trade on the exchange. trades/<tradeid>/open-order DELETE - Cancel open order for this trade. trades/<tradeid>/reload GET - Reload a trade from the Exchange. Only works in live, and can potentially help recover a trade that was manually sold on the exchange. show_config Shows part of the current configuration with relevant settings to operation. logs Shows last log messages. status Lists all open trades. count Displays number of trades used and available. entries [pair] Shows profit statistics for each enter tags for given pair (or all pairs if pair isn't given). Pair is optional. exits [pair] Shows profit statistics for each exit reasons for given pair (or all pairs if pair isn't given). Pair is optional. mix_tags [pair] Shows profit statistics for each combinations of enter tag + exit reasons for given pair (or all pairs if pair isn't given). Pair is optional. locks Displays currently locked pairs. delete_lock <lock_id> Deletes (disables) the lock by id. locks add <pair>, <until>, [side], [reason] Locks a pair until \"until\". (Until will be rounded up to the nearest timeframe). profit Display a summary of your profit/loss from close trades and some stats about your performance. forceexit <trade_id> [order_type] [amount] Instantly exits the given trade (ignoring minimum_roi), using the given order type (\"market\" or \"limit\", uses your config setting if not specified), and the chosen amount (full sell if not specified). forceexit all Instantly exits all open trades (Ignoring minimum_roi). forceenter <pair> [rate] Instantly enters the given pair. Rate is optional. (force_entry_enable must be set to True) forceenter <pair> <side> [rate] Instantly longs or shorts the given pair. Rate is optional. (force_entry_enable must be set to True) performance Show performance of each finished trade grouped by pair. balance Show account balance per currency. daily <n> Shows profit or loss per day, over the last n days (n defaults to 7). weekly <n> Shows profit or loss per week, over the last n days (n defaults to 4). monthly <n> Shows profit or loss per month, over the last n days (n defaults to 3). stats Display a summary of profit / loss reasons as well as average holding times. whitelist Show the current whitelist. blacklist [pair] Show the current blacklist, or adds a pair to the blacklist. edge Show validated pairs by Edge if it is enabled. pair_candles Returns dataframe for a pair / timeframe combination while the bot is running. Alpha pair_history Returns an analyzed dataframe for a given timerange, analyzed by a given strategy. Alpha plot_config Get plot config from the strategy (or nothing if not configured). Alpha strategies List strategies in strategy directory. Alpha strategy <strategy> Get specific Strategy content. Alpha available_pairs List available backtest data. Alpha version Show version. sysinfo Show information about the system load. health Show bot health (last bot loop).

    Alpha status

    Endpoints labeled with Alpha status above may change at any time without notice.

    Possible commands can be listed from the rest-client script using the help command.

    freqtrade-client help\n
    Possible commands:\n\navailable_pairs\n    Return available pair (backtest data) based on timeframe / stake_currency selection\n\n        :param timeframe: Only pairs with this timeframe available.\n        :param stake_currency: Only pairs that include this timeframe\n\nbalance\n    Get the account balance.\n\nblacklist\n    Show the current blacklist.\n\n        :param add: List of coins to add (example: \"BNB/BTC\")\n\ncancel_open_order\n    Cancel open order for trade.\n\n        :param trade_id: Cancels open orders for this trade.\n\ncount\n    Return the amount of open trades.\n\ndaily\n    Return the profits for each day, and amount of trades.\n\ndelete_lock\n    Delete (disable) lock from the database.\n\n        :param lock_id: ID for the lock to delete\n\ndelete_trade\n    Delete trade from the database.\n        Tries to close open orders. Requires manual handling of this asset on the exchange.\n\n        :param trade_id: Deletes the trade with this ID from the database.\n\nedge\n    Return information about edge.\n\nforcebuy\n    Buy an asset.\n\n        :param pair: Pair to buy (ETH/BTC)\n        :param price: Optional - price to buy\n\nforceenter\n    Force entering a trade\n\n        :param pair: Pair to buy (ETH/BTC)\n        :param side: 'long' or 'short'\n        :param price: Optional - price to buy\n\nforceexit\n    Force-exit a trade.\n\n        :param tradeid: Id of the trade (can be received via status command)\n        :param ordertype: Order type to use (must be market or limit)\n        :param amount: Amount to sell. Full sell if not given\n\nhealth\n    Provides a quick health check of the running bot.\n\nlocks\n    Return current locks\n\nlogs\n    Show latest logs.\n\n        :param limit: Limits log messages to the last <limit> logs. No limit to get the entire log.\n\npair_candles\n    Return live dataframe for <pair><timeframe>.\n\n        :param pair: Pair to get data for\n        :param timeframe: Only pairs with this timeframe available.\n        :param limit: Limit result to the last n candles.\n\npair_history\n    Return historic, analyzed dataframe\n\n        :param pair: Pair to get data for\n        :param timeframe: Only pairs with this timeframe available.\n        :param strategy: Strategy to analyze and get values for\n        :param timerange: Timerange to get data for (same format than --timerange endpoints)\n\nperformance\n    Return the performance of the different coins.\n\nping\n    simple ping\n\nplot_config\n    Return plot configuration if the strategy defines one.\n\nprofit\n    Return the profit summary.\n\nreload_config\n    Reload configuration.\n\nshow_config\n        Returns part of the configuration, relevant for trading operations.\n\nstart\n    Start the bot if it's in the stopped state.\n\nstats\n    Return the stats report (durations, sell-reasons).\n\nstatus\n    Get the status of open trades.\n\nstop\n    Stop the bot. Use `start` to restart.\n\nstopbuy\n    Stop buying (but handle sells gracefully). Use `reload_config` to reset.\n\nstrategies\n    Lists available strategies\n\nstrategy\n    Get strategy details\n\n        :param strategy: Strategy class name\n\nsysinfo\n    Provides system information (CPU, RAM usage)\n\ntrade\n    Return specific trade\n\n        :param trade_id: Specify which trade to get.\n\ntrades\n    Return trades history, sorted by id\n\n        :param limit: Limits trades to the X last trades. Max 500 trades.\n        :param offset: Offset by this amount of trades.\n\nversion\n    Return the version of the bot.\n\nwhitelist\n    Show the current whitelist.\n
    "},{"location":"rest-api/#message-websocket","title":"Message WebSocket","text":"

    The API Server includes a websocket endpoint for subscribing to RPC messages from the freqtrade Bot. This can be used to consume real-time data from your bot, such as entry/exit fill messages, whitelist changes, populated indicators for pairs, and more.

    This is also used to setup Producer/Consumer mode in Freqtrade.

    Assuming your rest API is set to 127.0.0.1 on port 8080, the endpoint is available at http://localhost:8080/api/v1/message/ws.

    To access the websocket endpoint, the ws_token is required as a query parameter in the endpoint URL.

    To generate a safe ws_token you can run the following code:

    >>> import secrets\n>>> secrets.token_urlsafe(25)\n'hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q'\n

    You would then add that token under ws_token in your api_server config. Like so:

    \"api_server\": {\n    \"enabled\": true,\n    \"listen_ip_address\": \"127.0.0.1\",\n    \"listen_port\": 8080,\n    \"verbosity\": \"error\",\n    \"enable_openapi\": false,\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [],\n    \"username\": \"Freqtrader\",\n    \"password\": \"SuperSecret1!\",\n    \"ws_token\": \"hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q\" // <-----\n},\n

    You can now connect to the endpoint at http://localhost:8080/api/v1/message/ws?token=hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q.

    Reuse of example tokens

    Please do not use the above example token. To make sure you are secure, generate a completely new token.

    "},{"location":"rest-api/#using-the-websocket","title":"Using the WebSocket","text":"

    Once connected to the WebSocket, the bot will broadcast RPC messages to anyone who is subscribed to them. To subscribe to a list of messages, you must send a JSON request through the WebSocket like the one below. The data key must be a list of message type strings.

    {\n  \"type\": \"subscribe\",\n  \"data\": [\"whitelist\", \"analyzed_df\"] // A list of string message types\n}\n

    For a list of message types, please refer to the RPCMessageType enum in freqtrade/enums/rpcmessagetype.py

    Now anytime those types of RPC messages are sent in the bot, you will receive them through the WebSocket as long as the connection is active. They typically take the same form as the request:

    {\n  \"type\": \"analyzed_df\",\n  \"data\": {\n      \"key\": [\"NEO/BTC\", \"5m\", \"spot\"],\n      \"df\": {}, // The dataframe\n      \"la\": \"2022-09-08 22:14:41.457786+00:00\"\n  }\n}\n
    "},{"location":"rest-api/#reverse-proxy-setup","title":"Reverse Proxy setup","text":"

    When using Nginx, the following configuration is required for WebSockets to work (Note this configuration is incomplete, it's missing some information and can not be used as is):

    Please make sure to replace <freqtrade_listen_ip> (and the subsequent port) with the IP and Port matching your configuration/setup.

    http {\n    map $http_upgrade $connection_upgrade {\n        default upgrade;\n        '' close;\n    }\n\n    #...\n\n    server {\n        #...\n\n        location / {\n            proxy_http_version 1.1;\n            proxy_pass http://<freqtrade_listen_ip>:8080;\n            proxy_set_header Upgrade $http_upgrade;\n            proxy_set_header Connection $connection_upgrade;\n            proxy_set_header Host $host;\n        }\n    }\n}\n

    To properly configure your reverse proxy (securely), please consult it's documentation for proxying websockets.

    • Traefik: Traefik supports websockets out of the box, see the documentation
    • Caddy: Caddy v2 supports websockets out of the box, see the documentation

    SSL certificates

    You can use tools like certbot to setup ssl certificates to access your bot's UI through encrypted connection by using any of the above reverse proxies. While this will protect your data in transit, we do not recommend to run the freqtrade API outside of your private network (VPN, SSH tunnel).

    "},{"location":"rest-api/#openapi-interface","title":"OpenAPI interface","text":"

    To enable the builtin openAPI interface (Swagger UI), specify \"enable_openapi\": true in the api_server configuration. This will enable the Swagger UI at the /docs endpoint. By default, that's running at http://localhost:8080/docs - but it'll depend on your settings.

    "},{"location":"rest-api/#advanced-api-usage-using-jwt-tokens","title":"Advanced API usage using JWT tokens","text":"

    Note

    The below should be done in an application (a Freqtrade REST API client, which fetches info via API), and is not intended to be used on a regular basis.

    Freqtrade's REST API also offers JWT (JSON Web Tokens). You can login using the following command, and subsequently use the resulting access_token.

    > curl -X POST --user Freqtrader http://localhost:8080/api/v1/token/login\n{\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk2ODEsIm5iZiI6MTU4OTExOTY4MSwianRpIjoiMmEwYmY0NWUtMjhmOS00YTUzLTlmNzItMmM5ZWVlYThkNzc2IiwiZXhwIjoxNTg5MTIwNTgxLCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.qt6MAXYIa-l556OM7arBvYJ0SDI9J8bIk3_glDujF5g\",\"refresh_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk2ODEsIm5iZiI6MTU4OTExOTY4MSwianRpIjoiZWQ1ZWI3YjAtYjMwMy00YzAyLTg2N2MtNWViMjIxNWQ2YTMxIiwiZXhwIjoxNTkxNzExNjgxLCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJ0eXBlIjoicmVmcmVzaCJ9.d1AT_jYICyTAjD0fiQAr52rkRqtxCjUGEMwlNuuzgNQ\"}\n\n> access_token=\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk2ODEsIm5iZiI6MTU4OTExOTY4MSwianRpIjoiMmEwYmY0NWUtMjhmOS00YTUzLTlmNzItMmM5ZWVlYThkNzc2IiwiZXhwIjoxNTg5MTIwNTgxLCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.qt6MAXYIa-l556OM7arBvYJ0SDI9J8bIk3_glDujF5g\"\n# Use access_token for authentication\n> curl -X GET --header \"Authorization: Bearer ${access_token}\" http://localhost:8080/api/v1/count\n

    Since the access token has a short timeout (15 min) - the token/refresh request should be used periodically to get a fresh access token:

    > curl -X POST --header \"Authorization: Bearer ${refresh_token}\"http://localhost:8080/api/v1/token/refresh\n{\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk5NzQsIm5iZiI6MTU4OTExOTk3NCwianRpIjoiMDBjNTlhMWUtMjBmYS00ZTk0LTliZjAtNWQwNTg2MTdiZDIyIiwiZXhwIjoxNTg5MTIwODc0LCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.1seHlII3WprjjclY6DpRhen0rqdF4j6jbvxIhUFaSbs\"}\n
    "},{"location":"rest-api/#cors","title":"CORS","text":"

    This whole section is only necessary in cross-origin cases (where you multiple bot API's running on localhost:8081, localhost:8082, ...), and want to combine them into one FreqUI instance.

    Technical explanation

    All web-based front-ends are subject to CORS - Cross-Origin Resource Sharing. Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems. Also, the standard disallows * CORS policies for requests with credentials, so this setting must be set appropriately.

    Users can allow access from different origin URL's to the bot API via the CORS_origins configuration setting. It consists of a list of allowed URL's that are allowed to consume resources from the bot's API.

    Assuming your application is deployed as https://frequi.freqtrade.io/home/ - this would mean that the following configuration becomes necessary:

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"https://frequi.freqtrade.io\"],\n    //...\n}\n

    In the following (pretty common) case, FreqUI is accessible on http://localhost:8080/trade (this is what you see in your navbar when navigating to freqUI).

    The correct configuration for this case is http://localhost:8080 - the main part of the URL including the port.

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"http://localhost:8080\"],\n    //...\n}\n

    trailing Slash

    The trailing slash is not allowed in the CORS_origins configuration (e.g. \"http://localhots:8080/\"). Such a configuration will not take effect, and the cors errors will remain.

    Note

    We strongly recommend to also set jwt_secret_key to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"sql_cheatsheet/","title":"SQL Helper","text":"

    This page contains some help if you want to query your sqlite db.

    Other Database systems

    To use other Database Systems like PostgreSQL or MariaDB, you can use the same queries, but you need to use the respective client for the database system. Click here to learn how to setup a different database system with freqtrade.

    Warning

    If you are not familiar with SQL, you should be very careful when running queries on your database. Always make sure to have a backup of your database before running any queries.

    "},{"location":"sql_cheatsheet/#install-sqlite3","title":"Install sqlite3","text":"

    Sqlite3 is a terminal based sqlite application. Feel free to use a visual Database editor like SqliteBrowser if you feel more comfortable with that.

    "},{"location":"sql_cheatsheet/#ubuntudebian-installation","title":"Ubuntu/Debian installation","text":"
    sudo apt-get install sqlite3\n
    "},{"location":"sql_cheatsheet/#using-sqlite3-via-docker","title":"Using sqlite3 via docker","text":"

    The freqtrade docker image does contain sqlite3, so you can edit the database without having to install anything on the host system.

    docker compose exec freqtrade /bin/bash\nsqlite3 <database-file>.sqlite\n
    "},{"location":"sql_cheatsheet/#open-the-db","title":"Open the DB","text":"
    sqlite3\n.open <filepath>\n
    "},{"location":"sql_cheatsheet/#table-structure","title":"Table structure","text":""},{"location":"sql_cheatsheet/#list-tables","title":"List tables","text":"
    .tables\n
    "},{"location":"sql_cheatsheet/#display-table-structure","title":"Display table structure","text":"
    .schema <table_name>\n
    "},{"location":"sql_cheatsheet/#get-all-trades-in-the-table","title":"Get all trades in the table","text":"
    SELECT * FROM trades;\n
    "},{"location":"sql_cheatsheet/#destructive-queries","title":"Destructive queries","text":"

    Queries that write to the database. These queries should usually not be necessary as freqtrade tries to handle all database operations itself - or exposes them via API or telegram commands.

    Warning

    Please make sure you have a backup of your database before running any of the below queries.

    Danger

    You should also never run any writing query (update, insert, delete) while a bot is connected to the database. This can and will lead to data corruption - most likely, without the possibility of recovery.

    "},{"location":"sql_cheatsheet/#fix-trade-still-open-after-a-manual-exit-on-the-exchange","title":"Fix trade still open after a manual exit on the exchange","text":"

    Warning

    Manually selling a pair on the exchange will not be detected by the bot and it will try to sell anyway. Whenever possible, /forceexit should be used to accomplish the same thing. It is strongly advised to backup your database file before making any manual changes.

    Note

    This should not be necessary after /forceexit, as force_exit orders are closed automatically by the bot on the next iteration.

    UPDATE trades\nSET is_open=0,\n  close_date=<close_date>,\n  close_rate=<close_rate>,\n  close_profit = close_rate / open_rate - 1,\n  close_profit_abs = (amount * <close_rate> * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),\n  exit_reason=<exit_reason>\nWHERE id=<trade_ID_to_update>;\n
    "},{"location":"sql_cheatsheet/#example","title":"Example","text":"
    UPDATE trades\nSET is_open=0,\n  close_date='2020-06-20 03:08:45.103418',\n  close_rate=0.19638016,\n  close_profit=0.0496,\n  close_profit_abs = (amount * 0.19638016 * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),\n  exit_reason='force_exit'  \nWHERE id=31;\n
    "},{"location":"sql_cheatsheet/#remove-trade-from-the-database","title":"Remove trade from the database","text":"

    Use RPC Methods to delete trades

    Consider using /delete <tradeid> via telegram or rest API. That's the recommended way to deleting trades.

    If you'd still like to remove a trade from the database directly, you can use the below query.

    Danger

    Some systems (Ubuntu) disable foreign keys in their sqlite3 packaging. When using sqlite - please ensure that foreign keys are on by running PRAGMA foreign_keys = ON before the above query.

    DELETE FROM trades WHERE id = <tradeid>;\n\nDELETE FROM trades WHERE id = 31;\n

    Warning

    This will remove this trade from the database. Please make sure you got the correct id and NEVER run this query without the where clause.

    "},{"location":"stoploss/","title":"Stop Loss","text":"

    The stoploss configuration parameter is loss as ratio that should trigger a sale. For example, value -0.10 will cause immediate sell if the profit dips below -10% for a given trade. This parameter is optional. Stoploss calculations do include fees, so a stoploss of -10% is placed exactly 10% below the entry point.

    Most of the strategy files already include the optimal stoploss value.

    Info

    All stoploss properties mentioned in this file can be set in the Strategy, or in the configuration. Configuration values will override the strategy values.

    "},{"location":"stoploss/#stop-loss-on-exchangefreqtrade","title":"Stop Loss On-Exchange/Freqtrade","text":"

    Those stoploss modes can be on exchange or off exchange.

    These modes can be configured with these values:

        'emergency_exit': 'market',\n    'stoploss_on_exchange': False\n    'stoploss_on_exchange_interval': 60,\n    'stoploss_on_exchange_limit_ratio': 0.99\n

    Stoploss on exchange is only supported for the following exchanges, and not all exchanges support both stop-limit and stop-market. The Order-type will be ignored if only one mode is available.

    Exchange stop-loss type Binance limit Binance Futures market, limit Bingx market, limit HTX (former Huobi) limit kraken market, limit Gate limit Okx limit Kucoin stop-limit, stop-market

    Tight stoploss

    Do not set too low/tight stoploss value when using stop loss on exchange! If set to low/tight you will have greater risk of missing fill on the order and stoploss will not work.

    "},{"location":"stoploss/#stoploss_on_exchange-and-stoploss_on_exchange_limit_ratio","title":"stoploss_on_exchange and stoploss_on_exchange_limit_ratio","text":"

    Enable or Disable stop loss on exchange. If the stoploss is on exchange it means a stoploss limit order is placed on the exchange immediately after buy order fills. This will protect you against sudden crashes in market, as the order execution happens purely within the exchange, and has no potential network overhead.

    If stoploss_on_exchange uses limit orders, the exchange needs 2 prices, the stoploss_price and the Limit price. stoploss defines the stop-price where the limit order is placed - and limit should be slightly below this. If an exchange supports both limit and market stoploss orders, then the value of stoploss will be used to determine the stoploss type.

    Calculation example: we bought the asset at 100$. Stop-price is 95$, then limit would be 95 * 0.99 = 94.05$ - so the limit order fill can happen between 95$ and 94.05$.

    For example, assuming the stoploss is on exchange, and trailing stoploss is enabled, and the market is going up, then the bot automatically cancels the previous stoploss order and puts a new one with a stop value higher than the previous stoploss order.

    Note

    If stoploss_on_exchange is enabled and the stoploss is cancelled manually on the exchange, then the bot will create a new stoploss order.

    "},{"location":"stoploss/#stoploss_on_exchange_interval","title":"stoploss_on_exchange_interval","text":"

    In case of stoploss on exchange there is another parameter called stoploss_on_exchange_interval. This configures the interval in seconds at which the bot will check the stoploss and update it if necessary. The bot cannot do these every 5 seconds (at each iteration), otherwise it would get banned by the exchange. So this parameter will tell the bot how often it should update the stoploss order. The default value is 60 (1 minute). This same logic will reapply a stoploss order on the exchange should you cancel it accidentally.

    "},{"location":"stoploss/#stoploss_price_type","title":"stoploss_price_type","text":"

    Only applies to futures

    stoploss_price_type only applies to futures markets (on exchanges where it's available). Freqtrade will perform a validation of this setting on startup, failing to start if an invalid setting for your exchange has been selected. Supported price types are gonna differs between each exchanges. Please check with your exchange on which price types it supports.

    Stoploss on exchange on futures markets can trigger on different price types. The naming for these prices in exchange terminology often varies, but is usually something around \"last\" (or \"contract price\" ), \"mark\" and \"index\".

    Acceptable values for this setting are \"last\", \"mark\" and \"index\" - which freqtrade will transfer automatically to the corresponding API type, and place the stoploss on exchange order correspondingly.

    "},{"location":"stoploss/#force_exit","title":"force_exit","text":"

    force_exit is an optional value, which defaults to the same value as exit and is used when sending a /forceexit command from Telegram or from the Rest API.

    "},{"location":"stoploss/#force_entry","title":"force_entry","text":"

    force_entry is an optional value, which defaults to the same value as entry and is used when sending a /forceentry command from Telegram or from the Rest API.

    "},{"location":"stoploss/#emergency_exit","title":"emergency_exit","text":"

    emergency_exit is an optional value, which defaults to market and is used when creating stop loss on exchange orders fails. The below is the default which is used if not changed in strategy or configuration file.

    Example from strategy file:

    order_types = {\n    \"entry\": \"limit\",\n    \"exit\": \"limit\",\n    \"emergency_exit\": \"market\",\n    \"stoploss\": \"market\",\n    \"stoploss_on_exchange\": True,\n    \"stoploss_on_exchange_interval\": 60,\n    \"stoploss_on_exchange_limit_ratio\": 0.99\n}\n
    "},{"location":"stoploss/#stop-loss-types","title":"Stop Loss Types","text":"

    At this stage the bot contains the following stoploss support modes:

    1. Static stop loss.
    2. Trailing stop loss.
    3. Trailing stop loss, custom positive loss.
    4. Trailing stop loss only once the trade has reached a certain offset.
    5. Custom stoploss function
    "},{"location":"stoploss/#static-stop-loss","title":"Static Stop Loss","text":"

    This is very simple, you define a stop loss of x (as a ratio of price, i.e. x * 100% of price). This will try to sell the asset once the loss exceeds the defined loss.

    Example of stop loss:

        stoploss = -0.10\n

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    "},{"location":"stoploss/#trailing-stop-loss","title":"Trailing Stop Loss","text":"

    The initial value for this is stoploss, just as you would define your static Stop loss. To enable trailing stoploss:

        stoploss = -0.10\n    trailing_stop = True\n

    This will now activate an algorithm, which automatically moves the stop loss up every time the price of your asset increases.

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    • assuming the asset now increases to 102$
    • the stop loss will now be -10% of 102$ = 91.8$
    • now the asset drops in value to 101$, the stop loss will still be 91.8$ and would trigger at 91.8$.

    In summary: The stoploss will be adjusted to be always be -10% of the highest observed price.

    "},{"location":"stoploss/#trailing-stop-loss-custom-positive-loss","title":"Trailing stop loss, custom positive loss","text":"

    You could also have a default stop loss when you are in the red with your buy (buy - fee), but once you hit a positive result (or an offset you define) the system will utilize a new stop loss, which can have a different value. For example, your default stop loss is -10%, but once you have more than 0% profit (example 0.1%) a different trailing stoploss will be used.

    Note

    If you want the stoploss to only be changed when you break even of making a profit (what most users want) please refer to next section with offset enabled.

    Both values require trailing_stop to be set to true and trailing_stop_positive with a value.

        stoploss = -0.10\n    trailing_stop = True\n    trailing_stop_positive = 0.02\n    trailing_stop_positive_offset = 0.0\n    trailing_only_offset_is_reached = False  # Default - not necessary for this example\n

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    • assuming the asset now increases to 102$
    • the stop loss will now be -2% of 102$ = 99.96$ (99.96$ stop loss will be locked in and will follow asset price increments with -2%)
    • now the asset drops in value to 101$, the stop loss will still be 99.96$ and would trigger at 99.96$

    The 0.02 would translate to a -2% stop loss. Before this, stoploss is used for the trailing stoploss.

    Use an offset to change your stoploss

    Use trailing_stop_positive_offset to ensure that your new trailing stoploss will be in profit by setting trailing_stop_positive_offset higher than trailing_stop_positive. Your first new stoploss value will then already have locked in profits.

    Example with simplified math:

        stoploss = -0.10\n    trailing_stop = True\n    trailing_stop_positive = 0.02\n    trailing_stop_positive_offset = 0.03\n
    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%, so the stop loss would get triggered once the asset drops below 90$
    • assuming the asset now increases to 102$
    • the stoploss will now be at 91.8$ - 10% below the highest observed rate
    • assuming the asset now increases to 103.5$ (above the offset configured)
    • the stop loss will now be -2% of 103.5$ = 101.43$
    • now the asset drops in value to 102$, the stop loss will still be 101.43$ and would trigger once price breaks below 101.43$
    "},{"location":"stoploss/#trailing-stop-loss-only-once-the-trade-has-reached-a-certain-offset","title":"Trailing stop loss only once the trade has reached a certain offset","text":"

    You can also keep a static stoploss until the offset is reached, and then trail the trade to take profits once the market turns.

    If trailing_only_offset_is_reached = True then the trailing stoploss is only activated once the offset is reached. Until then, the stoploss remains at the configured stoploss. This option can be used with or without trailing_stop_positive, but uses trailing_stop_positive_offset as offset.

    Configuration (offset is buy-price + 3%):

        stoploss = -0.10\n    trailing_stop = True\n    trailing_stop_positive = 0.02\n    trailing_stop_positive_offset = 0.03\n    trailing_only_offset_is_reached = True\n

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    • stoploss will remain at 90$ unless asset increases to or above the configured offset
    • assuming the asset now increases to 103$ (where we have the offset configured)
    • the stop loss will now be -2% of 103$ = 100.94$
    • now the asset drops in value to 101$, the stop loss will still be 100.94$ and would trigger at 100.94$

    Tip

    Make sure to have this value (trailing_stop_positive_offset) lower than minimal ROI, otherwise minimal ROI will apply first and sell the trade.

    "},{"location":"stoploss/#stoploss-and-leverage","title":"Stoploss and Leverage","text":"

    Stoploss should be thought of as \"risk on this trade\" - so a stoploss of 10% on a 100$ trade means you are willing to lose 10$ (10%) on this trade - which would trigger if the price moves 10% to the downside.

    When using leverage, the same principle is applied - with stoploss defining the risk on the trade (the amount you are willing to lose).

    Therefore, a stoploss of 10% on a 10x trade would trigger on a 1% price move. If your stake amount (own capital) was 100$ - this trade would be 1000$ at 10x (after leverage). If price moves 1% - you've lost 10$ of your own capital - therefore stoploss will trigger in this case.

    Make sure to be aware of this, and avoid using too tight stoploss (at 10x leverage, 10% risk may be too little to allow the trade to \"breath\" a little).

    "},{"location":"stoploss/#changing-stoploss-on-open-trades","title":"Changing stoploss on open trades","text":"

    A stoploss on an open trade can be changed by changing the value in the configuration or strategy and use the /reload_config command (alternatively, completely stopping and restarting the bot also works).

    The new stoploss value will be applied to open trades (and corresponding log-messages will be generated).

    "},{"location":"stoploss/#limitations","title":"Limitations","text":"

    Stoploss values cannot be changed if trailing_stop is enabled and the stoploss has already been adjusted, or if Edge is enabled (since Edge would recalculate stoploss based on the current market situation).

    "},{"location":"strategy-advanced/","title":"Advanced Strategies","text":"

    This page explains some advanced concepts available for strategies. If you're just getting started, please familiarize yourself with the Freqtrade basics and methods described in Strategy Customization first.

    The call sequence of the methods described here is covered under bot execution logic. Those docs are also helpful in deciding which method is most suitable for your customisation needs.

    Note

    Callback methods should only be implemented if a strategy uses them.

    Tip

    Start off with a strategy template containing all available callback methods by running freqtrade new-strategy --strategy MyAwesomeStrategy --template advanced

    "},{"location":"strategy-advanced/#storing-information-persistent","title":"Storing information (Persistent)","text":"

    Freqtrade allows storing/retrieving user custom information associated with a specific trade in the database.

    Using a trade object, information can be stored using trade.set_custom_data(key='my_key', value=my_value) and retrieved using trade.get_custom_data(key='my_key'). Each data entry is associated with a trade and a user supplied key (of type string). This means that this can only be used in callbacks that also provide a trade object.

    For the data to be able to be stored within the database, freqtrade must serialized the data. This is done by converting the data to a JSON formatted string. Freqtrade will attempt to reverse this action on retrieval, so from a strategy perspective, this should not be relevant.

    from freqtrade.persistence import Trade\nfrom datetime import timedelta\n\nclass AwesomeStrategy(IStrategy):\n\n    def bot_loop_start(self, **kwargs) -> None:\n        for trade in Trade.get_open_order_trades():\n            fills = trade.select_filled_orders(trade.entry_side)\n            if trade.pair == 'ETH/USDT':\n                trade_entry_type = trade.get_custom_data(key='entry_type')\n                if trade_entry_type is None:\n                    trade_entry_type = 'breakout' if 'entry_1' in trade.enter_tag else 'dip'\n                elif fills > 1:\n                    trade_entry_type = 'buy_up'\n                trade.set_custom_data(key='entry_type', value=trade_entry_type)\n        return super().bot_loop_start(**kwargs)\n\n    def adjust_entry_price(self, trade: Trade, order: Optional[Order], pair: str,\n                           current_time: datetime, proposed_rate: float, current_order_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n        # Limit orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair.\n        if (\n            pair == 'BTC/USDT' \n            and entry_tag == 'long_sma200' \n            and side == 'long' \n            and (current_time - timedelta(minutes=10)) > trade.open_date_utc \n            and order.filled == 0.0\n        ):\n            dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)\n            current_candle = dataframe.iloc[-1].squeeze()\n            # store information about entry adjustment\n            existing_count = trade.get_custom_data('num_entry_adjustments', default=0)\n            if not existing_count:\n                existing_count = 1\n            else:\n                existing_count += 1\n            trade.set_custom_data(key='num_entry_adjustments', value=existing_count)\n\n            # adjust order price\n            return current_candle['sma_200']\n\n        # default: maintain existing order\n        return current_order_rate\n\n    def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs):\n\n        entry_adjustment_count = trade.get_custom_data(key='num_entry_adjustments')\n        trade_entry_type = trade.get_custom_data(key='entry_type')\n        if entry_adjustment_count is None:\n            if current_profit > 0.01 and (current_time - timedelta(minutes=100) > trade.open_date_utc):\n                return True, 'exit_1'\n        else\n            if entry_adjustment_count > 0 and if current_profit > 0.05:\n                return True, 'exit_2'\n            if trade_entry_type == 'breakout' and current_profit > 0.1:\n                return True, 'exit_3\n\n        return False, None\n

    The above is a simple example - there are simpler ways to retrieve trade data like entry-adjustments.

    Note

    It is recommended that simple data types are used [bool, int, float, str] to ensure no issues when serializing the data that needs to be stored. Storing big junks of data may lead to unintended side-effects, like a database becoming big (and as a consequence, also slow).

    Non-serializable data

    If supplied data cannot be serialized a warning is logged and the entry for the specified key will contain None as data.

    All attributes

    custom-data has the following accessors through the Trade object (assumed as trade below):

    • trade.get_custom_data(key='something', default=0) - Returns the actual value given in the type provided.
    • trade.get_custom_data_entry(key='something') - Returns the entry - including metadata. The value is accessible via .value property.
    • trade.set_custom_data(key='something', value={'some': 'value'}) - set or update the corresponding key for this trade. Value must be serializable - and we recommend to keep the stored data relatively small.

    \"value\" can be any type (both in setting and receiving) - but must be json serializable.

    "},{"location":"strategy-advanced/#storing-information-non-persistent","title":"Storing information (Non-Persistent)","text":"

    Deprecated

    This method of storing information is deprecated and we do advise against using non-persistent storage. Please use Persistent Storage instead.

    It's content has therefore been collapsed.

    Storing information

    Storing information can be accomplished by creating a new dictionary within the strategy class.

    The name of the variable can be chosen at will, but should be prefixed with custom_ to avoid naming collisions with predefined strategy variables.

    class AwesomeStrategy(IStrategy):\n    # Create custom dictionary\n    custom_info = {}\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # Check if the entry already exists\n        if not metadata[\"pair\"] in self.custom_info:\n            # Create empty entry for this pair\n            self.custom_info[metadata[\"pair\"]] = {}\n\n        if \"crosstime\" in self.custom_info[metadata[\"pair\"]]:\n            self.custom_info[metadata[\"pair\"]][\"crosstime\"] += 1\n        else:\n            self.custom_info[metadata[\"pair\"]][\"crosstime\"] = 1\n

    Warning

    The data is not persisted after a bot-restart (or config-reload). Also, the amount of data should be kept smallish (no DataFrames and such), otherwise the bot will start to consume a lot of memory and eventually run out of memory and crash.

    Note

    If the data is pair-specific, make sure to use pair as one of the keys in the dictionary.

    "},{"location":"strategy-advanced/#dataframe-access","title":"Dataframe access","text":"

    You may access dataframe in various strategy functions by querying it from dataprovider.

    from freqtrade.exchange import timeframe_to_prev_date\n\nclass AwesomeStrategy(IStrategy):\n    def confirm_trade_exit(self, pair: str, trade: 'Trade', order_type: str, amount: float,\n                           rate: float, time_in_force: str, exit_reason: str,\n                           current_time: 'datetime', **kwargs) -> bool:\n        # Obtain pair dataframe.\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n\n        # Obtain last available candle. Do not use current_time to look up latest candle, because \n        # current_time points to current incomplete candle whose data is not available.\n        last_candle = dataframe.iloc[-1].squeeze()\n        # <...>\n\n        # In dry/live runs trade open date will not match candle open date therefore it must be \n        # rounded.\n        trade_date = timeframe_to_prev_date(self.timeframe, trade.open_date_utc)\n        # Look up trade candle.\n        trade_candle = dataframe.loc[dataframe['date'] == trade_date]\n        # trade_candle may be empty for trades that just opened as it is still incomplete.\n        if not trade_candle.empty:\n            trade_candle = trade_candle.squeeze()\n            # <...>\n

    Using .iloc[-1]

    You can use .iloc[-1] here because get_analyzed_dataframe() only returns candles that backtesting is allowed to see. This will not work in populate_* methods, so make sure to not use .iloc[] in that area. Also, this will only work starting with version 2021.5.

    "},{"location":"strategy-advanced/#enter-tag","title":"Enter Tag","text":"

    When your strategy has multiple buy signals, you can name the signal that triggered. Then you can access your buy signal on custom_exit

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (dataframe['rsi'] < 35) &\n            (dataframe['volume'] > 0)\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'buy_signal_rsi')\n\n    return dataframe\n\ndef custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,\n                current_profit: float, **kwargs):\n    dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n    last_candle = dataframe.iloc[-1].squeeze()\n    if trade.enter_tag == 'buy_signal_rsi' and last_candle['rsi'] > 80:\n        return 'sell_signal_rsi'\n    return None\n

    Note

    enter_tag is limited to 100 characters, remaining data will be truncated.

    Warning

    There is only one enter_tag column, which is used for both long and short trades. As a consequence, this column must be treated as \"last write wins\" (it's just a dataframe column after all). In fancy situations, where multiple signals collide (or if signals are deactivated again based on different conditions), this can lead to odd results with the wrong tag applied to an entry signal. These results are a consequence of the strategy overwriting prior tags - where the last tag will \"stick\" and will be the one freqtrade will use.

    "},{"location":"strategy-advanced/#exit-tag","title":"Exit tag","text":"

    Similar to Entry Tagging, you can also specify an exit tag.

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (dataframe['rsi'] > 70) &\n            (dataframe['volume'] > 0)\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'exit_rsi')\n\n    return dataframe\n

    The provided exit-tag is then used as sell-reason - and shown as such in backtest results.

    Note

    exit_reason is limited to 100 characters, remaining data will be truncated.

    "},{"location":"strategy-advanced/#strategy-version","title":"Strategy version","text":"

    You can implement custom strategy versioning by using the \"version\" method, and returning the version you would like this strategy to have.

    def version(self) -> str:\n    \"\"\"\n    Returns version of the strategy.\n    \"\"\"\n    return \"1.1\"\n

    Note

    You should make sure to implement proper version control (like a git repository) alongside this, as freqtrade will not keep historic versions of your strategy, so it's up to the user to be able to eventually roll back to a prior version of the strategy.

    "},{"location":"strategy-advanced/#derived-strategies","title":"Derived strategies","text":"

    The strategies can be derived from other strategies. This avoids duplication of your custom strategy code. You can use this technique to override small parts of your main strategy, leaving the rest untouched:

    user_data/strategies/myawesomestrategy.py
    class MyAwesomeStrategy(IStrategy):\n    ...\n    stoploss = 0.13\n    trailing_stop = False\n    # All other attributes and methods are here as they\n    # should be in any custom strategy...\n    ...\n
    user_data/strategies/MyAwesomeStrategy2.py
    from myawesomestrategy import MyAwesomeStrategy\nclass MyAwesomeStrategy2(MyAwesomeStrategy):\n    # Override something\n    stoploss = 0.08\n    trailing_stop = True\n

    Both attributes and methods may be overridden, altering behavior of the original strategy in a way you need.

    While keeping the subclass in the same file is technically possible, it can lead to some problems with hyperopt parameter files, we therefore recommend to use separate strategy files, and import the parent strategy as shown above.

    "},{"location":"strategy-advanced/#embedding-strategies","title":"Embedding Strategies","text":"

    Freqtrade provides you with an easy way to embed the strategy into your configuration file. This is done by utilizing BASE64 encoding and providing this string at the strategy configuration field, in your chosen config file.

    "},{"location":"strategy-advanced/#encoding-a-string-as-base64","title":"Encoding a string as BASE64","text":"

    This is a quick example, how to generate the BASE64 string in python

    from base64 import urlsafe_b64encode\n\nwith open(file, 'r') as f:\n    content = f.read()\ncontent = urlsafe_b64encode(content.encode('utf-8'))\n

    The variable 'content', will contain the strategy file in a BASE64 encoded form. Which can now be set in your configurations file as following

    \"strategy\": \"NameOfStrategy:BASE64String\"\n

    Please ensure that 'NameOfStrategy' is identical to the strategy name!

    "},{"location":"strategy-advanced/#performance-warning","title":"Performance warning","text":"

    When executing a strategy, one can sometimes be greeted by the following in the logs

    PerformanceWarning: DataFrame is highly fragmented.

    This is a warning from pandas and as the warning continues to say: use pd.concat(axis=1). This can have slight performance implications, which are usually only visible during hyperopt (when optimizing an indicator).

    For example:

    for val in self.buy_ema_short.range:\n    dataframe[f'ema_short_{val}'] = ta.EMA(dataframe, timeperiod=val)\n

    should be rewritten to

    frames = [dataframe]\nfor val in self.buy_ema_short.range:\n    frames.append(DataFrame({\n        f'ema_short_{val}': ta.EMA(dataframe, timeperiod=val)\n    }))\n\n# Combine all dataframes, and reassign the original dataframe column\ndataframe = pd.concat(frames, axis=1)\n

    Freqtrade does however also counter this by running dataframe.copy() on the dataframe right after the populate_indicators() method - so performance implications of this should be low to non-existent.

    "},{"location":"strategy-callbacks/","title":"Strategy Callbacks","text":"

    While the main strategy functions (populate_indicators(), populate_entry_trend(), populate_exit_trend()) should be used in a vectorized way, and are only called once during backtesting, callbacks are called \"whenever needed\".

    As such, you should avoid doing heavy calculations in callbacks to avoid delays during operations. Depending on the callback used, they may be called when entering / exiting a trade, or throughout the duration of a trade.

    Currently available callbacks:

    • bot_start()
    • bot_loop_start()
    • custom_stake_amount()
    • custom_exit()
    • custom_stoploss()
    • custom_entry_price() and custom_exit_price()
    • check_entry_timeout() and check_exit_timeout()
    • confirm_trade_entry()
    • confirm_trade_exit()
    • adjust_trade_position()
    • adjust_entry_price()
    • leverage()
    • order_filled()

    Callback calling sequence

    You can find the callback calling sequence in bot-basics

    "},{"location":"strategy-callbacks/#imports-necessary-for-a-strategy","title":"Imports necessary for a strategy","text":"

    When creating a strategy, you will need to import the necessary modules and classes. The following imports are required for a strategy:

    By default, we recommend the following imports as a base line for your strategy: This will cover all imports necessary for freqtrade functions to work. Obviously you can add more imports as needed for your strategy.

    # flake8: noqa: F401\n# isort: skip_file\n# --- Do not remove these imports ---\nimport numpy as np\nimport pandas as pd\nfrom datetime import datetime, timedelta, timezone\nfrom pandas import DataFrame\nfrom typing import Dict, Optional, Union, Tuple\n\nfrom freqtrade.strategy import (\n    IStrategy,\n    Trade, \n    Order,\n    PairLocks,\n    informative,  # @informative decorator\n    # Hyperopt Parameters\n    BooleanParameter,\n    CategoricalParameter,\n    DecimalParameter,\n    IntParameter,\n    RealParameter,\n    # timeframe helpers\n    timeframe_to_minutes,\n    timeframe_to_next_date,\n    timeframe_to_prev_date,\n    # Strategy helper functions\n    merge_informative_pair,\n    stoploss_from_absolute,\n    stoploss_from_open,\n)\n\n# --------------------------------\n# Add your lib to import here\nimport talib.abstract as ta\nfrom technical import qtpylib\n
    "},{"location":"strategy-callbacks/#bot-start","title":"Bot start","text":"

    A simple callback which is called once when the strategy is loaded. This can be used to perform actions that must only be performed once and runs after dataprovider and wallet are set

    import requests\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def bot_start(self, **kwargs) -> None:\n        \"\"\"\n        Called only once after bot instantiation.\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        \"\"\"\n        if self.config[\"runmode\"].value in (\"live\", \"dry_run\"):\n            # Assign this to the class by using self.*\n            # can then be used by populate_* methods\n            self.custom_remote_data = requests.get(\"https://some_remote_source.example.com\")\n

    During hyperopt, this runs only once at startup.

    "},{"location":"strategy-callbacks/#bot-loop-start","title":"Bot loop start","text":"

    A simple callback which is called once at the start of every bot throttling iteration in dry/live mode (roughly every 5 seconds, unless configured differently) or once per candle in backtest/hyperopt mode. This can be used to perform calculations which are pair independent (apply to all pairs), loading of external data, etc.

    # Default imports\nimport requests\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def bot_loop_start(self, current_time: datetime, **kwargs) -> None:\n        \"\"\"\n        Called at the start of the bot iteration (one loop).\n        Might be used to perform pair-independent tasks\n        (e.g. gather some remote resource for comparison)\n        :param current_time: datetime object, containing the current datetime\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        \"\"\"\n        if self.config[\"runmode\"].value in (\"live\", \"dry_run\"):\n            # Assign this to the class by using self.*\n            # can then be used by populate_* methods\n            self.remote_data = requests.get(\"https://some_remote_source.example.com\")\n
    "},{"location":"strategy-callbacks/#stake-size-management","title":"Stake size management","text":"

    Called before entering a trade, makes it possible to manage your position size when placing a new trade.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            leverage: float, entry_tag: Optional[str], side: str,\n                            **kwargs) -> float:\n\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)\n        current_candle = dataframe.iloc[-1].squeeze()\n\n        if current_candle[\"fastk_rsi_1h\"] > current_candle[\"fastd_rsi_1h\"]:\n            if self.config[\"stake_amount\"] == \"unlimited\":\n                # Use entire available wallet during favorable conditions when in compounding mode.\n                return max_stake\n            else:\n                # Compound profits during favorable conditions instead of using a static stake.\n                return self.wallets.get_total_stake_amount() / self.config[\"max_open_trades\"]\n\n        # Use default stake amount.\n        return proposed_stake\n

    Freqtrade will fall back to the proposed_stake value should your code raise an exception. The exception itself will be logged.

    Tip

    You do not have to ensure that min_stake <= returned_value <= max_stake. Trades will succeed as the returned value will be clamped to supported range and this action will be logged.

    Tip

    Returning 0 or None will prevent trades from being placed.

    "},{"location":"strategy-callbacks/#custom-exit-signal","title":"Custom exit signal","text":"

    Called for open trade every throttling iteration (roughly every 5 seconds) until a trade is closed.

    Allows to define custom exit signals, indicating that specified position should be sold. This is very useful when we need to customize exit conditions for each individual trade, or if you need trade data to make an exit decision.

    For example you could implement a 1:2 risk-reward ROI with custom_exit().

    Using custom_exit() signals in place of stoploss though is not recommended. It is a inferior method to using custom_stoploss() in this regard - which also allows you to keep the stoploss on exchange.

    Note

    Returning a (none-empty) string or True from this method is equal to setting exit signal on a candle at specified time. This method is not called when exit signal is set already, or if exit signals are disabled (use_exit_signal=False). string max length is 64 characters. Exceeding this limit will cause the message to be truncated to 64 characters. custom_exit() will ignore exit_profit_only, and will always be called unless use_exit_signal=False, even if there is a new enter signal.

    An example of how we can use different indicators depending on the current profit and also exit trades that were open longer than one day:

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,\n                    current_profit: float, **kwargs):\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n\n        # Above 20% profit, sell when rsi < 80\n        if current_profit > 0.2:\n            if last_candle[\"rsi\"] < 80:\n                return \"rsi_below_80\"\n\n        # Between 2% and 10%, sell if EMA-long above EMA-short\n        if 0.02 < current_profit < 0.1:\n            if last_candle[\"emalong\"] > last_candle[\"emashort\"]:\n                return \"ema_long_below_80\"\n\n        # Sell any positions at a loss if they are held for more than one day.\n        if current_profit < 0.0 and (current_time - trade.open_date_utc).days >= 1:\n            return \"unclog\"\n

    See Dataframe access for more information about dataframe use in strategy callbacks.

    "},{"location":"strategy-callbacks/#custom-stoploss","title":"Custom stoploss","text":"

    Called for open trade every iteration (roughly every 5 seconds) until a trade is closed.

    The usage of the custom stoploss method must be enabled by setting use_custom_stoploss=True on the strategy object.

    The stoploss price can only ever move upwards - if the stoploss value returned from custom_stoploss would result in a lower stoploss price than was previously set, it will be ignored. The traditional stoploss value serves as an absolute lower level and will be instated as the initial stoploss (before this method is called for the first time for a trade), and is still mandatory.

    The method must return a stoploss value (float / number) as a percentage of the current price. E.g. If the current_rate is 200 USD, then returning 0.02 will set the stoploss price 2% lower, at 196 USD. During backtesting, current_rate (and current_profit) are provided against the candle's high (or low for short trades) - while the resulting stoploss is evaluated against the candle's low (or high for short trades).

    The absolute value of the return value is used (the sign is ignored), so returning 0.05 or -0.05 have the same result, a stoploss 5% below the current price. Returning None will be interpreted as \"no desire to change\", and is the only safe way to return when you'd like to not modify the stoploss. NaN and inf values are considered invalid and will be ignored (identical to None).

    Stoploss on exchange works similar to trailing_stop, and the stoploss on exchange is updated as configured in stoploss_on_exchange_interval (More details about stoploss on exchange).

    Use of dates

    All time-based calculations should be done based on current_time - using datetime.now() or datetime.utcnow() is discouraged, as this will break backtesting support.

    Trailing stoploss

    It's recommended to disable trailing_stop when using custom stoploss values. Both can work in tandem, but you might encounter the trailing stop to move the price higher while your custom function would not want this, causing conflicting behavior.

    "},{"location":"strategy-callbacks/#adjust-stoploss-after-position-adjustments","title":"Adjust stoploss after position adjustments","text":"

    Depending on your strategy, you may encounter the need to adjust the stoploss in both directions after a position adjustment. For this, freqtrade will make an additional call with after_fill=True after an order fills, which will allow the strategy to move the stoploss in any direction (also widening the gap between stoploss and current price, which is otherwise forbidden).

    backwards compatibility

    This call will only be made if the after_fill parameter is part of the function definition of your custom_stoploss function. As such, this will not impact (and with that, surprise) existing, running strategies.

    "},{"location":"strategy-callbacks/#custom-stoploss-examples","title":"Custom stoploss examples","text":"

    The next section will show some examples on what's possible with the custom stoploss function. Of course, many more things are possible, and all examples can be combined at will.

    "},{"location":"strategy-callbacks/#trailing-stop-via-custom-stoploss","title":"Trailing stop via custom stoploss","text":"

    To simulate a regular trailing stoploss of 4% (trailing 4% behind the maximum reached price) you would use the following very simple method:

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n        \"\"\"\n        Custom stoploss logic, returning the new distance relative to current_rate (as ratio).\n        e.g. returning -0.05 would create a stoploss 5% below current_rate.\n        The custom stoploss can never be below self.stoploss, which serves as a hard maximum loss.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns the initial stoploss value.\n        Only called when use_custom_stoploss is set to True.\n\n        :param pair: Pair that's currently analyzed\n        :param trade: trade object.\n        :param current_time: datetime object, containing the current datetime\n        :param current_rate: Rate, calculated based on pricing settings in exit_pricing.\n        :param current_profit: Current profit (as ratio), calculated based on current_rate.\n        :param after_fill: True if the stoploss is called after the order was filled.\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return float: New stoploss value, relative to the current_rate\n        \"\"\"\n        return -0.04\n
    "},{"location":"strategy-callbacks/#time-based-trailing-stop","title":"Time based trailing stop","text":"

    Use the initial stoploss for the first 60 minutes, after this change to 10% trailing stoploss, and after 2 hours (120 minutes) we use a 5% trailing stoploss.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n\n        # Make sure you have the longest interval first - these conditions are evaluated from top to bottom.\n        if current_time - timedelta(minutes=120) > trade.open_date_utc:\n            return -0.05\n        elif current_time - timedelta(minutes=60) > trade.open_date_utc:\n            return -0.10\n        return None\n
    "},{"location":"strategy-callbacks/#time-based-trailing-stop-with-after-fill-adjustments","title":"Time based trailing stop with after-fill adjustments","text":"

    Use the initial stoploss for the first 60 minutes, after this change to 10% trailing stoploss, and after 2 hours (120 minutes) we use a 5% trailing stoploss. If an additional order fills, set stoploss to -10% below the new open_rate (Averaged across all entries).

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n\n        if after_fill: \n            # After an additional order, start with a stoploss of 10% below the new open rate\n            return stoploss_from_open(0.10, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n        # Make sure you have the longest interval first - these conditions are evaluated from top to bottom.\n        if current_time - timedelta(minutes=120) > trade.open_date_utc:\n            return -0.05\n        elif current_time - timedelta(minutes=60) > trade.open_date_utc:\n            return -0.10\n        return None\n
    "},{"location":"strategy-callbacks/#different-stoploss-per-pair","title":"Different stoploss per pair","text":"

    Use a different stoploss depending on the pair. In this example, we'll trail the highest price with 10% trailing stoploss for ETH/BTC and XRP/BTC, with 5% trailing stoploss for LTC/BTC and with 15% for all other pairs.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        if pair in (\"ETH/BTC\", \"XRP/BTC\"):\n            return -0.10\n        elif pair in (\"LTC/BTC\"):\n            return -0.05\n        return -0.15\n
    "},{"location":"strategy-callbacks/#trailing-stoploss-with-positive-offset","title":"Trailing stoploss with positive offset","text":"

    Use the initial stoploss until the profit is above 4%, then use a trailing stoploss of 50% of the current profit with a minimum of 2.5% and a maximum of 5%.

    Please note that the stoploss can only increase, values lower than the current stoploss are ignored.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        if current_profit < 0.04:\n            return None # return None to keep using the initial stoploss\n\n        # After reaching the desired offset, allow the stoploss to trail by half the profit\n        desired_stoploss = current_profit / 2\n\n        # Use a minimum of 2.5% and a maximum of 5%\n        return max(min(desired_stoploss, 0.05), 0.025)\n
    "},{"location":"strategy-callbacks/#stepped-stoploss","title":"Stepped stoploss","text":"

    Instead of continuously trailing behind the current price, this example sets fixed stoploss price levels based on the current profit.

    • Use the regular stoploss until 20% profit is reached
    • Once profit is > 20% - set stoploss to 7% above open price.
    • Once profit is > 25% - set stoploss to 15% above open price.
    • Once profit is > 40% - set stoploss to 25% above open price.
    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        # evaluate highest to lowest, so that highest possible stop is used\n        if current_profit > 0.40:\n            return stoploss_from_open(0.25, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n        elif current_profit > 0.25:\n            return stoploss_from_open(0.15, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n        elif current_profit > 0.20:\n            return stoploss_from_open(0.07, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n\n        # return maximum stoploss value, keeping current stoploss price unchanged\n        return None\n
    "},{"location":"strategy-callbacks/#custom-stoploss-using-an-indicator-from-dataframe-example","title":"Custom stoploss using an indicator from dataframe example","text":"

    Absolute stoploss value may be derived from indicators stored in dataframe. Example uses parabolic SAR below the price as stoploss.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # <...>\n        dataframe[\"sar\"] = ta.SAR(dataframe)\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n\n        # Use parabolic sar as absolute stoploss price\n        stoploss_price = last_candle[\"sar\"]\n\n        # Convert absolute price to percentage relative to current_rate\n        if stoploss_price < current_rate:\n            return stoploss_from_absolute(stoploss_price, current_rate, is_short=trade.is_short)\n\n        # return maximum stoploss value, keeping current stoploss price unchanged\n        return None\n

    See Dataframe access for more information about dataframe use in strategy callbacks.

    "},{"location":"strategy-callbacks/#common-helpers-for-stoploss-calculations","title":"Common helpers for stoploss calculations","text":""},{"location":"strategy-callbacks/#stoploss-relative-to-open-price","title":"Stoploss relative to open price","text":"

    Stoploss values returned from custom_stoploss() must specify a percentage relative to current_rate, but sometimes you may want to specify a stoploss relative to the entry price instead. stoploss_from_open() is a helper function to calculate a stoploss value that can be returned from custom_stoploss which will be equivalent to the desired trade profit above the entry point.

    Returning a stoploss relative to the open price from the custom stoploss function

    Say the open price was $100, and current_price is $121 (current_profit will be 0.21).

    If we want a stop price at 7% above the open price we can call stoploss_from_open(0.07, current_profit, False) which will return 0.1157024793. 11.57% below $121 is $107, which is the same as 7% above $100.

    This function will consider leverage - so at 10x leverage, the actual stoploss would be 0.7% above $100 (0.7% * 10x = 7%).

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        # once the profit has risen above 10%, keep the stoploss at 7% above the open price\n        if current_profit > 0.10:\n            return stoploss_from_open(0.07, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n\n        return 1\n

    Full examples can be found in the Custom stoploss section of the Documentation.

    Note

    Providing invalid input to stoploss_from_open() may produce \"CustomStoploss function did not return valid stoploss\" warnings. This may happen if current_profit parameter is below specified open_relative_stop. Such situations may arise when closing trade is blocked by confirm_trade_exit() method. Warnings can be solved by never blocking stop loss sells by checking exit_reason in confirm_trade_exit(), or by using return stoploss_from_open(...) or 1 idiom, which will request to not change stop loss when current_profit < open_relative_stop.

    "},{"location":"strategy-callbacks/#stoploss-percentage-from-absolute-price","title":"Stoploss percentage from absolute price","text":"

    Stoploss values returned from custom_stoploss() always specify a percentage relative to current_rate. In order to set a stoploss at specified absolute price level, we need to use stop_rate to calculate what percentage relative to the current_rate will give you the same result as if the percentage was specified from the open price.

    The helper function stoploss_from_absolute() can be used to convert from an absolute price, to a current price relative stop which can be returned from custom_stoploss().

    Returning a stoploss using absolute price from the custom stoploss function

    If we want to trail a stop price at 2xATR below current price we can call stoploss_from_absolute(current_rate + (side * candle[\"atr\"] * 2), current_rate=current_rate, is_short=trade.is_short, leverage=trade.leverage). For futures, we need to adjust the direction (up or down), as well as adjust for leverage, since the custom_stoploss callback returns the \"risk for this trade\" - not the relative price movement.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    use_custom_stoploss = True\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe[\"atr\"] = ta.ATR(dataframe, timeperiod=14)\n        return dataframe\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        trade_date = timeframe_to_prev_date(self.timeframe, trade.open_date_utc)\n        candle = dataframe.iloc[-1].squeeze()\n        side = 1 if trade.is_short else -1\n        return stoploss_from_absolute(current_rate + (side * candle[\"atr\"] * 2), \n                                      current_rate=current_rate, \n                                      is_short=trade.is_short,\n                                      leverage=trade.leverage)\n
    "},{"location":"strategy-callbacks/#custom-order-price-rules","title":"Custom order price rules","text":"

    By default, freqtrade use the orderbook to automatically set an order price(Relevant documentation), you also have the option to create custom order prices based on your strategy.

    You can use this feature by creating a custom_entry_price() function in your strategy file to customize entry prices and custom_exit_price() for exits.

    Each of these methods are called right before placing an order on the exchange.

    Note

    If your custom pricing function return None or an invalid value, price will fall back to proposed_rate, which is based on the regular pricing configuration.

    Note

    Using custom_entry_price, the Trade object will be available as soon as the first entry order associated with the trade is created, for the first entry, trade parameter value will be None.

    "},{"location":"strategy-callbacks/#custom-order-entry-and-exit-price-example","title":"Custom order entry and exit price example","text":"
    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def custom_entry_price(self, pair: str, trade: Optional[Trade], current_time: datetime, proposed_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n\n        dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair,\n                                                                timeframe=self.timeframe)\n        new_entryprice = dataframe[\"bollinger_10_lowerband\"].iat[-1]\n\n        return new_entryprice\n\n    def custom_exit_price(self, pair: str, trade: Trade,\n                          current_time: datetime, proposed_rate: float,\n                          current_profit: float, exit_tag: Optional[str], **kwargs) -> float:\n\n        dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair,\n                                                                timeframe=self.timeframe)\n        new_exitprice = dataframe[\"bollinger_10_upperband\"].iat[-1]\n\n        return new_exitprice\n

    Warning

    Modifying entry and exit prices will only work for limit orders. Depending on the price chosen, this can result in a lot of unfilled orders. By default the maximum allowed distance between the current price and the custom price is 2%, this value can be changed in config with the custom_price_max_distance_ratio parameter. Example: If the new_entryprice is 97, the proposed_rate is 100 and the custom_price_max_distance_ratio is set to 2%, The retained valid custom entry price will be 98, which is 2% below the current (proposed) rate.

    Backtesting

    Custom prices are supported in backtesting (starting with 2021.12), and orders will fill if the price falls within the candle's low/high range. Orders that don't fill immediately are subject to regular timeout handling, which happens once per (detail) candle. custom_exit_price() is only called for sells of type exit_signal, Custom exit and partial exits. All other exit-types will use regular backtesting prices.

    "},{"location":"strategy-callbacks/#custom-order-timeout-rules","title":"Custom order timeout rules","text":"

    Simple, time-based order-timeouts can be configured either via strategy or in the configuration in the unfilledtimeout section.

    However, freqtrade also offers a custom callback for both order types, which allows you to decide based on custom criteria if an order did time out or not.

    Note

    Backtesting fills orders if their price falls within the candle's low/high range. The below callbacks will be called once per (detail) candle for orders that don't fill immediately (which use custom pricing).

    "},{"location":"strategy-callbacks/#custom-order-timeout-example","title":"Custom order timeout example","text":"

    Called for every open order until that order is either filled or cancelled. check_entry_timeout() is called for trade entries, while check_exit_timeout() is called for trade exit orders.

    A simple example, which applies different unfilled-timeouts depending on the price of the asset can be seen below. It applies a tight timeout for higher priced assets, while allowing more time to fill on cheap coins.

    The function must return either True (cancel order) or False (keep order alive).

        # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    # Set unfilledtimeout to 25 hours, since the maximum timeout from below is 24 hours.\n    unfilledtimeout = {\n        \"entry\": 60 * 25,\n        \"exit\": 60 * 25\n    }\n\n    def check_entry_timeout(self, pair: str, trade: Trade, order: Order,\n                            current_time: datetime, **kwargs) -> bool:\n        if trade.open_rate > 100 and trade.open_date_utc < current_time - timedelta(minutes=5):\n            return True\n        elif trade.open_rate > 10 and trade.open_date_utc < current_time - timedelta(minutes=3):\n            return True\n        elif trade.open_rate < 1 and trade.open_date_utc < current_time - timedelta(hours=24):\n           return True\n        return False\n\n\n    def check_exit_timeout(self, pair: str, trade: Trade, order: Order,\n                           current_time: datetime, **kwargs) -> bool:\n        if trade.open_rate > 100 and trade.open_date_utc < current_time - timedelta(minutes=5):\n            return True\n        elif trade.open_rate > 10 and trade.open_date_utc < current_time - timedelta(minutes=3):\n            return True\n        elif trade.open_rate < 1 and trade.open_date_utc < current_time - timedelta(hours=24):\n           return True\n        return False\n

    Note

    For the above example, unfilledtimeout must be set to something bigger than 24h, otherwise that type of timeout will apply first.

    "},{"location":"strategy-callbacks/#custom-order-timeout-example-using-additional-data","title":"Custom order timeout example (using additional data)","text":"
        # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    # Set unfilledtimeout to 25 hours, since the maximum timeout from below is 24 hours.\n    unfilledtimeout = {\n        \"entry\": 60 * 25,\n        \"exit\": 60 * 25\n    }\n\n    def check_entry_timeout(self, pair: str, trade: Trade, order: Order,\n                            current_time: datetime, **kwargs) -> bool:\n        ob = self.dp.orderbook(pair, 1)\n        current_price = ob[\"bids\"][0][0]\n        # Cancel buy order if price is more than 2% above the order.\n        if current_price > order.price * 1.02:\n            return True\n        return False\n\n\n    def check_exit_timeout(self, pair: str, trade: Trade, order: Order,\n                           current_time: datetime, **kwargs) -> bool:\n        ob = self.dp.orderbook(pair, 1)\n        current_price = ob[\"asks\"][0][0]\n        # Cancel sell order if price is more than 2% below the order.\n        if current_price < order.price * 0.98:\n            return True\n        return False\n
    "},{"location":"strategy-callbacks/#bot-order-confirmation","title":"Bot order confirmation","text":"

    Confirm trade entry / exits. This are the last methods that will be called before an order is placed.

    "},{"location":"strategy-callbacks/#trade-entry-buy-order-confirmation","title":"Trade entry (buy order) confirmation","text":"

    confirm_trade_entry() can be used to abort a trade entry at the latest second (maybe because the price is not what we expect).

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,\n                            time_in_force: str, current_time: datetime, entry_tag: Optional[str],\n                            side: str, **kwargs) -> bool:\n        \"\"\"\n        Called right before placing a entry order.\n        Timing for this function is critical, so avoid doing heavy computations or\n        network requests in this method.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns True (always confirming).\n\n        :param pair: Pair that's about to be bought/shorted.\n        :param order_type: Order type (as configured in order_types). usually limit or market.\n        :param amount: Amount in target (base) currency that's going to be traded.\n        :param rate: Rate that's going to be used when using limit orders \n                     or current rate for market orders.\n        :param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).\n        :param current_time: datetime object, containing the current datetime\n        :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.\n        :param side: \"long\" or \"short\" - indicating the direction of the proposed trade\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return bool: When True is returned, then the buy-order is placed on the exchange.\n            False aborts the process\n        \"\"\"\n        return True\n
    "},{"location":"strategy-callbacks/#trade-exit-sell-order-confirmation","title":"Trade exit (sell order) confirmation","text":"

    confirm_trade_exit() can be used to abort a trade exit (sell) at the latest second (maybe because the price is not what we expect).

    confirm_trade_exit() may be called multiple times within one iteration for the same trade if different exit-reasons apply. The exit-reasons (if applicable) will be in the following sequence:

    • exit_signal / custom_exit
    • stop_loss
    • roi
    • trailing_stop_loss
    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,\n                           rate: float, time_in_force: str, exit_reason: str,\n                           current_time: datetime, **kwargs) -> bool:\n        \"\"\"\n        Called right before placing a regular exit order.\n        Timing for this function is critical, so avoid doing heavy computations or\n        network requests in this method.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns True (always confirming).\n\n        :param pair: Pair for trade that's about to be exited.\n        :param trade: trade object.\n        :param order_type: Order type (as configured in order_types). usually limit or market.\n        :param amount: Amount in base currency.\n        :param rate: Rate that's going to be used when using limit orders\n                     or current rate for market orders.\n        :param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).\n        :param exit_reason: Exit reason.\n            Can be any of [\"roi\", \"stop_loss\", \"stoploss_on_exchange\", \"trailing_stop_loss\",\n                           \"exit_signal\", \"force_exit\", \"emergency_exit\"]\n        :param current_time: datetime object, containing the current datetime\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return bool: When True, then the exit-order is placed on the exchange.\n            False aborts the process\n        \"\"\"\n        if exit_reason == \"force_exit\" and trade.calc_profit_ratio(rate) < 0:\n            # Reject force-sells with negative profit\n            # This is just a sample, please adjust to your needs\n            # (this does not necessarily make sense, assuming you know when you're force-selling)\n            return False\n        return True\n

    Warning

    confirm_trade_exit() can prevent stoploss exits, causing significant losses as this would ignore stoploss exits. confirm_trade_exit() will not be called for Liquidations - as liquidations are forced by the exchange, and therefore cannot be rejected.

    "},{"location":"strategy-callbacks/#adjust-trade-position","title":"Adjust trade position","text":"

    The position_adjustment_enable strategy property enables the usage of adjust_trade_position() callback in the strategy. For performance reasons, it's disabled by default and freqtrade will show a warning message on startup if enabled. adjust_trade_position() can be used to perform additional orders, for example to manage risk with DCA (Dollar Cost Averaging) or to increase or decrease positions.

    Additional orders also result in additional fees and those orders don't count towards max_open_trades.

    This callback is not called when there is an open order (either buy or sell) waiting for execution.

    adjust_trade_position() is called very frequently for the duration of a trade, so you must keep your implementation as performant as possible.

    Position adjustments will always be applied in the direction of the trade, so a positive value will always increase your position (negative values will decrease your position), no matter if it's a long or short trade. Adjustment orders can be assigned with a tag by returning a 2 element Tuple, with the first element being the adjustment amount, and the 2nd element the tag (e.g. return 250, \"increase_favorable_conditions\").

    Modifications to leverage are not possible, and the stake-amount returned is assumed to be before applying leverage.

    "},{"location":"strategy-callbacks/#increase-position","title":"Increase position","text":"

    The strategy is expected to return a positive stake_amount (in stake currency) between min_stake and max_stake if and when an additional entry order should be made (position is increased -> buy order for long trades, sell order for short trades).

    If there are not enough funds in the wallet (the return value is above max_stake) then the signal will be ignored. max_entry_position_adjustment property is used to limit the number of additional entries per trade (on top of the first entry order) that the bot can execute. By default, the value is -1 which means the bot have no limit on number of adjustment entries.

    Additional entries are ignored once you have reached the maximum amount of extra entries that you have set on max_entry_position_adjustment, but the callback is called anyway looking for partial exits.

    "},{"location":"strategy-callbacks/#decrease-position","title":"Decrease position","text":"

    The strategy is expected to return a negative stake_amount (in stake currency) for a partial exit. Returning the full owned stake at that point (-trade.stake_amount) results in a full exit. Returning a value more than the above (so remaining stake_amount would become negative) will result in the bot ignoring the signal.

    About stake size

    Using fixed stake size means it will be the amount used for the first order, just like without position adjustment. If you wish to buy additional orders with DCA, then make sure to leave enough funds in the wallet for that. Using \"unlimited\" stake amount with DCA orders requires you to also implement the custom_stake_amount() callback to avoid allocating all funds to the initial order.

    Stoploss calculation

    Stoploss is still calculated from the initial opening price, not averaged price. Regular stoploss rules still apply (cannot move down).

    While /stopentry command stops the bot from entering new trades, the position adjustment feature will continue buying new orders on existing trades.

    Backtesting

    During backtesting this callback is called for each candle in timeframe or timeframe_detail, so run-time performance will be affected. This can also cause deviating results between live and backtesting, since backtesting can adjust the trade only once per candle, whereas live could adjust the trade multiple times per candle.

    Performance with many position adjustments

    Position adjustments can be a good approach to increase a strategy's output - but it can also have drawbacks if using this feature extensively. Each of the orders will be attached to the trade object for the duration of the trade - hence increasing memory usage. Trades with long duration and 10s or even 100ds of position adjustments are therefore not recommended, and should be closed at regular intervals to not affect performance.

    # Default imports\n\nclass DigDeeperStrategy(IStrategy):\n\n    position_adjustment_enable = True\n\n    # Attempts to handle large drops with DCA. High stoploss is required.\n    stoploss = -0.30\n\n    # ... populate_* methods\n\n    # Example specific variables\n    max_entry_position_adjustment = 3\n    # This number is explained a bit further down\n    max_dca_multiplier = 5.5\n\n    # This is called when placing the initial order (opening trade)\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            leverage: float, entry_tag: Optional[str], side: str,\n                            **kwargs) -> float:\n\n        # We need to leave most of the funds for possible further DCA orders\n        # This also applies to fixed stakes\n        return proposed_stake / self.max_dca_multiplier\n\n    def adjust_trade_position(self, trade: Trade, current_time: datetime,\n                              current_rate: float, current_profit: float,\n                              min_stake: Optional[float], max_stake: float,\n                              current_entry_rate: float, current_exit_rate: float,\n                              current_entry_profit: float, current_exit_profit: float,\n                              **kwargs\n                              ) -> Union[Optional[float], Tuple[Optional[float], Optional[str]]]:\n        \"\"\"\n        Custom trade adjustment logic, returning the stake amount that a trade should be\n        increased or decreased.\n        This means extra entry or exit orders with additional fees.\n        Only called when `position_adjustment_enable` is set to True.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns None\n\n        :param trade: trade object.\n        :param current_time: datetime object, containing the current datetime\n        :param current_rate: Current entry rate (same as current_entry_profit)\n        :param current_profit: Current profit (as ratio), calculated based on current_rate \n                               (same as current_entry_profit).\n        :param min_stake: Minimal stake size allowed by exchange (for both entries and exits)\n        :param max_stake: Maximum stake allowed (either through balance, or by exchange limits).\n        :param current_entry_rate: Current rate using entry pricing.\n        :param current_exit_rate: Current rate using exit pricing.\n        :param current_entry_profit: Current profit using entry pricing.\n        :param current_exit_profit: Current profit using exit pricing.\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return float: Stake amount to adjust your trade,\n                       Positive values to increase position, Negative values to decrease position.\n                       Return None for no action.\n                       Optionally, return a tuple with a 2nd element with an order reason\n        \"\"\"\n\n        if current_profit > 0.05 and trade.nr_of_successful_exits == 0:\n            # Take half of the profit at +5%\n            return -(trade.stake_amount / 2), \"half_profit_5%\"\n\n        if current_profit > -0.05:\n            return None\n\n        # Obtain pair dataframe (just to show how to access it)\n        dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)\n        # Only buy when not actively falling price.\n        last_candle = dataframe.iloc[-1].squeeze()\n        previous_candle = dataframe.iloc[-2].squeeze()\n        if last_candle[\"close\"] < previous_candle[\"close\"]:\n            return None\n\n        filled_entries = trade.select_filled_orders(trade.entry_side)\n        count_of_entries = trade.nr_of_successful_entries\n        # Allow up to 3 additional increasingly larger buys (4 in total)\n        # Initial buy is 1x\n        # If that falls to -5% profit, we buy 1.25x more, average profit should increase to roughly -2.2%\n        # If that falls down to -5% again, we buy 1.5x more\n        # If that falls once again down to -5%, we buy 1.75x more\n        # Total stake for this trade would be 1 + 1.25 + 1.5 + 1.75 = 5.5x of the initial allowed stake.\n        # That is why max_dca_multiplier is 5.5\n        # Hope you have a deep wallet!\n        try:\n            # This returns first order stake size\n            stake_amount = filled_entries[0].stake_amount\n            # This then calculates current safety order size\n            stake_amount = stake_amount * (1 + (count_of_entries * 0.25))\n            return stake_amount, \"1/3rd_increase\"\n        except Exception as exception:\n            return None\n\n        return None\n
    "},{"location":"strategy-callbacks/#position-adjust-calculations","title":"Position adjust calculations","text":"
    • Entry rates are calculated using weighted averages.
    • Exits will not influence the average entry rate.
    • Partial exit relative profit is relative to the average entry price at this point.
    • Final exit relative profit is calculated based on the total invested capital. (See example below)
    Calculation example

    This example assumes 0 fees for simplicity, and a long position on an imaginary coin.

    • Buy 100@8$
    • Buy 100@9$ -> Avg price: 8.5$
    • Sell 100@10$ -> Avg price: 8.5$, realized profit 150$, 17.65%
    • Buy 150@11$ -> Avg price: 10$, realized profit 150$, 17.65%
    • Sell 100@12$ -> Avg price: 10$, total realized profit 350$, 20%
    • Sell 150@14$ -> Avg price: 10$, total realized profit 950$, 40% <- This will be the last \"Exit\" message

    The total profit for this trade was 950$ on a 3350$ investment (100@8$ + 100@9$ + 150@11$). As such - the final relative profit is 28.35% (950 / 3350).

    "},{"location":"strategy-callbacks/#adjust-entry-price","title":"Adjust Entry Price","text":"

    The adjust_entry_price() callback may be used by strategy developer to refresh/replace limit orders upon arrival of new candles. Be aware that custom_entry_price() is still the one dictating initial entry limit order price target at the time of entry trigger.

    Orders can be cancelled out of this callback by returning None.

    Returning current_order_rate will keep the order on the exchange \"as is\". Returning any other price will cancel the existing order, and replace it with a new order.

    The trade open-date (trade.open_date_utc) will remain at the time of the very first order placed. Please make sure to be aware of this - and eventually adjust your logic in other callbacks to account for this, and use the date of the first filled order instead.

    If the cancellation of the original order fails, then the order will not be replaced - though the order will most likely have been canceled on exchange. Having this happen on initial entries will result in the deletion of the order, while on position adjustment orders, it'll result in the trade size remaining as is.

    Regular timeout

    Entry unfilledtimeout mechanism (as well as check_entry_timeout()) takes precedence over this. Entry Orders that are cancelled via the above methods will not have this callback called. Be sure to update timeout values to match your expectations.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def adjust_entry_price(self, trade: Trade, order: Optional[Order], pair: str,\n                           current_time: datetime, proposed_rate: float, current_order_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n        \"\"\"\n        Entry price re-adjustment logic, returning the user desired limit price.\n        This only executes when a order was already placed, still open (unfilled fully or partially)\n        and not timed out on subsequent candles after entry trigger.\n\n        When not implemented by a strategy, returns current_order_rate as default.\n        If current_order_rate is returned then the existing order is maintained.\n        If None is returned then order gets canceled but not replaced by a new one.\n\n        :param pair: Pair that's currently analyzed\n        :param trade: Trade object.\n        :param order: Order object\n        :param current_time: datetime object, containing the current datetime\n        :param proposed_rate: Rate, calculated based on pricing settings in entry_pricing.\n        :param current_order_rate: Rate of the existing order in place.\n        :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.\n        :param side: \"long\" or \"short\" - indicating the direction of the proposed trade\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return float: New entry price value if provided\n\n        \"\"\"\n        # Limit orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair.\n        if (\n            pair == \"BTC/USDT\" \n            and entry_tag == \"long_sma200\" \n            and side == \"long\" \n            and (current_time - timedelta(minutes=10)) > trade.open_date_utc\n        ):\n            # just cancel the order if it has been filled more than half of the amount\n            if order.filled > order.remaining:\n                return None\n            else:\n                dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)\n                current_candle = dataframe.iloc[-1].squeeze()\n                # desired price\n                return current_candle[\"sma_200\"]\n        # default: maintain existing order\n        return current_order_rate\n
    "},{"location":"strategy-callbacks/#leverage-callback","title":"Leverage Callback","text":"

    When trading in markets that allow leverage, this method must return the desired Leverage (Defaults to 1 -> No leverage).

    Assuming a capital of 500USDT, a trade with leverage=3 would result in a position with 500 x 3 = 1500 USDT.

    Values that are above max_leverage will be adjusted to max_leverage. For markets / exchanges that don't support leverage, this method is ignored.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def leverage(self, pair: str, current_time: datetime, current_rate: float,\n                 proposed_leverage: float, max_leverage: float, entry_tag: Optional[str], side: str,\n                 **kwargs) -> float:\n        \"\"\"\n        Customize leverage for each new trade. This method is only called in futures mode.\n\n        :param pair: Pair that's currently analyzed\n        :param current_time: datetime object, containing the current datetime\n        :param current_rate: Rate, calculated based on pricing settings in exit_pricing.\n        :param proposed_leverage: A leverage proposed by the bot.\n        :param max_leverage: Max leverage allowed on this pair\n        :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.\n        :param side: \"long\" or \"short\" - indicating the direction of the proposed trade\n        :return: A leverage amount, which is between 1.0 and max_leverage.\n        \"\"\"\n        return 1.0\n

    All profit calculations include leverage. Stoploss / ROI also include leverage in their calculation. Defining a stoploss of 10% at 10x leverage would trigger the stoploss with a 1% move to the downside.

    "},{"location":"strategy-callbacks/#order-filled-callback","title":"Order filled Callback","text":"

    The order_filled() callback may be used to perform specific actions based on the current trade state after an order is filled. It will be called independent of the order type (entry, exit, stoploss or position adjustment).

    Assuming that your strategy needs to store the high value of the candle at trade entry, this is possible with this callback as the following example show.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def order_filled(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None:\n        \"\"\"\n        Called right after an order fills. \n        Will be called for all order types (entry, exit, stoploss, position adjustment).\n        :param pair: Pair for trade\n        :param trade: trade object.\n        :param order: Order object.\n        :param current_time: datetime object, containing the current datetime\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        \"\"\"\n        # Obtain pair dataframe (just to show how to access it)\n        dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n\n        if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side):\n            trade.set_custom_data(key=\"entry_candle_high\", value=last_candle[\"high\"])\n\n        return None\n
    "},{"location":"strategy-customization/","title":"Strategy Customization","text":"

    This page explains how to customize your strategies, add new indicators and set up trading rules.

    Please familiarize yourself with Freqtrade basics first, which provides overall info on how the bot operates.

    "},{"location":"strategy-customization/#develop-your-own-strategy","title":"Develop your own strategy","text":"

    The bot includes a default strategy file. Also, several other strategies are available in the strategy repository.

    You will however most likely have your own idea for a strategy. This document intends to help you convert your strategy idea into your own strategy.

    To get started, use freqtrade new-strategy --strategy AwesomeStrategy (you can obviously use your own naming for your strategy). This will create a new strategy file from a template, which will be located under user_data/strategies/AwesomeStrategy.py.

    Note

    This is just a template file, which will most likely not be profitable out of the box.

    Different template levels

    freqtrade new-strategy has an additional parameter, --template, which controls the amount of pre-build information you get in the created strategy. Use --template minimal to get an empty strategy without any indicator examples, or --template advanced to get a template with most callbacks defined.

    "},{"location":"strategy-customization/#anatomy-of-a-strategy","title":"Anatomy of a strategy","text":"

    A strategy file contains all the information needed to build a good strategy:

    • Indicators
    • Entry strategy rules
    • Exit strategy rules
    • Minimal ROI recommended
    • Stoploss strongly recommended

    The bot also include a sample strategy called SampleStrategy you can update: user_data/strategies/sample_strategy.py. You can test it with the parameter: --strategy SampleStrategy

    Additionally, there is an attribute called INTERFACE_VERSION, which defines the version of the strategy interface the bot should use. The current version is 3 - which is also the default when it's not set explicitly in the strategy.

    Future versions will require this to be set.

    freqtrade trade --strategy AwesomeStrategy\n

    For the following section we will use the user_data/strategies/sample_strategy.py file as reference.

    Strategies and Backtesting

    To avoid problems and unexpected differences between Backtesting and dry/live modes, please be aware that during backtesting the full time range is passed to the populate_*() methods at once. It is therefore best to use vectorized operations (across the whole dataframe, not loops) and avoid index referencing (df.iloc[-1]), but instead use df.shift() to get to the previous candle.

    Warning: Using future data

    Since backtesting passes the full time range to the populate_*() methods, the strategy author needs to take care to avoid having the strategy utilize data from the future. Some common patterns for this are listed in the Common Mistakes section of this document.

    "},{"location":"strategy-customization/#dataframe","title":"Dataframe","text":"

    Freqtrade uses pandas to store/provide the candlestick (OHLCV) data. Pandas is a great library developed for processing large amounts of data.

    Each row in a dataframe corresponds to one candle on a chart, with the latest candle always being the last in the dataframe (sorted by date).

    > dataframe.head()\n                       date      open      high       low     close     volume\n0 2021-11-09 23:25:00+00:00  67279.67  67321.84  67255.01  67300.97   44.62253\n1 2021-11-09 23:30:00+00:00  67300.97  67301.34  67183.03  67187.01   61.38076\n2 2021-11-09 23:35:00+00:00  67187.02  67187.02  67031.93  67123.81  113.42728\n3 2021-11-09 23:40:00+00:00  67123.80  67222.40  67080.33  67160.48   78.96008\n4 2021-11-09 23:45:00+00:00  67160.48  67160.48  66901.26  66943.37  111.39292\n

    Pandas provides fast ways to calculate metrics. To benefit from this speed, it's advised to not use loops, but use vectorized methods instead.

    Vectorized operations perform calculations across the whole range of data and are therefore, compared to looping through each row, a lot faster when calculating indicators.

    As a dataframe is a table, simple python comparisons like the following will not work

        if dataframe['rsi'] > 30:\n        dataframe['enter_long'] = 1\n

    The above section will fail with The truth value of a Series is ambiguous. [...].

    This must instead be written in a pandas-compatible way, so the operation is performed across the whole dataframe.

        dataframe.loc[\n        (dataframe['rsi'] > 30)\n    , 'enter_long'] = 1\n

    With this section, you have a new column in your dataframe, which has 1 assigned whenever RSI is above 30.

    "},{"location":"strategy-customization/#customize-indicators","title":"Customize Indicators","text":"

    Buy and sell signals need indicators. You can add more indicators by extending the list contained in the method populate_indicators() from your strategy file.

    You should only add the indicators used in either populate_entry_trend(), populate_exit_trend(), or to populate another indicator, otherwise performance may suffer.

    It's important to always return the dataframe without removing/modifying the columns \"open\", \"high\", \"low\", \"close\", \"volume\", otherwise these fields would contain something unexpected.

    Sample:

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    \"\"\"\n    Adds several different TA indicators to the given DataFrame\n\n    Performance Note: For the best performance be frugal on the number of indicators\n    you are using. Let uncomment only the indicator you are using in your strategies\n    or your hyperopt configuration, otherwise you will waste your memory and CPU usage.\n    :param dataframe: Dataframe with data from the exchange\n    :param metadata: Additional information, like the currently traded pair\n    :return: a Dataframe with all mandatory indicators for the strategies\n    \"\"\"\n    dataframe['sar'] = ta.SAR(dataframe)\n    dataframe['adx'] = ta.ADX(dataframe)\n    stoch = ta.STOCHF(dataframe)\n    dataframe['fastd'] = stoch['fastd']\n    dataframe['fastk'] = stoch['fastk']\n    dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband']\n    dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)\n    dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)\n    dataframe['mfi'] = ta.MFI(dataframe)\n    dataframe['rsi'] = ta.RSI(dataframe)\n    dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)\n    dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)\n    dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)\n    dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)\n    dataframe['ao'] = awesome_oscillator(dataframe)\n    macd = ta.MACD(dataframe)\n    dataframe['macd'] = macd['macd']\n    dataframe['macdsignal'] = macd['macdsignal']\n    dataframe['macdhist'] = macd['macdhist']\n    hilbert = ta.HT_SINE(dataframe)\n    dataframe['htsine'] = hilbert['sine']\n    dataframe['htleadsine'] = hilbert['leadsine']\n    dataframe['plus_dm'] = ta.PLUS_DM(dataframe)\n    dataframe['plus_di'] = ta.PLUS_DI(dataframe)\n    dataframe['minus_dm'] = ta.MINUS_DM(dataframe)\n    dataframe['minus_di'] = ta.MINUS_DI(dataframe)\n    return dataframe\n

    Want more indicator examples?

    Look into the user_data/strategies/sample_strategy.py. Then uncomment indicators you need.

    "},{"location":"strategy-customization/#indicator-libraries","title":"Indicator libraries","text":"

    Out of the box, freqtrade installs the following technical libraries:

    • ta-lib
    • pandas-ta
    • technical

    Additional technical libraries can be installed as necessary, or custom indicators may be written / invented by the strategy author.

    "},{"location":"strategy-customization/#strategy-startup-period","title":"Strategy startup period","text":"

    Most indicators have an instable startup period, in which they are either not available (NaN), or the calculation is incorrect. This can lead to inconsistencies, since Freqtrade does not know how long this instable period should be. To account for this, the strategy can be assigned the startup_candle_count attribute. This should be set to the maximum number of candles that the strategy requires to calculate stable indicators. In the case where a user includes higher timeframes with informative pairs, the startup_candle_count does not necessarily change. The value is the maximum period (in candles) that any of the informatives timeframes need to compute stable indicators.

    You can use recursive-analysis to check and find the correct startup_candle_count to be used.

    In this example strategy, this should be set to 400 (startup_candle_count = 400), since the minimum needed history for ema100 calculation to make sure the value is correct is 400 candles.

        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)\n

    By letting the bot know how much history is needed, backtest trades can start at the specified timerange during backtesting and hyperopt.

    Using x calls to get OHLCV

    If you receive a warning like WARNING - Using 3 calls to get OHLCV. This can result in slower operations for the bot. Please check if you really need 1500 candles for your strategy - you should consider if you really need this much historic data for your signals. Having this will cause Freqtrade to make multiple calls for the same pair, which will obviously be slower than one network request. As a consequence, Freqtrade will take longer to refresh candles - and should therefore be avoided if possible. This is capped to 5 total calls to avoid overloading the exchange, or make freqtrade too slow.

    Warning

    startup_candle_count should be below ohlcv_candle_limit * 5 (which is 500 * 5 for most exchanges) - since only this amount of candles will be available during Dry-Run/Live Trade operations.

    "},{"location":"strategy-customization/#example","title":"Example","text":"

    Let's try to backtest 1 month (January 2019) of 5m candles using an example strategy with EMA100, as above.

    freqtrade backtesting --timerange 20190101-20190201 --timeframe 5m\n

    Assuming startup_candle_count is set to 400, backtesting knows it needs 400 candles to generate valid buy signals. It will load data from 20190101 - (400 * 5m) - which is ~2018-12-30 11:40:00. If this data is available, indicators will be calculated with this extended timerange. The instable startup period (up to 2019-01-01 00:00:00) will then be removed before starting backtesting.

    Note

    If data for the startup period is not available, then the timerange will be adjusted to account for this startup period - so Backtesting would start at 2019-01-02 09:20:00.

    "},{"location":"strategy-customization/#entry-signal-rules","title":"Entry signal rules","text":"

    Edit the method populate_entry_trend() in your strategy file to update your entry strategy.

    It's important to always return the dataframe without removing/modifying the columns \"open\", \"high\", \"low\", \"close\", \"volume\", otherwise these fields would contain something unexpected.

    This method will also define a new column, \"enter_long\" (\"enter_short\" for shorts), which needs to contain 1 for entries, and 0 for \"no action\". enter_long is a mandatory column that must be set even if the strategy is shorting only.

    Sample from user_data/strategies/sample_strategy.py:

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    \"\"\"\n    Based on TA indicators, populates the buy signal for the given dataframe\n    :param dataframe: DataFrame populated with indicators\n    :param metadata: Additional information, like the currently traded pair\n    :return: DataFrame with buy column\n    \"\"\"\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n
    Enter short trades

    Short-entries can be created by setting enter_short (corresponds to enter_long for long trades). The enter_tag column remains identical. Short-trades need to be supported by your exchange and market configuration! Please make sure to set can_short appropriately on your strategy if you intend to short.

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n\n    dataframe.loc[\n        (\n            (qtpylib.crossed_below(dataframe['rsi'], 70)) &  # Signal: RSI crosses below 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_short', 'enter_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n

    Note

    Buying requires sellers to buy from - therefore volume needs to be > 0 (dataframe['volume'] > 0) to make sure that the bot does not buy/sell in no-activity periods.

    "},{"location":"strategy-customization/#exit-signal-rules","title":"Exit signal rules","text":"

    Edit the method populate_exit_trend() into your strategy file to update your exit strategy. The exit-signal can be suppressed by setting use_exit_signal to false in the configuration or strategy. use_exit_signal will not influence signal collision rules - which will still apply and can prevent entries.

    It's important to always return the dataframe without removing/modifying the columns \"open\", \"high\", \"low\", \"close\", \"volume\", otherwise these fields would contain something unexpected.

    This method will also define a new column, \"exit_long\" (\"exit_short\" for shorts), which needs to contain 1 for exits, and 0 for \"no action\".

    Sample from user_data/strategies/sample_strategy.py:

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    \"\"\"\n    Based on TA indicators, populates the exit signal for the given dataframe\n    :param dataframe: DataFrame populated with indicators\n    :param metadata: Additional information, like the currently traded pair\n    :return: DataFrame with buy column\n    \"\"\"\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'rsi_too_high')\n    return dataframe\n
    Exit short trades

    Short-exits can be created by setting exit_short (corresponds to exit_long). The exit_tag column remains identical. Short-trades need to be supported by your exchange and market configuration!

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'rsi_too_high')\n    dataframe.loc[\n        (\n            (qtpylib.crossed_below(dataframe['rsi'], 30)) &  # Signal: RSI crosses below 30\n            (dataframe['tema'] < dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_short', 'exit_tag']] = (1, 'rsi_too_low')\n    return dataframe\n
    "},{"location":"strategy-customization/#minimal-roi","title":"Minimal ROI","text":"

    This dict defines the minimal Return On Investment (ROI) a trade should reach before exiting, independent from the exit signal.

    It is of the following format, with the dict key (left side of the colon) being the minutes passed since the trade opened, and the value (right side of the colon) being the percentage.

    minimal_roi = {\n    \"40\": 0.0,\n    \"30\": 0.01,\n    \"20\": 0.02,\n    \"0\": 0.04\n}\n

    The above configuration would therefore mean:

    • Exit whenever 4% profit was reached
    • Exit when 2% profit was reached (in effect after 20 minutes)
    • Exit when 1% profit was reached (in effect after 30 minutes)
    • Exit when trade is non-loosing (in effect after 40 minutes)

    The calculation does include fees.

    To disable ROI completely, set it to an empty dictionary:

    minimal_roi = {}\n

    To use times based on candle duration (timeframe), the following snippet can be handy. This will allow you to change the timeframe for the strategy, and ROI times will still be set as candles (e.g. after 3 candles ...)

    from freqtrade.exchange import timeframe_to_minutes\n\nclass AwesomeStrategy(IStrategy):\n\n    timeframe = \"1d\"\n    timeframe_mins = timeframe_to_minutes(timeframe)\n    minimal_roi = {\n        \"0\": 0.05,                      # 5% for the first 3 candles\n        str(timeframe_mins * 3): 0.02,  # 2% after 3 candles\n        str(timeframe_mins * 6): 0.01,  # 1% After 6 candles\n    }\n
    Orders that don't fill immediately

    minimal_roi will take the trade.open_date as reference, which is the time the trade was initialized / the first order for this trade was placed. This will also hold true for limit orders that don't fill immediately (usually in combination with \"off-spot\" prices through custom_entry_price()), as well as for cases where the initial order is replaced through adjust_entry_price(). The time used will still be from the initial trade.open_date (when the initial order was first placed), not from the newly placed order date.

    "},{"location":"strategy-customization/#stoploss","title":"Stoploss","text":"

    Setting a stoploss is highly recommended to protect your capital from strong moves against you.

    Sample of setting a 10% stoploss:

    stoploss = -0.10\n

    For the full documentation on stoploss features, look at the dedicated stoploss page.

    "},{"location":"strategy-customization/#timeframe","title":"Timeframe","text":"

    This is the set of candles the bot should download and use for the analysis. Common values are \"1m\", \"5m\", \"15m\", \"1h\", however all values supported by your exchange should work.

    Please note that the same entry/exit signals may work well with one timeframe, but not with the others.

    This setting is accessible within the strategy methods as the self.timeframe attribute.

    "},{"location":"strategy-customization/#can-short","title":"Can short","text":"

    To use short signals in futures markets, you will have to let us know to do so by setting can_short=True. Strategies which enable this will fail to load on spot markets. Disabling of this will have short signals ignored (also in futures markets).

    "},{"location":"strategy-customization/#metadata-dict","title":"Metadata dict","text":"

    The metadata-dict (available for populate_entry_trend, populate_exit_trend, populate_indicators) contains additional information. Currently this is pair, which can be accessed using metadata['pair'] - and will return a pair in the format XRP/BTC.

    The Metadata-dict should not be modified and does not persist information across multiple calls. Instead, have a look at the Storing information section.

    "},{"location":"strategy-customization/#imports-necessary-for-a-strategy","title":"Imports necessary for a strategy","text":"

    When creating a strategy, you will need to import the necessary modules and classes. The following imports are required for a strategy:

    By default, we recommend the following imports as a base line for your strategy: This will cover all imports necessary for freqtrade functions to work. Obviously you can add more imports as needed for your strategy.

    # flake8: noqa: F401\n# isort: skip_file\n# --- Do not remove these imports ---\nimport numpy as np\nimport pandas as pd\nfrom datetime import datetime, timedelta, timezone\nfrom pandas import DataFrame\nfrom typing import Dict, Optional, Union, Tuple\n\nfrom freqtrade.strategy import (\n    IStrategy,\n    Trade, \n    Order,\n    PairLocks,\n    informative,  # @informative decorator\n    # Hyperopt Parameters\n    BooleanParameter,\n    CategoricalParameter,\n    DecimalParameter,\n    IntParameter,\n    RealParameter,\n    # timeframe helpers\n    timeframe_to_minutes,\n    timeframe_to_next_date,\n    timeframe_to_prev_date,\n    # Strategy helper functions\n    merge_informative_pair,\n    stoploss_from_absolute,\n    stoploss_from_open,\n)\n\n# --------------------------------\n# Add your lib to import here\nimport talib.abstract as ta\nfrom technical import qtpylib\n
    "},{"location":"strategy-customization/#strategy-file-loading","title":"Strategy file loading","text":"

    By default, freqtrade will attempt to load strategies from all .py files within user_data/strategies.

    Assuming your strategy is called AwesomeStrategy, stored in the file user_data/strategies/AwesomeStrategy.py, then you can start freqtrade with freqtrade trade --strategy AwesomeStrategy. Note that we're using the class-name, not the file name.

    You can use freqtrade list-strategies to see a list of all strategies Freqtrade is able to load (all strategies in the correct folder). It will also include a \"status\" field, highlighting potential problems.

    Customize strategy directory

    You can use a different directory by using --strategy-path user_data/otherPath. This parameter is available to all commands that require a strategy.

    "},{"location":"strategy-customization/#informative-pairs","title":"Informative Pairs","text":""},{"location":"strategy-customization/#get-data-for-non-tradeable-pairs","title":"Get data for non-tradeable pairs","text":"

    Data for additional, informative pairs (reference pairs) can be beneficial for some strategies. OHLCV data for these pairs will be downloaded as part of the regular whitelist refresh process and is available via DataProvider just as other pairs (see below). These parts will not be traded unless they are also specified in the pair whitelist, or have been selected by Dynamic Whitelisting.

    The pairs need to be specified as tuples in the format (\"pair\", \"timeframe\"), with pair as the first and timeframe as the second argument.

    Sample:

    def informative_pairs(self):\n    return [(\"ETH/USDT\", \"5m\"),\n            (\"BTC/TUSD\", \"15m\"),\n            ]\n

    A full sample can be found in the DataProvider section.

    Warning

    As these pairs will be refreshed as part of the regular whitelist refresh, it's best to keep this list short. All timeframes and all pairs can be specified as long as they are available (and active) on the used exchange. It is however better to use resampling to longer timeframes whenever possible to avoid hammering the exchange with too many requests and risk being blocked.

    Alternative candle types

    Informative_pairs can also provide a 3rd tuple element defining the candle type explicitly. Availability of alternative candle-types will depend on the trading-mode and the exchange. In general, spot pairs cannot be used in futures markets, and futures candles can't be used as informative pairs for spot bots. Details about this may vary, if they do, this can be found in the exchange documentation.

    def informative_pairs(self):\n    return [\n        (\"ETH/USDT\", \"5m\", \"\"),   # Uses default candletype, depends on trading_mode (recommended)\n        (\"ETH/USDT\", \"5m\", \"spot\"),   # Forces usage of spot candles (only valid for bots running on spot markets).\n        (\"BTC/TUSD\", \"15m\", \"futures\"),  # Uses futures candles (only bots with `trading_mode=futures`)\n        (\"BTC/TUSD\", \"15m\", \"mark\"),  # Uses mark candles (only bots with `trading_mode=futures`)\n    ]\n
    "},{"location":"strategy-customization/#informative-pairs-decorator-informative","title":"Informative pairs decorator (@informative())","text":"

    In most common case it is possible to easily define informative pairs by using a decorator. All decorated populate_indicators_* methods run in isolation, not having access to data from other informative pairs, in the end all informative dataframes are merged and passed to main populate_indicators() method. When hyperopting, use of hyperoptable parameter .value attribute is not supported. Please use .range attribute. See optimizing an indicator parameter for more information.

    Full documentation
    def informative(timeframe: str, asset: str = '',\n                fmt: Optional[Union[str, Callable[[KwArg(str)], str]]] = None,\n                *,\n                candle_type: Optional[CandleType] = None,\n                ffill: bool = True) -> Callable[[PopulateIndicators], PopulateIndicators]:\n    \"\"\"\n    A decorator for populate_indicators_Nn(self, dataframe, metadata), allowing these functions to\n    define informative indicators.\n\n    Example usage:\n\n        @informative('1h')\n        def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n            dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n            return dataframe\n\n    :param timeframe: Informative timeframe. Must always be equal or higher than strategy timeframe.\n    :param asset: Informative asset, for example BTC, BTC/USDT, ETH/BTC. Do not specify to use\n                current pair. Also supports limited pair format strings (see below)\n    :param fmt: Column format (str) or column formatter (callable(name, asset, timeframe)). When not\n    specified, defaults to:\n    * {base}_{quote}_{column}_{timeframe} if asset is specified.\n    * {column}_{timeframe} if asset is not specified.\n    Pair format supports these format variables:\n    * {base} - base currency in lower case, for example 'eth'.\n    * {BASE} - same as {base}, except in upper case.\n    * {quote} - quote currency in lower case, for example 'usdt'.\n    * {QUOTE} - same as {quote}, except in upper case.\n    Format string additionally supports this variables.\n    * {asset} - full name of the asset, for example 'BTC/USDT'.\n    * {column} - name of dataframe column.\n    * {timeframe} - timeframe of informative dataframe.\n    :param ffill: ffill dataframe after merging informative pair.\n    :param candle_type: '', mark, index, premiumIndex, or funding_rate\n    \"\"\"\n
    Fast and easy way to define informative pairs

    Most of the time we do not need power and flexibility offered by merge_informative_pair(), therefore we can use a decorator to quickly define informative pairs.

    from datetime import datetime\nfrom freqtrade.persistence import Trade\nfrom freqtrade.strategy import IStrategy, informative\n\nclass AwesomeStrategy(IStrategy):\n\n    # This method is not required. \n    # def informative_pairs(self): ...\n\n    # Define informative upper timeframe for each pair. Decorators can be stacked on same \n    # method. Available in populate_indicators as 'rsi_30m' and 'rsi_1h'.\n    @informative('30m')\n    @informative('1h')\n    def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    # Define BTC/STAKE informative pair. Available in populate_indicators and other methods as\n    # 'btc_rsi_1h'. Current stake currency should be specified as {stake} format variable \n    # instead of hard-coding actual stake currency. Available in populate_indicators and other \n    # methods as 'btc_usdt_rsi_1h' (when stake currency is USDT).\n    @informative('1h', 'BTC/{stake}')\n    def populate_indicators_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    # Define BTC/ETH informative pair. You must specify quote currency if it is different from\n    # stake currency. Available in populate_indicators and other methods as 'eth_btc_rsi_1h'.\n    @informative('1h', 'ETH/BTC')\n    def populate_indicators_eth_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    # Define BTC/STAKE informative pair. A custom formatter may be specified for formatting\n    # column names. A callable `fmt(**kwargs) -> str` may be specified, to implement custom\n    # formatting. Available in populate_indicators and other methods as 'rsi_upper_1h'.\n    @informative('1h', 'BTC/{stake}', '{column}_{timeframe}')\n    def populate_indicators_btc_1h_2(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi_upper'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # Strategy timeframe indicators for current pair.\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        # Informative pairs are available in this method.\n        dataframe['rsi_less'] = dataframe['rsi'] < dataframe['rsi_1h']\n        return dataframe\n

    Note

    Do not use @informative decorator if you need to use data of one informative pair when generating another informative pair. Instead, define informative pairs manually as described in the DataProvider section.

    Note

    Use string formatting when accessing informative dataframes of other pairs. This will allow easily changing stake currency in config without having to adjust strategy code.

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    stake = self.config['stake_currency']\n    dataframe.loc[\n        (\n            (dataframe[f'btc_{stake}_rsi_1h'] < 35)\n            &\n            (dataframe['volume'] > 0)\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'buy_signal_rsi')\n\n    return dataframe\n

    Alternatively column renaming may be used to remove stake currency from column names: @informative('1h', 'BTC/{stake}', fmt='{base}_{column}_{timeframe}').

    Duplicate method names

    Methods tagged with @informative() decorator must always have unique names! Re-using same name (for example when copy-pasting already defined informative method) will overwrite previously defined method and not produce any errors due to limitations of Python programming language. In such cases you will find that indicators created in earlier-defined methods are not available in the dataframe. Carefully review method names and make sure they are unique!

    "},{"location":"strategy-customization/#merge_informative_pair","title":"merge_informative_pair()","text":"

    This method helps you merge an informative pair to a regular dataframe without lookahead bias. It's there to help you merge the dataframe in a safe and consistent way.

    Options:

    • Rename the columns for you to create unique columns
    • Merge the dataframe without lookahead bias
    • Forward-fill (optional)

    For a full sample, please refer to the complete data provider example below.

    All columns of the informative dataframe will be available on the returning dataframe in a renamed fashion:

    Column renaming

    Assuming inf_tf = '1d' the resulting columns will be:

    'date', 'open', 'high', 'low', 'close', 'rsi'                     # from the original dataframe\n'date_1d', 'open_1d', 'high_1d', 'low_1d', 'close_1d', 'rsi_1d'   # from the informative dataframe\n
    Column renaming - 1h

    Assuming inf_tf = '1h' the resulting columns will be:

    'date', 'open', 'high', 'low', 'close', 'rsi'                     # from the original dataframe\n'date_1h', 'open_1h', 'high_1h', 'low_1h', 'close_1h', 'rsi_1h'   # from the informative dataframe\n
    Custom implementation

    A custom implementation for this is possible, and can be done as follows:

    # Shift date by 1 candle\n# This is necessary since the data is always the \"open date\"\n# and a 15m candle starting at 12:15 should not know the close of the 1h candle from 12:00 to 13:00\nminutes = timeframe_to_minutes(inf_tf)\n# Only do this if the timeframes are different:\ninformative['date_merge'] = informative[\"date\"] + pd.to_timedelta(minutes, 'm')\n\n# Rename columns to be unique\ninformative.columns = [f\"{col}_{inf_tf}\" for col in informative.columns]\n# Assuming inf_tf = '1d' - then the columns will now be:\n# date_1d, open_1d, high_1d, low_1d, close_1d, rsi_1d\n\n# Combine the 2 dataframes\n# all indicators on the informative sample MUST be calculated before this point\ndataframe = pd.merge(dataframe, informative, left_on='date', right_on=f'date_merge_{inf_tf}', how='left')\n# FFill to have the 1d value available in every row throughout the day.\n# Without this, comparisons would only work once per day.\ndataframe = dataframe.ffill()\n

    Informative timeframe < timeframe

    Using informative timeframes smaller than the dataframe timeframe is not recommended with this method, as it will not use any of the additional information this would provide. To use the more detailed information properly, more advanced methods should be applied (which are out of scope for freqtrade documentation, as it'll depend on the respective need).

    "},{"location":"strategy-customization/#additional-data-dataprovider","title":"Additional data (DataProvider)","text":"

    The strategy provides access to the DataProvider. This allows you to get additional data to use in your strategy.

    All methods return None in case of failure (do not raise an exception).

    Please always check the mode of operation to select the correct method to get data (samples see below).

    Hyperopt

    Dataprovider is available during hyperopt, however it can only be used in populate_indicators() within a strategy. It is not available in populate_buy() and populate_sell() methods, nor in populate_indicators(), if this method located in the hyperopt file.

    "},{"location":"strategy-customization/#possible-options-for-dataprovider","title":"Possible options for DataProvider","text":"
    • available_pairs - Property with tuples listing cached pairs with their timeframe (pair, timeframe).
    • current_whitelist() - Returns a current list of whitelisted pairs. Useful for accessing dynamic whitelists (i.e. VolumePairlist)
    • get_pair_dataframe(pair, timeframe) - This is a universal method, which returns either historical data (for backtesting) or cached live data (for the Dry-Run and Live-Run modes).
    • get_analyzed_dataframe(pair, timeframe) - Returns the analyzed dataframe (after calling populate_indicators(), populate_buy(), populate_sell()) and the time of the latest analysis.
    • historic_ohlcv(pair, timeframe) - Returns historical data stored on disk.
    • market(pair) - Returns market data for the pair: fees, limits, precisions, activity flag, etc. See ccxt documentation for more details on the Market data structure.
    • ohlcv(pair, timeframe) - Currently cached candle (OHLCV) data for the pair, returns DataFrame or empty DataFrame.
    • orderbook(pair, maximum) - Returns latest orderbook data for the pair, a dict with bids/asks with a total of maximum entries.
    • ticker(pair) - Returns current ticker data for the pair. See ccxt documentation for more details on the Ticker data structure.
    • runmode - Property containing the current runmode.
    "},{"location":"strategy-customization/#example-usages","title":"Example Usages","text":""},{"location":"strategy-customization/#available_pairs","title":"available_pairs","text":"
    for pair, timeframe in self.dp.available_pairs:\n    print(f\"available {pair}, {timeframe}\")\n
    "},{"location":"strategy-customization/#current_whitelist","title":"current_whitelist()","text":"

    Imagine you've developed a strategy that trades the 5m timeframe using signals generated from a 1d timeframe on the top 10 volume pairs by volume.

    The strategy might look something like this:

    Scan through the top 10 pairs by volume using the VolumePairList every 5 minutes and use a 14 day RSI to buy and sell.

    Due to the limited available data, it's very difficult to resample 5m candles into daily candles for use in a 14 day RSI. Most exchanges limit us to just 500-1000 candles which effectively gives us around 1.74 daily candles. We need 14 days at least!

    Since we can't resample the data we will have to use an informative pair; and since the whitelist will be dynamic we don't know which pair(s) to use.

    This is where calling self.dp.current_whitelist() comes in handy.

        def informative_pairs(self):\n\n        # get access to all pairs available in whitelist.\n        pairs = self.dp.current_whitelist()\n        # Assign tf to each pair so they can be downloaded and cached for strategy.\n        informative_pairs = [(pair, '1d') for pair in pairs]\n        return informative_pairs\n
    Plotting with current_whitelist

    Current whitelist is not supported for plot-dataframe, as this command is usually used by providing an explicit pairlist - and would therefore make the return values of this method misleading. It's also not supported for freqUI visualization in webserver mode - as the configuration for webserver mode doesn't require a pairlist to be set.

    "},{"location":"strategy-customization/#get_pair_dataframepair-timeframe","title":"get_pair_dataframe(pair, timeframe)","text":"
    # fetch live / historical candle (OHLCV) data for the first informative pair\ninf_pair, inf_timeframe = self.informative_pairs()[0]\ninformative = self.dp.get_pair_dataframe(pair=inf_pair,\n                                         timeframe=inf_timeframe)\n

    Warning about backtesting

    In backtesting, dp.get_pair_dataframe() behavior differs depending on where it's called. Within populate_*() methods, dp.get_pair_dataframe() returns the full timerange. Please make sure to not \"look into the future\" to avoid surprises when running in dry/live mode. Within callbacks, you'll get the full timerange up to the current (simulated) candle.

    "},{"location":"strategy-customization/#get_analyzed_dataframepair-timeframe","title":"get_analyzed_dataframe(pair, timeframe)","text":"

    This method is used by freqtrade internally to determine the last signal. It can also be used in specific callbacks to get the signal that caused the action (see Advanced Strategy Documentation for more details on available callbacks).

    # fetch current dataframe\ndataframe, last_updated = self.dp.get_analyzed_dataframe(pair=metadata['pair'],\n                                                         timeframe=self.timeframe)\n

    No data available

    Returns an empty dataframe if the requested pair was not cached. You can check for this with if dataframe.empty: and handle this case accordingly. This should not happen when using whitelisted pairs.

    "},{"location":"strategy-customization/#orderbookpair-maximum","title":"orderbook(pair, maximum)","text":"
    if self.dp.runmode.value in ('live', 'dry_run'):\n    ob = self.dp.orderbook(metadata['pair'], 1)\n    dataframe['best_bid'] = ob['bids'][0][0]\n    dataframe['best_ask'] = ob['asks'][0][0]\n

    The orderbook structure is aligned with the order structure from ccxt, so the result will look as follows:

    {\n    'bids': [\n        [ price, amount ], // [ float, float ]\n        [ price, amount ],\n        ...\n    ],\n    'asks': [\n        [ price, amount ],\n        [ price, amount ],\n        //...\n    ],\n    //...\n}\n

    Therefore, using ob['bids'][0][0] as demonstrated above will result in using the best bid price. ob['bids'][0][1] would look at the amount at this orderbook position.

    Warning about backtesting

    The order book is not part of the historic data which means backtesting and hyperopt will not work correctly if this method is used, as the method will return up-to-date values.

    "},{"location":"strategy-customization/#tickerpair","title":"ticker(pair)","text":"
    if self.dp.runmode.value in ('live', 'dry_run'):\n    ticker = self.dp.ticker(metadata['pair'])\n    dataframe['last_price'] = ticker['last']\n    dataframe['volume24h'] = ticker['quoteVolume']\n    dataframe['vwap'] = ticker['vwap']\n

    Warning

    Although the ticker data structure is a part of the ccxt Unified Interface, the values returned by this method can vary for different exchanges. For instance, many exchanges do not return vwap values, some exchanges does not always fills in the last field (so it can be None), etc. So you need to carefully verify the ticker data returned from the exchange and add appropriate error handling / defaults.

    Warning about backtesting

    This method will always return up-to-date values - so usage during backtesting / hyperopt without runmode checks will lead to wrong results.

    "},{"location":"strategy-customization/#send-notification","title":"Send Notification","text":"

    The dataprovider .send_msg() function allows you to send custom notifications from your strategy. Identical notifications will only be sent once per candle, unless the 2nd argument (always_send) is set to True.

        self.dp.send_msg(f\"{metadata['pair']} just got hot!\")\n\n    # Force send this notification, avoid caching (Please read warning below!)\n    self.dp.send_msg(f\"{metadata['pair']} just got hot!\", always_send=True)\n

    Notifications will only be sent in trading modes (Live/Dry-run) - so this method can be called without conditions for backtesting.

    Spamming

    You can spam yourself pretty good by setting always_send=True in this method. Use this with great care and only in conditions you know will not happen throughout a candle to avoid a message every 5 seconds.

    "},{"location":"strategy-customization/#complete-data-provider-sample","title":"Complete Data-provider sample","text":"
    from freqtrade.strategy import IStrategy, merge_informative_pair\nfrom pandas import DataFrame\n\nclass SampleStrategy(IStrategy):\n    # strategy init stuff...\n\n    timeframe = '5m'\n\n    # more strategy init stuff..\n\n    def informative_pairs(self):\n\n        # get access to all pairs available in whitelist.\n        pairs = self.dp.current_whitelist()\n        # Assign tf to each pair so they can be downloaded and cached for strategy.\n        informative_pairs = [(pair, '1d') for pair in pairs]\n        # Optionally Add additional \"static\" pairs\n        informative_pairs += [(\"ETH/USDT\", \"5m\"),\n                              (\"BTC/TUSD\", \"15m\"),\n                            ]\n        return informative_pairs\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        if not self.dp:\n            # Don't do anything if DataProvider is not available.\n            return dataframe\n\n        inf_tf = '1d'\n        # Get the informative pair\n        informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=inf_tf)\n        # Get the 14 day rsi\n        informative['rsi'] = ta.RSI(informative, timeperiod=14)\n\n        # Use the helper function merge_informative_pair to safely merge the pair\n        # Automatically renames the columns and merges a shorter timeframe dataframe and a longer timeframe informative pair\n        # use ffill to have the 1d value available in every row throughout the day.\n        # Without this, comparisons between columns of the original and the informative pair would only work once per day.\n        # Full documentation of this method, see below\n        dataframe = merge_informative_pair(dataframe, informative, self.timeframe, inf_tf, ffill=True)\n\n        # Calculate rsi of the original dataframe (5m timeframe)\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n\n        # Do other stuff\n        # ...\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n\n        dataframe.loc[\n            (\n                (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n                (dataframe['rsi_1d'] < 30) &                     # Ensure daily RSI is < 30\n                (dataframe['volume'] > 0)                        # Ensure this candle had volume (important for backtesting)\n            ),\n            ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n
    "},{"location":"strategy-customization/#additional-data-wallets","title":"Additional data (Wallets)","text":"

    The strategy provides access to the wallets object. This contains the current balances on the exchange.

    Backtesting / Hyperopt

    Wallets behaves differently depending on the function it's called. Within populate_*() methods, it'll return the full wallet as configured. Within callbacks, you'll get the wallet state corresponding to the actual simulated wallet at that point in the simulation process.

    Please always check if wallets is available to avoid failures during backtesting.

    if self.wallets:\n    free_eth = self.wallets.get_free('ETH')\n    used_eth = self.wallets.get_used('ETH')\n    total_eth = self.wallets.get_total('ETH')\n
    "},{"location":"strategy-customization/#possible-options-for-wallets","title":"Possible options for Wallets","text":"
    • get_free(asset) - currently available balance to trade
    • get_used(asset) - currently tied up balance (open orders)
    • get_total(asset) - total available balance - sum of the 2 above
    "},{"location":"strategy-customization/#additional-data-trades","title":"Additional data (Trades)","text":"

    A history of Trades can be retrieved in the strategy by querying the database.

    At the top of the file, import Trade.

    from freqtrade.persistence import Trade\n

    The following example queries for the current pair and trades from today, however other filters can easily be added.

    trades = Trade.get_trades_proxy(pair=metadata['pair'],\n                                open_date=datetime.now(timezone.utc) - timedelta(days=1),\n                                is_open=False,\n            ]).order_by(Trade.close_date).all()\n# Summarize profit for this pair.\ncurdayprofit = sum(trade.close_profit for trade in trades)\n

    For a full list of available methods, please consult the Trade object documentation.

    Warning

    Trade history is not available in populate_* methods during backtesting or hyperopt, and will result in empty results.

    "},{"location":"strategy-customization/#prevent-trades-from-happening-for-a-specific-pair","title":"Prevent trades from happening for a specific pair","text":"

    Freqtrade locks pairs automatically for the current candle (until that candle is over) when a pair is sold, preventing an immediate re-buy of that pair.

    Locked pairs will show the message Pair <pair> is currently locked..

    "},{"location":"strategy-customization/#locking-pairs-from-within-the-strategy","title":"Locking pairs from within the strategy","text":"

    Sometimes it may be desired to lock a pair after certain events happen (e.g. multiple losing trades in a row).

    Freqtrade has an easy method to do this from within the strategy, by calling self.lock_pair(pair, until, [reason]). until must be a datetime object in the future, after which trading will be re-enabled for that pair, while reason is an optional string detailing why the pair was locked.

    Locks can also be lifted manually, by calling self.unlock_pair(pair) or self.unlock_reason(<reason>) - providing reason the pair was locked with. self.unlock_reason(<reason>) will unlock all pairs currently locked with the provided reason.

    To verify if a pair is currently locked, use self.is_pair_locked(pair).

    Note

    Locked pairs will always be rounded up to the next candle. So assuming a 5m timeframe, a lock with until set to 10:18 will lock the pair until the candle from 10:15-10:20 will be finished.

    Warning

    Manually locking pairs is not available during backtesting, only locks via Protections are allowed.

    "},{"location":"strategy-customization/#pair-locking-example","title":"Pair locking example","text":"
    from freqtrade.persistence import Trade\nfrom datetime import timedelta, datetime, timezone\n# Put the above lines a the top of the strategy file, next to all the other imports\n# --------\n\n# Within populate indicators (or populate_buy):\nif self.config['runmode'].value in ('live', 'dry_run'):\n    # fetch closed trades for the last 2 days\n    trades = Trade.get_trades_proxy(\n        pair=metadata['pair'], is_open=False, \n        open_date=datetime.now(timezone.utc) - timedelta(days=2))\n    # Analyze the conditions you'd like to lock the pair .... will probably be different for every strategy\n    sumprofit = sum(trade.close_profit for trade in trades)\n    if sumprofit < 0:\n        # Lock pair for 12 hours\n        self.lock_pair(metadata['pair'], until=datetime.now(timezone.utc) + timedelta(hours=12))\n
    "},{"location":"strategy-customization/#print-created-dataframe","title":"Print created dataframe","text":"

    To inspect the created dataframe, you can issue a print-statement in either populate_entry_trend() or populate_exit_trend(). You may also want to print the pair so it's clear what data is currently shown.

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            #>> whatever condition<<<\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'somestring')\n\n    # Print the Analyzed pair\n    print(f\"result for {metadata['pair']}\")\n\n    # Inspect the last 5 rows\n    print(dataframe.tail())\n\n    return dataframe\n

    Printing more than a few rows is also possible (simply use print(dataframe) instead of print(dataframe.tail())), however not recommended, as that will be very verbose (~500 lines per pair every 5 seconds).

    "},{"location":"strategy-customization/#common-mistakes-when-developing-strategies","title":"Common mistakes when developing strategies","text":""},{"location":"strategy-customization/#peeking-into-the-future-while-backtesting","title":"Peeking into the future while backtesting","text":"

    Backtesting analyzes the whole time-range at once for performance reasons. Because of this, strategy authors need to make sure that strategies do not look-ahead into the future. This is a common pain-point, which can cause huge differences between backtesting and dry/live run methods, since they all use data which is not available during dry/live runs, so these strategies will perform well during backtesting, but will fail / perform badly in real conditions.

    The following lists some common patterns which should be avoided to prevent frustration:

    • don't use shift(-1) or other negative values. This uses data from the future in backtesting, which is not available in dry or live modes.
    • don't use .iloc[-1] or any other absolute position in the dataframe within populate_ functions, as this will be different between dry-run and backtesting. Absolute iloc indexing is safe to use in callbacks however - see Strategy Callbacks.
    • don't use dataframe['volume'].mean(). This uses the full DataFrame for backtesting, including data from the future. Use dataframe['volume'].rolling(<window>).mean() instead
    • don't use .resample('1h'). This uses the left border of the interval, so moves data from an hour to the start of the hour. Use .resample('1h', label='right') instead.

    Identifying problems

    You may also want to check the 2 helper commands lookahead-analysis and recursive-analysis, which can each help you figure out problems with your strategy in different ways. Please treat them as what they are - helpers to identify most common problems. A negative result of each does not guarantee that there's none of the above errors included.

    "},{"location":"strategy-customization/#colliding-signals","title":"Colliding signals","text":"

    When conflicting signals collide (e.g. both 'enter_long' and 'exit_long' are 1), freqtrade will do nothing and ignore the entry signal. This will avoid trades that enter, and exit immediately. Obviously, this can potentially lead to missed entries.

    The following rules apply, and entry signals will be ignored if more than one of the 3 signals is set:

    • enter_long -> exit_long, enter_short
    • enter_short -> exit_short, enter_long
    "},{"location":"strategy-customization/#further-strategy-ideas","title":"Further strategy ideas","text":"

    To get additional Ideas for strategies, head over to the strategy repository. Feel free to use them as they are - but results will depend on the current market situation, pairs used etc. - therefore please backtest the strategy for your exchange/desired pairs first, evaluate carefully, use at your own risk. Feel free to use any of them as inspiration for your own strategies. We're happy to accept Pull Requests containing new Strategies to that repo.

    "},{"location":"strategy-customization/#next-step","title":"Next step","text":"

    Now you have a perfect strategy you probably want to backtest it. Your next step is to learn How to use the Backtesting.

    "},{"location":"strategy_analysis_example/","title":"Strategy analysis example","text":"

    Debugging a strategy can be time-consuming. Freqtrade offers helper functions to visualize raw data. The following assumes you work with SampleStrategy, data for 5m timeframe from Binance and have downloaded them into the data directory in the default location. Please follow the documentation for more details.

    "},{"location":"strategy_analysis_example/#setup","title":"Setup","text":""},{"location":"strategy_analysis_example/#change-working-directory-to-repository-root","title":"Change Working directory to repository root","text":"
    import os\nfrom pathlib import Path\n\n\n# Change directory\n# Modify this cell to insure that the output shows the correct path.\n# Define all paths relative to the project root shown in the cell output\nproject_root = \"somedir/freqtrade\"\ni = 0\ntry:\n    os.chdir(project_root)\n    if not Path(\"LICENSE\").is_file():\n        i = 0\n        while i < 4 and (not Path(\"LICENSE\").is_file()):\n            os.chdir(Path(Path.cwd(), \"../\"))\n            i += 1\n        project_root = Path.cwd()\nexcept FileNotFoundError:\n    print(\"Please define the project root relative to the current directory\")\nprint(Path.cwd())\n
    "},{"location":"strategy_analysis_example/#configure-freqtrade-environment","title":"Configure Freqtrade environment","text":"
    from freqtrade.configuration import Configuration\n\n\n# Customize these according to your needs.\n\n# Initialize empty configuration object\nconfig = Configuration.from_files([])\n# Optionally (recommended), use existing configuration file\n# config = Configuration.from_files([\"user_data/config.json\"])\n\n# Define some constants\nconfig[\"timeframe\"] = \"5m\"\n# Name of the strategy class\nconfig[\"strategy\"] = \"SampleStrategy\"\n# Location of the data\ndata_location = config[\"datadir\"]\n# Pair to analyze - Only use one pair here\npair = \"BTC/USDT\"\n
    # Load data using values set above\nfrom freqtrade.data.history import load_pair_history\nfrom freqtrade.enums import CandleType\n\n\ncandles = load_pair_history(\n    datadir=data_location,\n    timeframe=config[\"timeframe\"],\n    pair=pair,\n    data_format=\"json\",  # Make sure to update this to your data\n    candle_type=CandleType.SPOT,\n)\n\n# Confirm success\nprint(f\"Loaded {len(candles)} rows of data for {pair} from {data_location}\")\ncandles.head()\n
    "},{"location":"strategy_analysis_example/#load-and-run-strategy","title":"Load and run strategy","text":"
    • Rerun each time the strategy file is changed
    # Load strategy using values set above\nfrom freqtrade.data.dataprovider import DataProvider\nfrom freqtrade.resolvers import StrategyResolver\n\n\nstrategy = StrategyResolver.load_strategy(config)\nstrategy.dp = DataProvider(config, None, None)\nstrategy.ft_bot_start()\n\n# Generate buy/sell signals using strategy\ndf = strategy.analyze_ticker(candles, {\"pair\": pair})\ndf.tail()\n
    "},{"location":"strategy_analysis_example/#display-the-trade-details","title":"Display the trade details","text":"
    • Note that using data.head() would also work, however most indicators have some \"startup\" data at the top of the dataframe.
    • Some possible problems * Columns with NaN values at the end of the dataframe * Columns used in crossed*() functions with completely different units
    • Comparison with full backtest * having 200 buy signals as output for one pair from analyze_ticker() does not necessarily mean that 200 trades will be made during backtesting. * Assuming you use only one condition such as, df['rsi'] < 30 as buy condition, this will generate multiple \"buy\" signals for each pair in sequence (until rsi returns > 29). The bot will only buy on the first of these signals (and also only if a trade-slot (\"max_open_trades\") is still available), or on one of the middle signals, as soon as a \"slot\" becomes available.
    # Report results\nprint(f\"Generated {df['enter_long'].sum()} entry signals\")\ndata = df.set_index(\"date\", drop=False)\ndata.tail()\n
    "},{"location":"strategy_analysis_example/#load-existing-objects-into-a-jupyter-notebook","title":"Load existing objects into a Jupyter notebook","text":"

    The following cells assume that you have already generated data using the cli. They will allow you to drill deeper into your results, and perform analysis which otherwise would make the output very difficult to digest due to information overload.

    "},{"location":"strategy_analysis_example/#load-backtest-results-to-pandas-dataframe","title":"Load backtest results to pandas dataframe","text":"

    Analyze a trades dataframe (also used below for plotting)

    from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats\n\n\n# if backtest_dir points to a directory, it'll automatically load the last backtest file.\nbacktest_dir = config[\"user_data_dir\"] / \"backtest_results\"\n# backtest_dir can also point to a specific file\n# backtest_dir = (\n#   config[\"user_data_dir\"] / \"backtest_results/backtest-result-2020-07-01_20-04-22.json\"\n# )\n
    # You can get the full backtest statistics by using the following command.\n# This contains all information used to generate the backtest result.\nstats = load_backtest_stats(backtest_dir)\n\nstrategy = \"SampleStrategy\"\n# All statistics are available per strategy, so if `--strategy-list` was used during backtest,\n# this will be reflected here as well.\n# Example usages:\nprint(stats[\"strategy\"][strategy][\"results_per_pair\"])\n# Get pairlist used for this backtest\nprint(stats[\"strategy\"][strategy][\"pairlist\"])\n# Get market change (average change of all pairs from start to end of the backtest period)\nprint(stats[\"strategy\"][strategy][\"market_change\"])\n# Maximum drawdown ()\nprint(stats[\"strategy\"][strategy][\"max_drawdown\"])\n# Maximum drawdown start and end\nprint(stats[\"strategy\"][strategy][\"drawdown_start\"])\nprint(stats[\"strategy\"][strategy][\"drawdown_end\"])\n\n\n# Get strategy comparison (only relevant if multiple strategies were compared)\nprint(stats[\"strategy_comparison\"])\n
    # Load backtested trades as dataframe\ntrades = load_backtest_data(backtest_dir)\n\n# Show value-counts per pair\ntrades.groupby(\"pair\")[\"exit_reason\"].value_counts()\n
    "},{"location":"strategy_analysis_example/#plotting-daily-profit-equity-line","title":"Plotting daily profit / equity line","text":"
    # Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day)\n\nimport pandas as pd\nimport plotly.express as px\n\nfrom freqtrade.configuration import Configuration\nfrom freqtrade.data.btanalysis import load_backtest_stats\n\n\n# strategy = 'SampleStrategy'\n# config = Configuration.from_files([\"user_data/config.json\"])\n# backtest_dir = config[\"user_data_dir\"] / \"backtest_results\"\n\nstats = load_backtest_stats(backtest_dir)\nstrategy_stats = stats[\"strategy\"][strategy]\n\ndf = pd.DataFrame(columns=[\"dates\", \"equity\"], data=strategy_stats[\"daily_profit\"])\ndf[\"equity_daily\"] = df[\"equity\"].cumsum()\n\nfig = px.line(df, x=\"dates\", y=\"equity_daily\")\nfig.show()\n
    "},{"location":"strategy_analysis_example/#load-live-trading-results-into-a-pandas-dataframe","title":"Load live trading results into a pandas dataframe","text":"

    In case you did already some trading and want to analyze your performance

    from freqtrade.data.btanalysis import load_trades_from_db\n\n\n# Fetch trades from database\ntrades = load_trades_from_db(\"sqlite:///tradesv3.sqlite\")\n\n# Display results\ntrades.groupby(\"pair\")[\"exit_reason\"].value_counts()\n
    "},{"location":"strategy_analysis_example/#analyze-the-loaded-trades-for-trade-parallelism","title":"Analyze the loaded trades for trade parallelism","text":"

    This can be useful to find the best max_open_trades parameter, when used with backtesting in conjunction with --disable-max-market-positions.

    analyze_trade_parallelism() returns a timeseries dataframe with an \"open_trades\" column, specifying the number of open trades for each candle.

    from freqtrade.data.btanalysis import analyze_trade_parallelism\n\n\n# Analyze the above\nparallel_trades = analyze_trade_parallelism(trades, \"5m\")\n\nparallel_trades.plot()\n
    "},{"location":"strategy_analysis_example/#plot-results","title":"Plot results","text":"

    Freqtrade offers interactive plotting capabilities based on plotly.

    from freqtrade.plot.plotting import generate_candlestick_graph\n\n\n# Limit graph period to keep plotly quick and reactive\n\n# Filter trades to one pair\ntrades_red = trades.loc[trades[\"pair\"] == pair]\n\ndata_red = data[\"2019-06-01\":\"2019-06-10\"]\n# Generate candlestick graph\ngraph = generate_candlestick_graph(\n    pair=pair,\n    data=data_red,\n    trades=trades_red,\n    indicators1=[\"sma20\", \"ema50\", \"ema55\"],\n    indicators2=[\"rsi\", \"macd\", \"macdsignal\", \"macdhist\"],\n)\n
    # Show graph inline\n# graph.show()\n\n# Render graph in a separate window\ngraph.show(renderer=\"browser\")\n
    "},{"location":"strategy_analysis_example/#plot-average-profit-per-trade-as-distribution-graph","title":"Plot average profit per trade as distribution graph","text":"
    import plotly.figure_factory as ff\n\n\nhist_data = [trades.profit_ratio]\ngroup_labels = [\"profit_ratio\"]  # name of the dataset\n\nfig = ff.create_distplot(hist_data, group_labels, bin_size=0.01)\nfig.show()\n

    Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.

    "},{"location":"strategy_migration/","title":"Strategy Migration between V2 and V3","text":"

    To support new markets and trade-types (namely short trades / trades with leverage), some things had to change in the interface. If you intend on using markets other than spot markets, please migrate your strategy to the new format.

    We have put a great effort into keeping compatibility with existing strategies, so if you just want to continue using freqtrade in spot markets, there should be no changes necessary for now.

    You can use the quick summary as checklist. Please refer to the detailed sections below for full migration details.

    "},{"location":"strategy_migration/#quick-summary-migration-checklist","title":"Quick summary / migration checklist","text":"

    Note : forcesell, forcebuy, emergencysell are changed to force_exit, force_enter, emergency_exit respectively.

    • Strategy methods:
      • populate_buy_trend() -> populate_entry_trend()
      • populate_sell_trend() -> populate_exit_trend()
      • custom_sell() -> custom_exit()
      • check_buy_timeout() -> check_entry_timeout()
      • check_sell_timeout() -> check_exit_timeout()
      • New side argument to callbacks without trade object
        • custom_stake_amount
        • confirm_trade_entry
        • custom_entry_price
      • Changed argument name in confirm_trade_exit
    • Dataframe columns:
      • buy -> enter_long
      • sell -> exit_long
      • buy_tag -> enter_tag (used for both long and short trades)
      • New column enter_short and corresponding new column exit_short
    • trade-object now has the following new properties:
      • is_short
      • entry_side
      • exit_side
      • trade_direction
      • renamed: sell_reason -> exit_reason
    • Renamed trade.nr_of_successful_buys to trade.nr_of_successful_entries (mostly relevant for adjust_trade_position())
    • Introduced new leverage callback.
    • Informative pairs can now pass a 3rd element in the Tuple, defining the candle type.
    • @informative decorator now takes an optional candle_type argument.
    • helper methods stoploss_from_open and stoploss_from_absolute now take is_short as additional argument.
    • INTERFACE_VERSION should be set to 3.
    • Strategy/Configuration settings.
      • order_time_in_force buy -> entry, sell -> exit.
      • order_types buy -> entry, sell -> exit.
      • unfilledtimeout buy -> entry, sell -> exit.
      • ignore_buying_expired_candle_after -> moved to root level instead of \"ask_strategy/exit_pricing\"
    • Terminology changes
      • Sell reasons changed to reflect the new naming of \"exit\" instead of sells. Be careful in your strategy if you're using exit_reason checks and eventually update your strategy.
        • sell_signal -> exit_signal
        • custom_sell -> custom_exit
        • force_sell -> force_exit
        • emergency_sell -> emergency_exit
      • Order pricing
        • bid_strategy -> entry_pricing
        • ask_strategy -> exit_pricing
        • ask_last_balance -> price_last_balance
        • bid_last_balance -> price_last_balance
      • Webhook terminology changed from \"sell\" to \"exit\", and from \"buy\" to entry
        • webhookbuy -> entry
        • webhookbuyfill -> entry_fill
        • webhookbuycancel -> entry_cancel
        • webhooksell -> exit
        • webhooksellfill -> exit_fill
        • webhooksellcancel -> exit_cancel
      • Telegram notification settings
        • buy -> entry
        • buy_fill -> entry_fill
        • buy_cancel -> entry_cancel
        • sell -> exit
        • sell_fill -> exit_fill
        • sell_cancel -> exit_cancel
      • Strategy/config settings:
        • use_sell_signal -> use_exit_signal
        • sell_profit_only -> exit_profit_only
        • sell_profit_offset -> exit_profit_offset
        • ignore_roi_if_buy_signal -> ignore_roi_if_entry_signal
        • forcebuy_enable -> force_entry_enable
    "},{"location":"strategy_migration/#extensive-explanation","title":"Extensive explanation","text":""},{"location":"strategy_migration/#populate_buy_trend","title":"populate_buy_trend","text":"

    In populate_buy_trend() - you will want to change the columns you assign from 'buy' to 'enter_long', as well as the method name from populate_buy_trend to populate_entry_trend.

    def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['buy', 'buy_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n

    After:

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n

    Please refer to the Strategy documentation on how to enter and exit short trades.

    "},{"location":"strategy_migration/#populate_sell_trend","title":"populate_sell_trend","text":"

    Similar to populate_buy_trend, populate_sell_trend() will be renamed to populate_exit_trend(). We'll also change the column from 'sell' to 'exit_long'.

    def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['sell', 'exit_tag']] = (1, 'some_exit_tag')\n    return dataframe\n

    After

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'some_exit_tag')\n    return dataframe\n

    Please refer to the Strategy documentation on how to enter and exit short trades.

    "},{"location":"strategy_migration/#custom_sell","title":"custom_sell","text":"

    custom_sell has been renamed to custom_exit. It's now also being called for every iteration, independent of current profit and exit_profit_only settings.

    class AwesomeStrategy(IStrategy):\n    def custom_sell(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,\n                    current_profit: float, **kwargs):\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n        # ...\n
    class AwesomeStrategy(IStrategy):\n    def custom_exit(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,\n                    current_profit: float, **kwargs):\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n        # ...\n
    "},{"location":"strategy_migration/#custom_entry_timeout","title":"custom_entry_timeout","text":"

    check_buy_timeout() has been renamed to check_entry_timeout(), and check_sell_timeout() has been renamed to check_exit_timeout().

    class AwesomeStrategy(IStrategy):\n    def check_buy_timeout(self, pair: str, trade: 'Trade', order: dict, \n                            current_time: datetime, **kwargs) -> bool:\n        return False\n\n    def check_sell_timeout(self, pair: str, trade: 'Trade', order: dict, \n                            current_time: datetime, **kwargs) -> bool:\n        return False \n
    class AwesomeStrategy(IStrategy):\n    def check_entry_timeout(self, pair: str, trade: 'Trade', order: 'Order', \n                            current_time: datetime, **kwargs) -> bool:\n        return False\n\n    def check_exit_timeout(self, pair: str, trade: 'Trade', order: 'Order', \n                            current_time: datetime, **kwargs) -> bool:\n        return False \n
    "},{"location":"strategy_migration/#custom_stake_amount","title":"custom_stake_amount","text":"

    New string argument side - which can be either \"long\" or \"short\".

    class AwesomeStrategy(IStrategy):\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            entry_tag: Optional[str], **kwargs) -> float:\n        # ... \n        return proposed_stake\n
    class AwesomeStrategy(IStrategy):\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            entry_tag: Optional[str], side: str, **kwargs) -> float:\n        # ... \n        return proposed_stake\n
    "},{"location":"strategy_migration/#confirm_trade_entry","title":"confirm_trade_entry","text":"

    New string argument side - which can be either \"long\" or \"short\".

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,\n                            time_in_force: str, current_time: datetime, entry_tag: Optional[str], \n                            **kwargs) -> bool:\n      return True\n

    After:

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,\n                            time_in_force: str, current_time: datetime, entry_tag: Optional[str], \n                            side: str, **kwargs) -> bool:\n      return True\n
    "},{"location":"strategy_migration/#confirm_trade_exit","title":"confirm_trade_exit","text":"

    Changed argument sell_reason to exit_reason. For compatibility, sell_reason will still be provided for a limited time.

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,\n                           rate: float, time_in_force: str, sell_reason: str,\n                           current_time: datetime, **kwargs) -> bool:\n    return True\n

    After:

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,\n                           rate: float, time_in_force: str, exit_reason: str,\n                           current_time: datetime, **kwargs) -> bool:\n    return True\n
    "},{"location":"strategy_migration/#custom_entry_price","title":"custom_entry_price","text":"

    New string argument side - which can be either \"long\" or \"short\".

    class AwesomeStrategy(IStrategy):\n    def custom_entry_price(self, pair: str, current_time: datetime, proposed_rate: float,\n                           entry_tag: Optional[str], **kwargs) -> float:\n      return proposed_rate\n

    After:

    class AwesomeStrategy(IStrategy):\n    def custom_entry_price(self, pair: str, trade: Optional[Trade], current_time: datetime, proposed_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n      return proposed_rate\n
    "},{"location":"strategy_migration/#adjust-trade-position-changes","title":"Adjust trade position changes","text":"

    While adjust-trade-position itself did not change, you should no longer use trade.nr_of_successful_buys - and instead use trade.nr_of_successful_entries, which will also include short entries.

    "},{"location":"strategy_migration/#helper-methods","title":"Helper methods","text":"

    Added argument \"is_short\" to stoploss_from_open and stoploss_from_absolute. This should be given the value of trade.is_short.

        def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,\n                        current_rate: float, current_profit: float, **kwargs) -> float:\n        # once the profit has risen above 10%, keep the stoploss at 7% above the open price\n        if current_profit > 0.10:\n            return stoploss_from_open(0.07, current_profit)\n\n        return stoploss_from_absolute(current_rate - (candle['atr'] * 2), current_rate)\n\n        return 1\n

    After:

        def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n        # once the profit has risen above 10%, keep the stoploss at 7% above the open price\n        if current_profit > 0.10:\n            return stoploss_from_open(0.07, current_profit, is_short=trade.is_short)\n\n        return stoploss_from_absolute(current_rate - (candle['atr'] * 2), current_rate, is_short=trade.is_short, leverage=trade.leverage)\n
    "},{"location":"strategy_migration/#strategyconfiguration-settings","title":"Strategy/Configuration settings","text":""},{"location":"strategy_migration/#order_time_in_force","title":"order_time_in_force","text":"

    order_time_in_force attributes changed from \"buy\" to \"entry\" and \"sell\" to \"exit\".

        order_time_in_force: Dict = {\n        \"buy\": \"gtc\",\n        \"sell\": \"gtc\",\n    }\n

    After:

        order_time_in_force: Dict = {\n        \"entry\": \"GTC\",\n        \"exit\": \"GTC\",\n    }\n
    "},{"location":"strategy_migration/#order_types","title":"order_types","text":"

    order_types have changed all wordings from buy to entry - and sell to exit. And two words are joined with _.

        order_types = {\n        \"buy\": \"limit\",\n        \"sell\": \"limit\",\n        \"emergencysell\": \"market\",\n        \"forcesell\": \"market\",\n        \"forcebuy\": \"market\",\n        \"stoploss\": \"market\",\n        \"stoploss_on_exchange\": false,\n        \"stoploss_on_exchange_interval\": 60\n    }\n

    After:

        order_types = {\n        \"entry\": \"limit\",\n        \"exit\": \"limit\",\n        \"emergency_exit\": \"market\",\n        \"force_exit\": \"market\",\n        \"force_entry\": \"market\",\n        \"stoploss\": \"market\",\n        \"stoploss_on_exchange\": false,\n        \"stoploss_on_exchange_interval\": 60\n    }\n
    "},{"location":"strategy_migration/#strategy-level-settings","title":"Strategy level settings","text":"
    • use_sell_signal -> use_exit_signal
    • sell_profit_only -> exit_profit_only
    • sell_profit_offset -> exit_profit_offset
    • ignore_roi_if_buy_signal -> ignore_roi_if_entry_signal
        # These values can be overridden in the config.\n    use_sell_signal = True\n    sell_profit_only = True\n    sell_profit_offset: 0.01\n    ignore_roi_if_buy_signal = False\n

    After:

        # These values can be overridden in the config.\n    use_exit_signal = True\n    exit_profit_only = True\n    exit_profit_offset: 0.01\n    ignore_roi_if_entry_signal = False\n
    "},{"location":"strategy_migration/#unfilledtimeout","title":"unfilledtimeout","text":"

    unfilledtimeout have changed all wordings from buy to entry - and sell to exit.

    unfilledtimeout = {\n        \"buy\": 10,\n        \"sell\": 10,\n        \"exit_timeout_count\": 0,\n        \"unit\": \"minutes\"\n    }\n

    After:

    unfilledtimeout = {\n        \"entry\": 10,\n        \"exit\": 10,\n        \"exit_timeout_count\": 0,\n        \"unit\": \"minutes\"\n    }\n
    "},{"location":"strategy_migration/#order-pricing","title":"order pricing","text":"

    Order pricing changed in 2 ways. bid_strategy was renamed to entry_pricing and ask_strategy was renamed to exit_pricing. The attributes ask_last_balance -> price_last_balance and bid_last_balance -> price_last_balance were renamed as well. Also, price-side can now be defined as ask, bid, same or other. Please refer to the pricing documentation for more information.

    {\n    \"bid_strategy\": {\n        \"price_side\": \"bid\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"ask_last_balance\": 0.0,\n        \"check_depth_of_market\": {\n            \"enabled\": false,\n            \"bids_to_ask_delta\": 1\n        }\n    },\n    \"ask_strategy\":{\n        \"price_side\": \"ask\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"bid_last_balance\": 0.0\n        \"ignore_buying_expired_candle_after\": 120\n    }\n}\n

    after:

    {\n    \"entry_pricing\": {\n        \"price_side\": \"same\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"price_last_balance\": 0.0,\n        \"check_depth_of_market\": {\n            \"enabled\": false,\n            \"bids_to_ask_delta\": 1\n        }\n    },\n    \"exit_pricing\":{\n        \"price_side\": \"same\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"price_last_balance\": 0.0\n    },\n    \"ignore_buying_expired_candle_after\": 120\n}\n
    "},{"location":"strategy_migration/#freqai-strategy","title":"FreqAI strategy","text":"

    The populate_any_indicators() method has been split into feature_engineering_expand_all(), feature_engineering_expand_basic(), feature_engineering_standard() andset_freqai_targets().

    For each new function, the pair (and timeframe where necessary) will be automatically added to the column. As such, the definition of features becomes much simpler with the new logic.

    For a full explanation of each method, please go to the corresponding freqAI documentation page

    def populate_any_indicators(\n        self, pair, df, tf, informative=None, set_generalized_indicators=False\n    ):\n\n        if informative is None:\n            informative = self.dp.get_pair_dataframe(pair, tf)\n\n        # first loop is automatically duplicating indicators for time periods\n        for t in self.freqai_info[\"feature_parameters\"][\"indicator_periods_candles\"]:\n\n            t = int(t)\n            informative[f\"%-{pair}rsi-period_{t}\"] = ta.RSI(informative, timeperiod=t)\n            informative[f\"%-{pair}mfi-period_{t}\"] = ta.MFI(informative, timeperiod=t)\n            informative[f\"%-{pair}adx-period_{t}\"] = ta.ADX(informative, timeperiod=t)\n            informative[f\"%-{pair}sma-period_{t}\"] = ta.SMA(informative, timeperiod=t)\n            informative[f\"%-{pair}ema-period_{t}\"] = ta.EMA(informative, timeperiod=t)\n\n            bollinger = qtpylib.bollinger_bands(\n                qtpylib.typical_price(informative), window=t, stds=2.2\n            )\n            informative[f\"{pair}bb_lowerband-period_{t}\"] = bollinger[\"lower\"]\n            informative[f\"{pair}bb_middleband-period_{t}\"] = bollinger[\"mid\"]\n            informative[f\"{pair}bb_upperband-period_{t}\"] = bollinger[\"upper\"]\n\n            informative[f\"%-{pair}bb_width-period_{t}\"] = (\n                informative[f\"{pair}bb_upperband-period_{t}\"]\n                - informative[f\"{pair}bb_lowerband-period_{t}\"]\n            ) / informative[f\"{pair}bb_middleband-period_{t}\"]\n            informative[f\"%-{pair}close-bb_lower-period_{t}\"] = (\n                informative[\"close\"] / informative[f\"{pair}bb_lowerband-period_{t}\"]\n            )\n\n            informative[f\"%-{pair}roc-period_{t}\"] = ta.ROC(informative, timeperiod=t)\n\n            informative[f\"%-{pair}relative_volume-period_{t}\"] = (\n                informative[\"volume\"] / informative[\"volume\"].rolling(t).mean()\n            ) # (1)\n\n        informative[f\"%-{pair}pct-change\"] = informative[\"close\"].pct_change()\n        informative[f\"%-{pair}raw_volume\"] = informative[\"volume\"]\n        informative[f\"%-{pair}raw_price\"] = informative[\"close\"]\n        # (2)\n\n        indicators = [col for col in informative if col.startswith(\"%\")]\n        # This loop duplicates and shifts all indicators to add a sense of recency to data\n        for n in range(self.freqai_info[\"feature_parameters\"][\"include_shifted_candles\"] + 1):\n            if n == 0:\n                continue\n            informative_shift = informative[indicators].shift(n)\n            informative_shift = informative_shift.add_suffix(\"_shift-\" + str(n))\n            informative = pd.concat((informative, informative_shift), axis=1)\n\n        df = merge_informative_pair(df, informative, self.config[\"timeframe\"], tf, ffill=True)\n        skip_columns = [\n            (s + \"_\" + tf) for s in [\"date\", \"open\", \"high\", \"low\", \"close\", \"volume\"]\n        ]\n        df = df.drop(columns=skip_columns)\n\n        # Add generalized indicators here (because in live, it will call this\n        # function to populate indicators during training). Notice how we ensure not to\n        # add them multiple times\n        if set_generalized_indicators:\n            df[\"%-day_of_week\"] = (df[\"date\"].dt.dayofweek + 1) / 7\n            df[\"%-hour_of_day\"] = (df[\"date\"].dt.hour + 1) / 25\n            # (3)\n\n            # user adds targets here by prepending them with &- (see convention below)\n            df[\"&-s_close\"] = (\n                df[\"close\"]\n                .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n                .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n                .mean()\n                / df[\"close\"]\n                - 1\n            )  # (4)\n\n        return df\n
    1. Features - Move to feature_engineering_expand_all
    2. Basic features, not expanded across indicator_periods_candles - move tofeature_engineering_expand_basic().
    3. Standard features which should not be expanded - move to feature_engineering_standard().
    4. Targets - Move this part to set_freqai_targets().
    "},{"location":"strategy_migration/#freqai-feature-engineering-expand-all","title":"freqai - feature engineering expand all","text":"

    Features will now expand automatically. As such, the expansion loops, as well as the {pair} / {timeframe} parts will need to be removed.

        def feature_engineering_expand_all(self, dataframe, period, **kwargs) -> DataFrame::\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and\n        `include_corr_pairs`. In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *\n        `include_corr_pairs` numbers of features added to the model.\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        More details on how these config defined parameters accelerate feature engineering\n        in the documentation at:\n\n        https://www.freqtrade.io/en/latest/freqai-parameter-table/#feature-parameters\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features\n\n        :param df: strategy dataframe which will receive the features\n        :param period: period of the indicator - usage example:\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n        \"\"\"\n\n        dataframe[\"%-rsi-period\"] = ta.RSI(dataframe, timeperiod=period)\n        dataframe[\"%-mfi-period\"] = ta.MFI(dataframe, timeperiod=period)\n        dataframe[\"%-adx-period\"] = ta.ADX(dataframe, timeperiod=period)\n        dataframe[\"%-sma-period\"] = ta.SMA(dataframe, timeperiod=period)\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n\n        bollinger = qtpylib.bollinger_bands(\n            qtpylib.typical_price(dataframe), window=period, stds=2.2\n        )\n        dataframe[\"bb_lowerband-period\"] = bollinger[\"lower\"]\n        dataframe[\"bb_middleband-period\"] = bollinger[\"mid\"]\n        dataframe[\"bb_upperband-period\"] = bollinger[\"upper\"]\n\n        dataframe[\"%-bb_width-period\"] = (\n            dataframe[\"bb_upperband-period\"]\n            - dataframe[\"bb_lowerband-period\"]\n        ) / dataframe[\"bb_middleband-period\"]\n        dataframe[\"%-close-bb_lower-period\"] = (\n            dataframe[\"close\"] / dataframe[\"bb_lowerband-period\"]\n        )\n\n        dataframe[\"%-roc-period\"] = ta.ROC(dataframe, timeperiod=period)\n\n        dataframe[\"%-relative_volume-period\"] = (\n            dataframe[\"volume\"] / dataframe[\"volume\"].rolling(period).mean()\n        )\n\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-feature-engineering-basic","title":"Freqai - feature engineering basic","text":"

    Basic features. Make sure to remove the {pair} part from your features.

        def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs) -> DataFrame::\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.\n        In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `include_timeframes` * `include_shifted_candles` * `include_corr_pairs`\n        numbers of features added to the model.\n\n        Features defined here will *not* be automatically duplicated on user defined\n        `indicator_periods_candles`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        More details on how these config defined parameters accelerate feature engineering\n        in the documentation at:\n\n        https://www.freqtrade.io/en/latest/freqai-parameter-table/#feature-parameters\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features\n\n        :param df: strategy dataframe which will receive the features\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-ema-200\"] = ta.EMA(dataframe, timeperiod=200)\n        \"\"\"\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-raw_volume\"] = dataframe[\"volume\"]\n        dataframe[\"%-raw_price\"] = dataframe[\"close\"]\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-feature-engineering-standard","title":"FreqAI - feature engineering standard","text":"
        def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This optional function will be called once with the dataframe of the base timeframe.\n        This is the final function to be called, which means that the dataframe entering this\n        function will contain all the features and columns created by all other\n        freqai_feature_engineering_* functions.\n\n        This function is a good place to do custom exotic feature extractions (e.g. tsfresh).\n        This function is a good place for any feature that should not be auto-expanded upon\n        (e.g. day of the week).\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        More details about feature engineering available:\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering\n\n        :param df: strategy dataframe which will receive the features\n        usage example: dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        \"\"\"\n        dataframe[\"%-day_of_week\"] = dataframe[\"date\"].dt.dayofweek\n        dataframe[\"%-hour_of_day\"] = dataframe[\"date\"].dt.hour\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-set-targets","title":"FreqAI - set Targets","text":"

    Targets now get their own, dedicated method.

        def set_freqai_targets(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        More details about feature engineering available:\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering\n\n        :param df: strategy dataframe which will receive the targets\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        dataframe[\"&-s_close\"] = (\n            dataframe[\"close\"]\n            .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .mean()\n            / dataframe[\"close\"]\n            - 1\n            )\n\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-new-data-pipeline","title":"FreqAI - New data Pipeline","text":"

    If you have created your own custom IFreqaiModel with a custom train()/predict() function, and you still rely on data_cleaning_train/predict(), then you will need to migrate to the new pipeline. If your model does not rely on data_cleaning_train/predict(), then you do not need to worry about this migration. That means that this migration guide is relevant for a very small percentage of power-users. If you stumbled upon this guide by mistake, feel free to inquire in depth about your problem in the Freqtrade discord server.

    The conversion involves first removing data_cleaning_train/predict() and replacing them with a define_data_pipeline() and define_label_pipeline() function to your IFreqaiModel class:

    class MyCoolFreqaiModel(BaseRegressionModel):\n    \"\"\"\n    Some cool custom IFreqaiModel you made before Freqtrade version 2023.6\n    \"\"\"\n    def train(\n        self, unfiltered_df: DataFrame, pair: str, dk: FreqaiDataKitchen, **kwargs\n    ) -> Any:\n\n        # ... your custom stuff\n\n        # Remove these lines\n        # data_dictionary = dk.make_train_test_datasets(features_filtered, labels_filtered)\n        # self.data_cleaning_train(dk)\n        # data_dictionary = dk.normalize_data(data_dictionary)\n        # (1)\n\n        # Add these lines. Now we control the pipeline fit/transform ourselves\n        dd = dk.make_train_test_datasets(features_filtered, labels_filtered)\n        dk.feature_pipeline = self.define_data_pipeline(threads=dk.thread_count)\n        dk.label_pipeline = self.define_label_pipeline(threads=dk.thread_count)\n\n        (dd[\"train_features\"],\n         dd[\"train_labels\"],\n         dd[\"train_weights\"]) = dk.feature_pipeline.fit_transform(dd[\"train_features\"],\n                                                                  dd[\"train_labels\"],\n                                                                  dd[\"train_weights\"])\n\n        (dd[\"test_features\"],\n         dd[\"test_labels\"],\n         dd[\"test_weights\"]) = dk.feature_pipeline.transform(dd[\"test_features\"],\n                                                             dd[\"test_labels\"],\n                                                             dd[\"test_weights\"])\n\n        dd[\"train_labels\"], _, _ = dk.label_pipeline.fit_transform(dd[\"train_labels\"])\n        dd[\"test_labels\"], _, _ = dk.label_pipeline.transform(dd[\"test_labels\"])\n\n        # ... your custom code\n\n        return model\n\n    def predict(\n        self, unfiltered_df: DataFrame, dk: FreqaiDataKitchen, **kwargs\n    ) -> Tuple[DataFrame, npt.NDArray[np.int_]]:\n\n        # ... your custom stuff\n\n        # Remove these lines:\n        # self.data_cleaning_predict(dk)\n        # (2)\n\n        # Add these lines:\n        dk.data_dictionary[\"prediction_features\"], outliers, _ = dk.feature_pipeline.transform(\n            dk.data_dictionary[\"prediction_features\"], outlier_check=True)\n\n        # Remove this line\n        # pred_df = dk.denormalize_labels_from_metadata(pred_df)\n        # (3)\n\n        # Replace with these lines\n        pred_df, _, _ = dk.label_pipeline.inverse_transform(pred_df)\n        if self.freqai_info.get(\"DI_threshold\", 0) > 0:\n            dk.DI_values = dk.feature_pipeline[\"di\"].di_values\n        else:\n            dk.DI_values = np.zeros(outliers.shape[0])\n        dk.do_predict = outliers\n\n        # ... your custom code\n        return (pred_df, dk.do_predict)\n
    1. Data normalization and cleaning is now homogenized with the new pipeline definition. This is created in the new define_data_pipeline() and define_label_pipeline() functions. The data_cleaning_train() and data_cleaning_predict() functions are no longer used. You can override define_data_pipeline() to create your own custom pipeline if you wish.
    2. Data normalization and cleaning is now homogenized with the new pipeline definition. This is created in the new define_data_pipeline() and define_label_pipeline() functions. The data_cleaning_train() and data_cleaning_predict() functions are no longer used. You can override define_data_pipeline() to create your own custom pipeline if you wish.
    3. Data denormalization is done with the new pipeline. Replace this with the lines below.
    "},{"location":"telegram-usage/","title":"Telegram usage","text":""},{"location":"telegram-usage/#setup-your-telegram-bot","title":"Setup your Telegram bot","text":"

    Below we explain how to create your Telegram Bot, and how to get your Telegram user id.

    "},{"location":"telegram-usage/#1-create-your-telegram-bot","title":"1. Create your Telegram bot","text":"

    Start a chat with the Telegram BotFather

    Send the message /newbot.

    BotFather response:

    Alright, a new bot. How are we going to call it? Please choose a name for your bot.

    Choose the public name of your bot (e.x. Freqtrade bot)

    BotFather response:

    Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.

    Choose the name id of your bot and send it to the BotFather (e.g. \"My_own_freqtrade_bot\")

    BotFather response:

    Done! Congratulations on your new bot. You will find it at t.me/yourbots_name_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.

    Use this token to access the HTTP API: 22222222:APITOKEN

    For a description of the Bot API, see this page: https://core.telegram.org/bots/api Father bot will return you the token (API key)

    Copy the API Token (22222222:APITOKEN in the above example) and keep use it for the config parameter token.

    Don't forget to start the conversation with your bot, by clicking /START button

    "},{"location":"telegram-usage/#2-telegram-user_id","title":"2. Telegram user_id","text":""},{"location":"telegram-usage/#get-your-user-id","title":"Get your user id","text":"

    Talk to the userinfobot

    Get your \"Id\", you will use it for the config parameter chat_id.

    "},{"location":"telegram-usage/#use-group-id","title":"Use Group id","text":"

    You can use bots in telegram groups by just adding them to the group. You can find the group id by first adding a RawDataBot to your group. The Group id is shown as id in the \"chat\" section, which the RawDataBot will send to you:

    \"chat\":{\n   \"id\":-1001332619709\n}\n

    For the Freqtrade configuration, you can then use the full value (including - if it's there) as string:

       \"chat_id\": \"-1001332619709\"\n

    Using telegram groups

    When using telegram groups, you're giving every member of the telegram group access to your freqtrade bot and to all commands possible via telegram. Please make sure that you can trust everyone in the telegram group to avoid unpleasant surprises.

    "},{"location":"telegram-usage/#control-telegram-noise","title":"Control telegram noise","text":"

    Freqtrade provides means to control the verbosity of your telegram bot. Each setting has the following possible values:

    • on - Messages will be sent, and user will be notified.
    • silent - Message will be sent, Notification will be without sound / vibration.
    • off - Skip sending a message-type all together.

    Example configuration showing the different settings:

    \"telegram\": {\n    \"enabled\": true,\n    \"token\": \"your_telegram_token\",\n    \"chat_id\": \"your_telegram_chat_id\",\n    \"allow_custom_messages\": true,\n    \"notification_settings\": {\n        \"status\": \"silent\",\n        \"warning\": \"on\",\n        \"startup\": \"off\",\n        \"entry\": \"silent\",\n        \"entry_fill\": \"on\",\n        \"entry_cancel\": \"silent\",\n        \"exit\": {\n            \"roi\": \"silent\",\n            \"emergency_exit\": \"on\",\n            \"force_exit\": \"on\",\n            \"exit_signal\": \"silent\",\n            \"trailing_stop_loss\": \"on\",\n            \"stop_loss\": \"on\",\n            \"stoploss_on_exchange\": \"on\",\n            \"custom_exit\": \"silent\",\n            \"partial_exit\": \"on\"\n        },\n        \"exit_cancel\": \"on\",\n        \"exit_fill\": \"off\",\n        \"protection_trigger\": \"off\",\n        \"protection_trigger_global\": \"on\",\n        \"strategy_msg\": \"off\",\n        \"show_candle\": \"off\"\n    },\n    \"reload\": true,\n    \"balance_dust_level\": 0.01\n},\n

    entry notifications are sent when the order is placed, while entry_fill notifications are sent when the order is filled on the exchange. exit notifications are sent when the order is placed, while exit_fill notifications are sent when the order is filled on the exchange. *_fill notifications are off by default and must be explicitly enabled. protection_trigger notifications are sent when a protection triggers and protection_trigger_global notifications trigger when global protections are triggered. strategy_msg - Receive notifications from the strategy, sent via self.dp.send_msg() from the strategy more details. show_candle - show candle values as part of entry/exit messages. Only possible values are \"ohlc\" or \"off\".

    balance_dust_level will define what the /balance command takes as \"dust\" - Currencies with a balance below this will be shown. allow_custom_messages completely disable strategy messages. reload allows you to disable reload-buttons on selected messages.

    "},{"location":"telegram-usage/#create-a-custom-keyboard-command-shortcut-buttons","title":"Create a custom keyboard (command shortcut buttons)","text":"

    Telegram allows us to create a custom keyboard with buttons for commands. The default custom keyboard looks like this.

    [\n    [\"/daily\", \"/profit\", \"/balance\"], # row 1, 3 commands\n    [\"/status\", \"/status table\", \"/performance\"], # row 2, 3 commands\n    [\"/count\", \"/start\", \"/stop\", \"/help\"] # row 3, 4 commands\n]\n
    "},{"location":"telegram-usage/#usage","title":"Usage","text":"

    You can create your own keyboard in config.json:

    \"telegram\": {\n      \"enabled\": true,\n      \"token\": \"your_telegram_token\",\n      \"chat_id\": \"your_telegram_chat_id\",\n      \"keyboard\": [\n          [\"/daily\", \"/stats\", \"/balance\", \"/profit\"],\n          [\"/status table\", \"/performance\"],\n          [\"/reload_config\", \"/count\", \"/logs\"]\n      ]\n   },\n

    Supported Commands

    Only the following commands are allowed. Command arguments are not supported!

    /start, /stop, /status, /status table, /trades, /profit, /performance, /daily, /stats, /count, /locks, /balance, /stopentry, /reload_config, /show_config, /logs, /whitelist, /blacklist, /edge, /help, /version, /marketdir

    "},{"location":"telegram-usage/#telegram-commands","title":"Telegram commands","text":"

    Per default, the Telegram bot shows predefined commands. Some commands are only available by sending them to the bot. The table below list the official commands. You can ask at any moment for help with /help.

    Command Description System commands /start Starts the trader /stop Stops the trader /stopbuy | /stopentry Stops the trader from opening new trades. Gracefully closes open trades according to their rules. /reload_config Reloads the configuration file /show_config Shows part of the current configuration with relevant settings to operation /logs [limit] Show last log messages. /help Show help message /version Show version Status /status Lists all open trades /status <trade_id> Lists one or more specific trade. Separate multiple with a blank space. /status table List all open trades in a table format. Pending buy orders are marked with an asterisk () Pending sell orders are marked with a double asterisk (*) /order <trade_id> Lists orders of one or more specific trade. Separate multiple with a blank space. /trades [limit] List all recently closed trades in a table format. /count Displays number of trades used and available /locks Show currently locked pairs. /unlock <pair or lock_id> Remove the lock for this pair (or for this lock id). /marketdir [long | short | even | none] Updates the user managed variable that represents the current market direction. If no direction is provided, the currently set direction will be displayed. /list_custom_data <trade_id> [key] List custom_data for Trade ID & Key combination. If no Key is supplied it will list all key-value pairs found for that Trade ID. Modify Trade states /forceexit <trade_id> | /fx <tradeid> Instantly exits the given trade (Ignoring minimum_roi). /forceexit all | /fx all Instantly exits all open trades (Ignoring minimum_roi). /fx alias for /forceexit /forcelong <pair> [rate] Instantly buys the given pair. Rate is optional and only applies to limit orders. (force_entry_enable must be set to True) /forceshort <pair> [rate] Instantly shorts the given pair. Rate is optional and only applies to limit orders. This will only work on non-spot markets. (force_entry_enable must be set to True) /delete <trade_id> Delete a specific trade from the Database. Tries to close open orders. Requires manual handling of this trade on the exchange. /reload_trade <trade_id> Reload a trade from the Exchange. Only works in live, and can potentially help recover a trade that was manually sold on the exchange. /cancel_open_order <trade_id> | /coo <trade_id> Cancel an open order for a trade. Metrics /profit [<n>] Display a summary of your profit/loss from close trades and some stats about your performance, over the last n days (all trades by default) /performance Show performance of each finished trade grouped by pair /balance Show bot managed balance per currency /balance full Show account balance per currency /daily <n> Shows profit or loss per day, over the last n days (n defaults to 7) /weekly <n> Shows profit or loss per week, over the last n weeks (n defaults to 8) /monthly <n> Shows profit or loss per month, over the last n months (n defaults to 6) /stats Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells /exits Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells /entries Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells /whitelist [sorted] [baseonly] Show the current whitelist. Optionally display in alphabetical order and/or with just the base currency of each pairing. /blacklist [pair] Show the current blacklist, or adds a pair to the blacklist. /edge Show validated pairs by Edge if it is enabled."},{"location":"telegram-usage/#telegram-commands-in-action","title":"Telegram commands in action","text":"

    Below, example of Telegram message you will receive for each command.

    "},{"location":"telegram-usage/#start","title":"/start","text":"

    Status: running

    "},{"location":"telegram-usage/#stop","title":"/stop","text":"

    Stopping trader ... Status: stopped

    "},{"location":"telegram-usage/#stopbuy","title":"/stopbuy","text":"

    status: Setting max_open_trades to 0. Run /reload_config to reset.

    Prevents the bot from opening new trades by temporarily setting \"max_open_trades\" to 0. Open trades will be handled via their regular rules (ROI / Sell-signal, stoploss, ...).

    After this, give the bot time to close off open trades (can be checked via /status table). Once all positions are sold, run /stop to completely stop the bot.

    /reload_config resets \"max_open_trades\" to the value set in the configuration and resets this command.

    Warning

    The stop-buy signal is ONLY active while the bot is running, and is not persisted anyway, so restarting the bot will cause this to reset.

    "},{"location":"telegram-usage/#status","title":"/status","text":"

    For each open trade, the bot will send you the following message. Enter Tag is configurable via Strategy.

    Trade ID: 123 (since 1 days ago) Current Pair: CVC/BTC Direction: Long Leverage: 1.0 Amount: 26.64180098 Enter Tag: Awesome Long Signal Open Rate: 0.00007489 Current Rate: 0.00007489 Unrealized Profit: 12.95% Stoploss: 0.00007389 (-0.02%)

    "},{"location":"telegram-usage/#status-table","title":"/status table","text":"

    Return the status of all open trades in a table format.

    ID L/S    Pair     Since   Profit\n----    --------  -------  --------\n  67 L   SC/BTC    1 d      13.33%\n 123 S   CVC/BTC   1 h      12.95%\n
    "},{"location":"telegram-usage/#count","title":"/count","text":"

    Return the number of trades used and available.

    current    max\n---------  -----\n     2     10\n
    "},{"location":"telegram-usage/#profit","title":"/profit","text":"

    Return a summary of your profit/loss and performance.

    ROI: Close trades \u2219 0.00485701 BTC (2.2%) (15.2 \u03a3%) \u2219 62.968 USD ROI: All trades \u2219 0.00255280 BTC (1.5%) (6.43 \u03a3%) \u2219 33.095 EUR

    Total Trade Count: 138 Bot started: 2022-07-11 18:40:44 First Trade opened: 3 days ago Latest Trade opened: 2 minutes ago Avg. Duration: 2:33:45 Best Performing: PAY/BTC: 50.23% Trading volume: 0.5 BTC Profit factor: 1.04 Win / Loss: 102 / 36 Winrate: 73.91% Expectancy (Ratio): 4.87 (1.66) Max Drawdown: 9.23% (0.01255 BTC)

    The relative profit of 1.2% is the average profit per trade. The relative profit of 15.2 \u03a3% is be based on the starting capital - so in this case, the starting capital was 0.00485701 * 1.152 = 0.00738 BTC. Starting capital is either taken from the available_capital setting, or calculated by using current wallet size - profits. Profit Factor is calculated as gross profits / gross losses - and should serve as an overall metric for the strategy. Expectancy corresponds to the average return per currency unit at risk, i.e. the winrate and the risk-reward ratio (the average gain of winning trades compared to the average loss of losing trades). Expectancy Ratio is expected profit or loss of a subsequent trade based on the performance of all past trades. Max drawdown corresponds to the backtesting metric Absolute Drawdown (Account) - calculated as (Absolute Drawdown) / (DrawdownHigh + startingBalance). Bot started date will refer to the date the bot was first started. For older bots, this will default to the first trade's open date.

    "},{"location":"telegram-usage/#forceexit","title":"/forceexit

    BINANCE: Exiting BTC/LTC with limit 0.01650000 (profit: ~-4.07%, -0.00008168)

    Tip

    You can get a list of all open trades by calling /forceexit without parameter, which will show a list of buttons to simply exit a trade. This command has an alias in /fx - which has the same capabilities, but is faster to type in \"emergency\" situations.

    ","text":""},{"location":"telegram-usage/#forcelong-rate-forceshort-rate","title":"/forcelong [rate] | /forceshort [rate]

    /forcebuy <pair> [rate] is also supported for longs but should be considered deprecated.

    BINANCE: Long ETH/BTC with limit 0.03400000 (1.000000 ETH, 225.290 USD)

    Omitting the pair will open a query asking for the pair to trade (based on the current whitelist). Trades created through /forcelong will have the buy-tag of force_entry.

    Note that for this to work, force_entry_enable needs to be set to true.

    More details

    ","text":""},{"location":"telegram-usage/#performance","title":"/performance

    Return the performance of each crypto-currency the bot has sold.

    Performance: 1. RCN/BTC 0.003 BTC (57.77%) (1) 2. PAY/BTC 0.0012 BTC (56.91%) (1) 3. VIB/BTC 0.0011 BTC (47.07%) (1) 4. SALT/BTC 0.0010 BTC (30.24%) (1) 5. STORJ/BTC 0.0009 BTC (27.24%) (1) ...

    ","text":""},{"location":"telegram-usage/#balance","title":"/balance

    Return the balance of all crypto-currency your have on the exchange.

    Currency: BTC Available: 3.05890234 Balance: 3.05890234 Pending: 0.0

    Currency: CVC Available: 86.64180098 Balance: 86.64180098 Pending: 0.0

    ","text":""},{"location":"telegram-usage/#daily","title":"/daily

    Per default /daily will return the 7 last days. The example below if for /daily 3:

    Daily Profit over the last 3 days:

    Day (count)     USDT          USD         Profit %\n--------------  ------------  ----------  ----------\n2022-06-11 (1)  -0.746 USDT   -0.75 USD   -0.08%\n2022-06-10 (0)  0 USDT        0.00 USD    0.00%\n2022-06-09 (5)  20 USDT       20.10 USD   5.00%\n

    ","text":""},{"location":"telegram-usage/#weekly","title":"/weekly

    Per default /weekly will return the 8 last weeks, including the current week. Each week starts from Monday. The example below if for /weekly 3:

    Weekly Profit over the last 3 weeks (starting from Monday):

    Monday (count)  Profit BTC      Profit USD   Profit %\n-------------  --------------  ------------    ----------\n2018-01-03 (5)  0.00224175 BTC  29,142 USD   4.98%\n2017-12-27 (1)  0.00033131 BTC   4,307 USD   0.00%\n2017-12-20 (4)  0.00269130 BTC  34.986 USD   5.12%\n

    ","text":""},{"location":"telegram-usage/#monthly","title":"/monthly

    Per default /monthly will return the 6 last months, including the current month. The example below if for /monthly 3:

    Monthly Profit over the last 3 months:

    Month (count)  Profit BTC      Profit USD    Profit %\n-------------  --------------  ------------    ----------\n2018-01 (20)    0.00224175 BTC  29,142 USD  4.98%\n2017-12 (5)    0.00033131 BTC   4,307 USD   0.00%\n2017-11 (10)    0.00269130 BTC  34.986 USD  5.10%\n

    ","text":""},{"location":"telegram-usage/#whitelist","title":"/whitelist

    Shows the current whitelist

    Using whitelist StaticPairList with 22 pairs IOTA/BTC, NEO/BTC, TRX/BTC, VET/BTC, ADA/BTC, ETC/BTC, NCASH/BTC, DASH/BTC, XRP/BTC, XVG/BTC, EOS/BTC, LTC/BTC, OMG/BTC, BTG/BTC, LSK/BTC, ZEC/BTC, HOT/BTC, IOTX/BTC, XMR/BTC, AST/BTC, XLM/BTC, NANO/BTC

    ","text":""},{"location":"telegram-usage/#blacklist-pair","title":"/blacklist [pair]

    Shows the current blacklist. If Pair is set, then this pair will be added to the pairlist. Also supports multiple pairs, separated by a space. Use /reload_config to reset the blacklist.

    Using blacklist StaticPairList with 2 pairs DODGE/BTC, HOT/BTC.

    ","text":""},{"location":"telegram-usage/#edge","title":"/edge

    Shows pairs validated by Edge along with their corresponding win-rate, expectancy and stoploss values.

    Edge only validated following pairs:

    Pair        Winrate    Expectancy    Stoploss\n--------  ---------  ------------  ----------\nDOCK/ETH   0.522727      0.881821       -0.03\nPHX/ETH    0.677419      0.560488       -0.03\nHOT/ETH    0.733333      0.490492       -0.03\nHC/ETH     0.588235      0.280988       -0.02\nARDR/ETH   0.366667      0.143059       -0.01\n

    ","text":""},{"location":"telegram-usage/#version","title":"/version

    Version: 0.14.3

    ","text":""},{"location":"telegram-usage/#marketdir","title":"/marketdir

    If a market direction is provided the command updates the user managed variable that represents the current market direction. This variable is not set to any valid market direction on bot startup and must be set by the user. The example below is for /marketdir long:

    Successfully updated marketdirection from none to long.\n

    If no market direction is provided the command outputs the currently set market directions. The example below is for /marketdir:

    Currently set marketdirection: even\n

    You can use the market direction in your strategy via self.market_direction.

    Bot restarts

    Please note that the market direction is not persisted, and will be reset after a bot restart/reload.

    Backtesting

    As this value/variable is intended to be changed manually in dry/live trading. Strategies using market_direction will probably not produce reliable, reproducible results (changes to this variable will not be reflected for backtesting). Use at your own risk.

    ","text":""},{"location":"trade-object/","title":"Trade Object","text":""},{"location":"trade-object/#trade","title":"Trade","text":"

    A position freqtrade enters is stored in a Trade object - which is persisted to the database. It's a core concept of freqtrade - and something you'll come across in many sections of the documentation, which will most likely point you to this location.

    It will be passed to the strategy in many strategy callbacks. The object passed to the strategy cannot be modified directly. Indirect modifications may occur based on callback results.

    "},{"location":"trade-object/#trade-available-attributes","title":"Trade - Available attributes","text":"

    The following attributes / properties are available for each individual trade - and can be used with trade.<property> (e.g. trade.pair).

    Attribute DataType Description pair string Pair of this trade. is_open boolean Is the trade currently open, or has it been concluded. open_rate float Rate this trade was entered at (Avg. entry rate in case of trade-adjustments). close_rate float Close rate - only set when is_open = False. stake_amount float Amount in Stake (or Quote) currency. amount float Amount in Asset / Base currency that is currently owned. open_date datetime Timestamp when trade was opened use open_date_utc instead open_date_utc datetime Timestamp when trade was opened - in UTC. close_date datetime Timestamp when trade was closed use close_date_utc instead close_date_utc datetime Timestamp when trade was closed - in UTC. close_profit float Relative profit at the time of trade closure. 0.01 == 1% close_profit_abs float Absolute profit (in stake currency) at the time of trade closure. leverage float Leverage used for this trade - defaults to 1.0 in spot markets. enter_tag string Tag provided on entry via the enter_tag column in the dataframe. is_short boolean True for short trades, False otherwise. orders Order[] List of order objects attached to this trade (includes both filled and cancelled orders). date_last_filled_utc datetime Time of the last filled order. entry_side \"buy\" / \"sell\" Order Side the trade was entered. exit_side \"buy\" / \"sell\" Order Side that will result in a trade exit / position reduction. trade_direction \"long\" / \"short\" Trade direction in text - long or short. nr_of_successful_entries int Number of successful (filled) entry orders. nr_of_successful_exits int Number of successful (filled) exit orders."},{"location":"trade-object/#class-methods","title":"Class methods","text":"

    The following are class methods - which return generic information, and usually result in an explicit query against the database. They can be used as Trade.<method> - e.g. open_trades = Trade.get_open_trade_count()

    Backtesting/hyperopt

    Most methods will work in both backtesting / hyperopt and live/dry modes. During backtesting, it's limited to usage in strategy callbacks. Usage in populate_*() methods is not supported and will result in wrong results.

    "},{"location":"trade-object/#get_trades_proxy","title":"get_trades_proxy","text":"

    When your strategy needs some information on existing (open or close) trades - it's best to use Trade.get_trades_proxy().

    Usage:

    from freqtrade.persistence import Trade\nfrom datetime import timedelta\n\n# ...\ntrade_hist = Trade.get_trades_proxy(pair='ETH/USDT', is_open=False, open_date=current_date - timedelta(days=2))\n

    get_trades_proxy() supports the following keyword arguments. All arguments are optional - calling get_trades_proxy() without arguments will return a list of all trades in the database.

    • pair e.g. pair='ETH/USDT'
    • is_open e.g. is_open=False
    • open_date e.g. open_date=current_date - timedelta(days=2)
    • close_date e.g. close_date=current_date - timedelta(days=5)
    "},{"location":"trade-object/#get_open_trade_count","title":"get_open_trade_count","text":"

    Get the number of currently open trades

    from freqtrade.persistence import Trade\n# ...\nopen_trades = Trade.get_open_trade_count()\n
    "},{"location":"trade-object/#get_total_closed_profit","title":"get_total_closed_profit","text":"

    Retrieve the total profit the bot has generated so far. Aggregates close_profit_abs for all closed trades.

    from freqtrade.persistence import Trade\n\n# ...\nprofit = Trade.get_total_closed_profit()\n
    "},{"location":"trade-object/#total_open_trades_stakes","title":"total_open_trades_stakes","text":"

    Retrieve the total stake_amount that's currently in trades.

    from freqtrade.persistence import Trade\n\n# ...\nprofit = Trade.total_open_trades_stakes()\n
    "},{"location":"trade-object/#get_overall_performance","title":"get_overall_performance","text":"

    Retrieve the overall performance - similar to the /performance telegram command.

    from freqtrade.persistence import Trade\n\n# ...\nif self.config['runmode'].value in ('live', 'dry_run'):\n    performance = Trade.get_overall_performance()\n

    Sample return value: ETH/BTC had 5 trades, with a total profit of 1.5% (ratio of 0.015).

    {\"pair\": \"ETH/BTC\", \"profit\": 0.015, \"count\": 5}\n
    "},{"location":"trade-object/#order-object","title":"Order Object","text":"

    An Order object represents an order on the exchange (or a simulated order in dry-run mode). An Order object will always be tied to it's corresponding Trade, and only really makes sense in the context of a trade.

    "},{"location":"trade-object/#order-available-attributes","title":"Order - Available attributes","text":"

    an Order object is typically attached to a trade. Most properties here can be None as they are dependent on the exchange response.

    Attribute DataType Description trade Trade Trade object this order is attached to ft_pair string Pair this order is for ft_is_open boolean is the order filled? order_type string Order type as defined on the exchange - usually market, limit or stoploss status string Status as defined by ccxt. Usually open, closed, expired or canceled side string Buy or Sell price float Price the order was placed at average float Average price the order filled at amount float Amount in base currency filled float Filled amount (in base currency) remaining float Remaining amount cost float Cost of the order - usually average * filled (Exchange dependent on futures, may contain the cost with or without leverage and may be in contracts.) stake_amount float Stake amount used for this order. Added in 2023.7. order_date datetime Order creation date use order_date_utc instead order_date_utc datetime Order creation date (in UTC) order_fill_date datetime Order fill date use order_fill_utc instead order_fill_date_utc datetime Order fill date"},{"location":"updating/","title":"How to update","text":"

    To update your freqtrade installation, please use one of the below methods, corresponding to your installation method.

    Tracking changes

    Breaking changes / changed behavior will be documented in the changelog that is posted alongside every release. For the develop branch, please follow PR's to avoid being surprised by changes.

    "},{"location":"updating/#docker","title":"Docker","text":"

    Legacy installations using the master image

    We're switching from master to stable for the release Images - please adjust your docker-file and replace freqtradeorg/freqtrade:master with freqtradeorg/freqtrade:stable

    docker compose pull\ndocker compose up -d\n
    "},{"location":"updating/#installation-via-setup-script","title":"Installation via setup script","text":"
    ./setup.sh --update\n

    Note

    Make sure to run this command with your virtual environment disabled!

    "},{"location":"updating/#plain-native-installation","title":"Plain native installation","text":"

    Please ensure that you're also updating dependencies - otherwise things might break without you noticing.

    git pull\npip install -U -r requirements.txt\npip install -e .\n\n# Ensure freqUI is at the latest version\nfreqtrade install-ui \n
    "},{"location":"updating/#problems-updating","title":"Problems updating","text":"

    Update-problems usually come missing dependencies (you didn't follow the above instructions) - or from updated dependencies, which fail to install (for example TA-lib). Please refer to the corresponding installation sections (common problems linked below)

    Common problems and their solutions:

    • ta-lib update on windows
    "},{"location":"utils/","title":"Utility Subcommands","text":"

    Besides the Live-Trade and Dry-Run run modes, the backtesting, edge and hyperopt optimization subcommands, and the download-data subcommand which prepares historical data, the bot contains a number of utility subcommands. They are described in this section.

    "},{"location":"utils/#create-userdir","title":"Create userdir","text":"

    Creates the directory structure to hold your files for freqtrade. Will also create strategy and hyperopt examples for you to get started. Can be used multiple times - using --reset will reset the sample strategy and hyperopt files to their default state.

    usage: freqtrade create-userdir [-h] [--userdir PATH] [--reset]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  --reset               Reset sample files to their original state.\n

    Warning

    Using --reset may result in loss of data, since this will overwrite all sample files without asking again.

    \u251c\u2500\u2500 backtest_results\n\u251c\u2500\u2500 data\n\u251c\u2500\u2500 hyperopt_results\n\u251c\u2500\u2500 hyperopts\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 sample_hyperopt_loss.py\n\u251c\u2500\u2500 notebooks\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 strategy_analysis_example.ipynb\n\u251c\u2500\u2500 plot\n\u2514\u2500\u2500 strategies\n    \u2514\u2500\u2500 sample_strategy.py\n
    "},{"location":"utils/#create-new-config","title":"Create new config","text":"

    Creates a new configuration file, asking some questions which are important selections for a configuration.

    usage: freqtrade new-config [-h] [-c PATH]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default: `config.json`). Multiple --config options may be used. Can be set to `-`\n                        to read config from stdin.\n

    Warning

    Only vital questions are asked. Freqtrade offers a lot more configuration possibilities, which are listed in the Configuration documentation

    "},{"location":"utils/#create-config-examples","title":"Create config examples","text":"
    $ freqtrade new-config --config user_data/config_binance.json\n\n? Do you want to enable Dry-run (simulated trades)?  Yes\n? Please insert your stake currency: BTC\n? Please insert your stake amount: 0.05\n? Please insert max_open_trades (Integer or -1 for unlimited open trades): 3\n? Please insert your desired timeframe (e.g. 5m): 5m\n? Please insert your display Currency (for reporting): USD\n? Select exchange  binance\n? Do you want to enable Telegram?  No\n
    "},{"location":"utils/#show-config","title":"Show config","text":"

    Show configuration file (with sensitive values redacted by default). Especially useful with split configuration files or environment variables, where this command will show the merged configuration.

    usage: freqtrade show-config [-h] [--userdir PATH] [-c PATH]\n                             [--show-sensitive]\n\noptions:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  --show-sensitive      Show secrets in the output.\n
    Your combined configuration is:\n{\n  \"exit_pricing\": {\n    \"price_side\": \"other\",\n    \"use_order_book\": true,\n    \"order_book_top\": 1\n  },\n  \"stake_currency\": \"USDT\",\n  \"exchange\": {\n    \"name\": \"binance\",\n    \"key\": \"REDACTED\",\n    \"secret\": \"REDACTED\",\n    \"ccxt_config\": {},\n    \"ccxt_async_config\": {},\n  }\n  // ...\n}\n

    Sharing information provided by this command

    We try to remove all known sensitive information from the default output (without --show-sensitive). Yet, please do double-check for sensitive values in your output to make sure you're not accidentally exposing some private info.

    "},{"location":"utils/#create-new-strategy","title":"Create new strategy","text":"

    Creates a new strategy from a template similar to SampleStrategy. The file will be named inline with your class name, and will not overwrite existing files.

    Results will be located in user_data/strategies/<strategyclassname>.py.

    usage: freqtrade new-strategy [-h] [--userdir PATH] [-s NAME]\n                              [--template {full,minimal,advanced}]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --template {full,minimal,advanced}\n                        Use a template which is either `minimal`, `full`\n                        (containing multiple sample indicators) or `advanced`.\n                        Default: `full`.\n
    "},{"location":"utils/#sample-usage-of-new-strategy","title":"Sample usage of new-strategy","text":"
    freqtrade new-strategy --strategy AwesomeStrategy\n

    With custom user directory

    freqtrade new-strategy --userdir ~/.freqtrade/ --strategy AwesomeStrategy\n

    Using the advanced template (populates all optional functions and methods)

    freqtrade new-strategy --strategy AwesomeStrategy --template advanced\n
    "},{"location":"utils/#list-strategies","title":"List Strategies","text":"

    Use the list-strategies subcommand to see all strategies in one particular directory.

    This subcommand is useful for finding problems in your environment with loading strategies: modules with strategies that contain errors and failed to load are printed in red (LOAD FAILED), while strategies with duplicate names are printed in yellow (DUPLICATE NAME).

    usage: freqtrade list-strategies [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                 [-d PATH] [--userdir PATH]\n                                 [--strategy-path PATH] [-1] [--no-color]\n                                 [--recursive-strategy-search]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --strategy-path PATH  Specify additional strategy lookup path.\n  -1, --one-column      Print output in one column.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n  --recursive-strategy-search\n                        Recursively search for a strategy in the strategies\n                        folder.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Warning

    Using these commands will try to load all python files from a directory. This can be a security risk if untrusted files reside in this directory, since all module-level code is executed.

    Example: Search default strategies directories (within the default userdir).

    freqtrade list-strategies\n

    Example: Search strategies directory within the userdir.

    freqtrade list-strategies --userdir ~/.freqtrade/\n

    Example: Search dedicated strategy path.

    freqtrade list-strategies --strategy-path ~/.freqtrade/strategies/\n
    "},{"location":"utils/#list-freqai-models","title":"List freqAI models","text":"

    Use the list-freqaimodels subcommand to see all freqAI models available.

    This subcommand is useful for finding problems in your environment with loading freqAI models: modules with models that contain errors and failed to load are printed in red (LOAD FAILED), while models with duplicate names are printed in yellow (DUPLICATE NAME).

    usage: freqtrade list-freqaimodels [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                   [-d PATH] [--userdir PATH]\n                                   [--freqaimodel-path PATH] [-1] [--no-color]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --freqaimodel-path PATH\n                        Specify additional lookup path for freqaimodels.\n  -1, --one-column      Print output in one column.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#list-exchanges","title":"List Exchanges","text":"

    Use the list-exchanges subcommand to see the exchanges available for the bot.

    usage: freqtrade list-exchanges [-h] [-1] [-a]\n\noptional arguments:\n  -h, --help        show this help message and exit\n  -1, --one-column  Print output in one column.\n  -a, --all         Print all exchanges known to the ccxt library.\n

    Example: see exchanges available for the bot:

    $ freqtrade list-exchanges\nExchanges available for Freqtrade:\nExchange name       Supported    Markets                 Reason\n------------------  -----------  ----------------------  ------------------------------------------------------------------------\nbinance             Official     spot, isolated futures\nbitmart             Official     spot\nbybit                            spot, isolated futures\ngate                Official     spot, isolated futures\nhtx                 Official     spot\nhuobi                            spot\nkraken              Official     spot\nokx                 Official     spot, isolated futures\n

    Output reduced for clarity - supported and available exchanges may change over time.

    missing opt exchanges

    Values with \"missing opt:\" might need special configuration (e.g. using orderbook if fetchTickers is missing) - but should in theory work (although we cannot guarantee they will).

    Example: see all exchanges supported by the ccxt library (including 'bad' ones, i.e. those that are known to not work with Freqtrade)

    $ freqtrade list-exchanges -a\nAll exchanges supported by the ccxt library:\nExchange name       Valid    Supported    Markets                 Reason\n------------------  -------  -----------  ----------------------  ---------------------------------------------------------------------------------\nbinance             True     Official     spot, isolated futures\nbitflyer            False                 spot                    missing: fetchOrder. missing opt: fetchTickers.\nbitmart             True     Official     spot\nbybit               True                  spot, isolated futures\ngate                True     Official     spot, isolated futures\nhtx                 True     Official     spot\nkraken              True     Official     spot\nokx                 True     Official     spot, isolated futures\n

    Reduced output - supported and available exchanges may change over time.

    "},{"location":"utils/#list-timeframes","title":"List Timeframes","text":"

    Use the list-timeframes subcommand to see the list of timeframes available for the exchange.

    usage: freqtrade list-timeframes [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                 [-d PATH] [--userdir PATH]\n                                 [--exchange EXCHANGE] [-1]\n\noptions:\n  -h, --help            show this help message and exit\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  -1, --one-column      Print output in one column.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    • Example: see the timeframes for the 'binance' exchange, set in the configuration file:
    $ freqtrade list-timeframes -c config_binance.json\n...\nTimeframes available for the exchange `binance`: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M\n
    • Example: enumerate exchanges available for Freqtrade and print timeframes supported by each of them:
      $ for i in `freqtrade list-exchanges -1`; do freqtrade list-timeframes --exchange $i; done\n
    "},{"location":"utils/#list-pairslist-markets","title":"List pairs/list markets","text":"

    The list-pairs and list-markets subcommands allow to see the pairs/markets available on exchange.

    Pairs are markets with the '/' character between the base currency part and the quote currency part in the market symbol. For example, in the 'ETH/BTC' pair 'ETH' is the base currency, while 'BTC' is the quote currency.

    For pairs traded by Freqtrade the pair quote currency is defined by the value of the stake_currency configuration setting.

    You can print info about any pair/market with these subcommands - and you can filter output by quote-currency using --quote BTC, or by base-currency using --base ETH options correspondingly.

    These subcommands have same usage and same set of available options:

    usage: freqtrade list-markets [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                              [-d PATH] [--userdir PATH] [--exchange EXCHANGE]\n                              [--print-list] [--print-json] [-1] [--print-csv]\n                              [--base BASE_CURRENCY [BASE_CURRENCY ...]]\n                              [--quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]]\n                              [-a] [--trading-mode {spot,margin,futures}]\nusage: freqtrade list-pairs [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                            [-d PATH] [--userdir PATH] [--exchange EXCHANGE]\n                            [--print-list] [--print-json] [-1] [--print-csv]\n                            [--base BASE_CURRENCY [BASE_CURRENCY ...]]\n                            [--quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]] [-a]\n                            [--trading-mode {spot,margin,futures}]\noptions:\n  -h, --help            show this help message and exit\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  --print-list          Print list of pairs or market symbols. By default data\n                        is printed in the tabular format.\n  --print-json          Print list of pairs or market symbols in JSON format.\n  -1, --one-column      Print output in one column.\n  --print-csv           Print exchange pair or market data in the csv format.\n  --base BASE_CURRENCY [BASE_CURRENCY ...]\n                        Specify base currency(-ies). Space-separated list.\n  --quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]\n                        Specify quote currency(-ies). Space-separated list.\n  -a, --all             Print all pairs or market symbols. By default only\n                        active ones are shown.\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    By default, only active pairs/markets are shown. Active pairs/markets are those that can currently be traded on the exchange. You can use the -a/-all option to see the list of all pairs/markets, including the inactive ones. Pairs may be listed as untradeable if the smallest tradeable price for the market is very small, i.e. less than 1e-11 (0.00000000001)

    Pairs/markets are sorted by its symbol string in the printed output.

    "},{"location":"utils/#examples","title":"Examples","text":"
    • Print the list of active pairs with quote currency USD on exchange, specified in the default configuration file (i.e. pairs on the \"Binance\" exchange) in JSON format:
    $ freqtrade list-pairs --quote USD --print-json\n
    • Print the list of all pairs on the exchange, specified in the config_binance.json configuration file (i.e. on the \"Binance\" exchange) with base currencies BTC or ETH and quote currencies USDT or USD, as the human-readable list with summary:
    $ freqtrade list-pairs -c config_binance.json --all --base BTC ETH --quote USDT USD --print-list\n
    • Print all markets on exchange \"Kraken\", in the tabular format:
    $ freqtrade list-markets --exchange kraken --all\n
    "},{"location":"utils/#test-pairlist","title":"Test pairlist","text":"

    Use the test-pairlist subcommand to test the configuration of dynamic pairlists.

    Requires a configuration with specified pairlists attribute. Can be used to generate static pairlists to be used during backtesting / hyperopt.

    usage: freqtrade test-pairlist [-h] [--userdir PATH] [-v] [-c PATH]\n                               [--quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]]\n                               [-1] [--print-json] [--exchange EXCHANGE]\n\noptions:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  --quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]\n                        Specify quote currency(-ies). Space-separated list.\n  -1, --one-column      Print output in one column.\n  --print-json          Print list of pairs or market symbols in JSON format.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n
    "},{"location":"utils/#examples_1","title":"Examples","text":"

    Show whitelist when using a dynamic pairlist.

    freqtrade test-pairlist --config config.json --quote USDT BTC\n
    "},{"location":"utils/#convert-database","title":"Convert database","text":"

    freqtrade convert-db can be used to convert your database from one system to another (sqlite -> postgres, postgres -> other postgres), migrating all trades, orders and Pairlocks.

    Please refer to the corresponding documentation to learn about requirements for different database systems.

    usage: freqtrade convert-db [-h] [--db-url PATH] [--db-url-from PATH]\n\noptional arguments:\n  -h, --help          show this help message and exit\n  --db-url PATH       Override trades database URL, this is useful in custom\n                      deployments (default: `sqlite:///tradesv3.sqlite` for\n                      Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                      Dry Run).\n  --db-url-from PATH  Source db url to use when migrating a database.\n

    Warning

    Please ensure to only use this on an empty target database. Freqtrade will perform a regular migration, but may fail if entries already existed.

    "},{"location":"utils/#webserver-mode","title":"Webserver mode","text":"

    Experimental

    Webserver mode is an experimental mode to increase backesting and strategy development productivity. There may still be bugs - so if you happen to stumble across these, please report them as github issues, thanks.

    Run freqtrade in webserver mode. Freqtrade will start the webserver and allow FreqUI to start and control backtesting processes. This has the advantage that data will not be reloaded between backtesting runs (as long as timeframe and timerange remain identical). FreqUI will also show the backtesting results.

    usage: freqtrade webserver [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                           [--userdir PATH]\n\noptional arguments:\n  -h, --help            show this help message and exit\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#webserver-mode-docker","title":"Webserver mode - docker","text":"

    You can also use webserver mode via docker. Starting a one-off container requires the configuration of the port explicitly, as ports are not exposed by default. You can use docker compose run --rm -p 127.0.0.1:8080:8080 freqtrade webserver to start a one-off container that'll be removed once you stop it. This assumes that port 8080 is still available and no other bot is running on that port.

    Alternatively, you can reconfigure the docker-compose file to have the command updated:

        command: >\n      webserver\n      --config /freqtrade/user_data/config.json\n

    You can now use docker compose up to start the webserver. This assumes that the configuration has a webserver enabled and configured for docker (listening port = 0.0.0.0).

    Tip

    Don't forget to reset the command back to the trade command if you want to start a live or dry-run bot.

    "},{"location":"utils/#show-previous-backtest-results","title":"Show previous Backtest results","text":"

    Allows you to show previous backtest results. Adding --show-pair-list outputs a sorted pair list you can easily copy/paste into your configuration (omitting bad pairs).

    Strategy overfitting

    Only using winning pairs can lead to an overfitted strategy, which will not work well on future data. Make sure to extensively test your strategy in dry-run before risking real money.

    usage: freqtrade backtesting-show [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                  [-d PATH] [--userdir PATH]\n                                  [--export-filename PATH] [--show-pair-list]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --export-filename PATH\n                        Save backtest results to the file with this filename.\n                        Requires `--export` to be set as well. Example:\n                        `--export-filename=user_data/backtest_results/backtest\n                        _today.json`\n  --show-pair-list      Show backtesting pairlist sorted by profit.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#detailed-backtest-analysis","title":"Detailed backtest analysis","text":"

    Advanced backtest result analysis.

    More details in the Backtesting analysis Section.

    usage: freqtrade backtesting-analysis [-h] [-v] [--logfile FILE] [-V]\n                                      [-c PATH] [-d PATH] [--userdir PATH]\n                                      [--export-filename PATH]\n                                      [--analysis-groups {0,1,2,3,4} [{0,1,2,3,4} ...]]\n                                      [--enter-reason-list ENTER_REASON_LIST [ENTER_REASON_LIST ...]]\n                                      [--exit-reason-list EXIT_REASON_LIST [EXIT_REASON_LIST ...]]\n                                      [--indicator-list INDICATOR_LIST [INDICATOR_LIST ...]]\n                                      [--timerange YYYYMMDD-[YYYYMMDD]]\n                                      [--rejected]\n                                      [--analysis-to-csv]\n                                      [--analysis-csv-path PATH]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --export-filename PATH, --backtest-filename PATH\n                        Use this filename for backtest results.Requires\n                        `--export` to be set as well. Example: `--export-filen\n                        ame=user_data/backtest_results/backtest_today.json`\n  --analysis-groups {0,1,2,3,4} [{0,1,2,3,4} ...]\n                        grouping output - 0: simple wins/losses by enter tag,\n                        1: by enter_tag, 2: by enter_tag and exit_tag, 3: by\n                        pair and enter_tag, 4: by pair, enter_ and exit_tag\n                        (this can get quite large)\n  --enter-reason-list ENTER_REASON_LIST [ENTER_REASON_LIST ...]\n                        Space separated list of entry signals to analyse.\n                        Default: all. e.g. 'entry_tag_a entry_tag_b'\n  --exit-reason-list EXIT_REASON_LIST [EXIT_REASON_LIST ...]\n                        Space separated list of exit signals to analyse.\n                        Default: all. e.g.\n                        'exit_tag_a roi stop_loss trailing_stop_loss'\n  --indicator-list INDICATOR_LIST [INDICATOR_LIST ...]\n                        Space separated list of indicators to analyse. e.g.\n                        'close rsi bb_lowerband profit_abs'\n  --timerange YYYYMMDD-[YYYYMMDD]\n                        Timerange to filter trades for analysis, \n                        start inclusive, end exclusive. e.g.\n                        20220101-20220201\n  --rejected\n                        Print out rejected trades table\n  --analysis-to-csv\n                        Write out tables to individual CSVs, by default to \n                        'user_data/backtest_results' unless '--analysis-csv-path' is given.\n  --analysis-csv-path [PATH]\n                        Optional path where individual CSVs will be written. If not used,\n                        CSVs will be written to 'user_data/backtest_results'.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#list-hyperopt-results","title":"List Hyperopt results","text":"

    You can list the hyperoptimization epochs the Hyperopt module evaluated previously with the hyperopt-list sub-command.

    usage: freqtrade hyperopt-list [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                               [-d PATH] [--userdir PATH] [--best]\n                               [--profitable] [--min-trades INT]\n                               [--max-trades INT] [--min-avg-time FLOAT]\n                               [--max-avg-time FLOAT] [--min-avg-profit FLOAT]\n                               [--max-avg-profit FLOAT]\n                               [--min-total-profit FLOAT]\n                               [--max-total-profit FLOAT]\n                               [--min-objective FLOAT] [--max-objective FLOAT]\n                               [--no-color] [--print-json] [--no-details]\n                               [--hyperopt-filename PATH] [--export-csv FILE]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --best                Select only best epochs.\n  --profitable          Select only profitable epochs.\n  --min-trades INT      Select epochs with more than INT trades.\n  --max-trades INT      Select epochs with less than INT trades.\n  --min-avg-time FLOAT  Select epochs above average time.\n  --max-avg-time FLOAT  Select epochs below average time.\n  --min-avg-profit FLOAT\n                        Select epochs above average profit.\n  --max-avg-profit FLOAT\n                        Select epochs below average profit.\n  --min-total-profit FLOAT\n                        Select epochs above total profit.\n  --max-total-profit FLOAT\n                        Select epochs below total profit.\n  --min-objective FLOAT\n                        Select epochs above objective.\n  --max-objective FLOAT\n                        Select epochs below objective.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n  --print-json          Print output in JSON format.\n  --no-details          Do not print best epoch details.\n  --hyperopt-filename FILENAME\n                        Hyperopt result filename.Example: `--hyperopt-\n                        filename=hyperopt_results_2020-09-27_16-20-48.pickle`\n  --export-csv FILE     Export to CSV-File. This will disable table print.\n                        Example: --export-csv hyperopt.csv\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Note

    hyperopt-list will automatically use the latest available hyperopt results file. You can override this using the --hyperopt-filename argument, and specify another, available filename (without path!).

    "},{"location":"utils/#examples_2","title":"Examples","text":"

    List all results, print details of the best result at the end:

    freqtrade hyperopt-list\n

    List only epochs with positive profit. Do not print the details of the best epoch, so that the list can be iterated in a script:

    freqtrade hyperopt-list --profitable --no-details\n

    "},{"location":"utils/#show-details-of-hyperopt-results","title":"Show details of Hyperopt results","text":"

    You can show the details of any hyperoptimization epoch previously evaluated by the Hyperopt module with the hyperopt-show subcommand.

    usage: freqtrade hyperopt-show [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                               [-d PATH] [--userdir PATH] [--best]\n                               [--profitable] [-n INT] [--print-json]\n                               [--hyperopt-filename FILENAME] [--no-header]\n                               [--disable-param-export]\n                               [--breakdown {day,week,month} [{day,week,month} ...]]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --best                Select only best epochs.\n  --profitable          Select only profitable epochs.\n  -n INT, --index INT   Specify the index of the epoch to print details for.\n  --print-json          Print output in JSON format.\n  --hyperopt-filename FILENAME\n                        Hyperopt result filename.Example: `--hyperopt-\n                        filename=hyperopt_results_2020-09-27_16-20-48.pickle`\n  --no-header           Do not print epoch details header.\n  --disable-param-export\n                        Disable automatic hyperopt parameter export.\n  --breakdown {day,week,month} [{day,week,month} ...]\n                        Show backtesting breakdown per [day, week, month].\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Note

    hyperopt-show will automatically use the latest available hyperopt results file. You can override this using the --hyperopt-filename argument, and specify another, available filename (without path!).

    "},{"location":"utils/#examples_3","title":"Examples","text":"

    Print details for the epoch 168 (the number of the epoch is shown by the hyperopt-list subcommand or by Hyperopt itself during hyperoptimization run):

    freqtrade hyperopt-show -n 168\n

    Prints JSON data with details for the last best epoch (i.e., the best of all epochs):

    freqtrade hyperopt-show --best -n -1 --print-json --no-header\n
    "},{"location":"utils/#show-trades","title":"Show trades","text":"

    Print selected (or all) trades from database to screen.

    usage: freqtrade show-trades [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                             [-d PATH] [--userdir PATH] [--db-url PATH]\n                             [--trade-ids TRADE_IDS [TRADE_IDS ...]]\n                             [--print-json]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --trade-ids TRADE_IDS [TRADE_IDS ...]\n                        Specify the list of trade ids.\n  --print-json          Print output in JSON format.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#examples_4","title":"Examples","text":"

    Print trades with id 2 and 3 as json

    freqtrade show-trades --db-url sqlite:///tradesv3.sqlite --trade-ids 2 3 --print-json\n
    "},{"location":"utils/#strategy-updater","title":"Strategy-Updater","text":"

    Updates listed strategies or all strategies within the strategies folder to be v3 compliant. If the command runs without --strategy-list then all strategies inside the strategies folder will be converted. Your original strategy will remain available in the user_data/strategies_orig_updater/ directory.

    Conversion results

    Strategy updater will work on a \"best effort\" approach. Please do your due diligence and verify the results of the conversion. We also recommend to run a python formatter (e.g. black) to format results in a sane manner.

    usage: freqtrade strategy-updater [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                  [-d PATH] [--userdir PATH]\n                                  [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]\n\noptions:\n  -h, --help            show this help message and exit\n  --strategy-list STRATEGY_LIST [STRATEGY_LIST ...]\n                        Provide a space-separated list of strategies to\n                        be converted.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"webhook-config/","title":"Webhook usage","text":""},{"location":"webhook-config/#configuration","title":"Configuration","text":"

    Enable webhooks by adding a webhook-section to your configuration file, and setting webhook.enabled to true.

    Sample configuration (tested using IFTTT).

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://maker.ifttt.com/trigger/<YOUREVENT>/with/key/<YOURKEY>/\",\n        \"entry\": {\n            \"value1\": \"Buying {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"{stake_amount:8f} {stake_currency}\"\n        },\n        \"entry_cancel\": {\n            \"value1\": \"Cancelling Open Buy Order for {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"{stake_amount:8f} {stake_currency}\"\n        },\n         \"entry_fill\": {\n            \"value1\": \"Buy Order for {pair} filled\",\n            \"value2\": \"at {open_rate:8f}\",\n            \"value3\": \"\"\n        },\n        \"exit\": {\n            \"value1\": \"Exiting {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"profit: {profit_amount:8f} {stake_currency} ({profit_ratio})\"\n        },\n        \"exit_cancel\": {\n            \"value1\": \"Cancelling Open Exit Order for {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"profit: {profit_amount:8f} {stake_currency} ({profit_ratio})\"\n        },\n        \"exit_fill\": {\n            \"value1\": \"Exit Order for {pair} filled\",\n            \"value2\": \"at {close_rate:8f}.\",\n            \"value3\": \"\"\n        },\n        \"status\": {\n            \"value1\": \"Status: {status}\",\n            \"value2\": \"\",\n            \"value3\": \"\"\n        }\n    },\n

    The url in webhook.url should point to the correct url for your webhook. If you're using IFTTT (as shown in the sample above) please insert your event and key to the url.

    You can set the POST body format to Form-Encoded (default), JSON-Encoded, or raw data. Use \"format\": \"form\", \"format\": \"json\", or \"format\": \"raw\" respectively. Example configuration for Mattermost Cloud integration:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURSUBDOMAIN>.cloud.mattermost.com/hooks/<YOURHOOK>\",\n        \"format\": \"json\",\n        \"status\": {\n            \"text\": \"Status: {status}\"\n        }\n    },\n

    The result would be a POST request with e.g. {\"text\":\"Status: running\"} body and Content-Type: application/json header which results Status: running message in the Mattermost channel.

    When using the Form-Encoded or JSON-Encoded configuration you can configure any number of payload values, and both the key and value will be output in the POST request. However, when using the raw data format you can only configure one value and it must be named \"data\". In this instance the data key will not be output in the POST request, only the value. For example:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURHOOKURL>\",\n        \"format\": \"raw\",\n        \"webhookstatus\": {\n            \"data\": \"Status: {status}\"\n        }\n    },\n

    The result would be a POST request with e.g. Status: running body and Content-Type: text/plain header.

    "},{"location":"webhook-config/#additional-configurations","title":"Additional configurations","text":"

    The webhook.retries parameter can be set for the maximum number of retries the webhook request should attempt if it is unsuccessful (i.e. HTTP response status is not 200). By default this is set to 0 which is disabled. An additional webhook.retry_delay parameter can be set to specify the time in seconds between retry attempts. By default this is set to 0.1 (i.e. 100ms). Note that increasing the number of retries or retry delay may slow down the trader if there are connectivity issues with the webhook. You can also specify webhook.timeout - which defines how long the bot will wait until it assumes the other host as unresponsive (defaults to 10s).

    Example configuration for retries:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURHOOKURL>\",\n        \"timeout\": 10,\n        \"retries\": 3,\n        \"retry_delay\": 0.2,\n        \"status\": {\n            \"status\": \"Status: {status}\"\n        }\n    },\n

    Custom messages can be sent to Webhook endpoints via the self.dp.send_msg() function from within the strategy. To enable this, set the allow_custom_messages option to true:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURHOOKURL>\",\n        \"allow_custom_messages\": true,\n        \"strategy_msg\": {\n            \"status\": \"StrategyMessage: {msg}\"\n        }\n    },\n

    Different payloads can be configured for different events. Not all fields are necessary, but you should configure at least one of the dicts, otherwise the webhook will never be called.

    "},{"location":"webhook-config/#webhook-message-types","title":"Webhook Message types","text":""},{"location":"webhook-config/#entry","title":"Entry","text":"

    The fields in webhook.entry are filled when the bot executes a long/short. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • limit # Deprecated - should no longer be used.
    • open_rate
    • amount
    • open_date
    • stake_amount
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • order_type
    • current_rate
    • enter_tag
    "},{"location":"webhook-config/#entry-cancel","title":"Entry cancel","text":"

    The fields in webhook.entry_cancel are filled when the bot cancels a long/short order. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • limit
    • amount
    • open_date
    • stake_amount
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • order_type
    • current_rate
    • enter_tag
    "},{"location":"webhook-config/#entry-fill","title":"Entry fill","text":"

    The fields in webhook.entry_fill are filled when the bot filled a long/short order. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • open_rate
    • amount
    • open_date
    • stake_amount
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • order_type
    • current_rate
    • enter_tag
    "},{"location":"webhook-config/#exit","title":"Exit","text":"

    The fields in webhook.exit are filled when the bot exits a trade. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • gain
    • limit
    • amount
    • open_rate
    • profit_amount
    • profit_ratio
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • exit_reason
    • order_type
    • open_date
    • close_date
    "},{"location":"webhook-config/#exit-fill","title":"Exit fill","text":"

    The fields in webhook.exit_fill are filled when the bot fills a exit order (closes a Trade). Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • gain
    • close_rate
    • amount
    • open_rate
    • current_rate
    • profit_amount
    • profit_ratio
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • exit_reason
    • order_type
    • open_date
    • close_date
    "},{"location":"webhook-config/#exit-cancel","title":"Exit cancel","text":"

    The fields in webhook.exit_cancel are filled when the bot cancels a exit order. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • gain
    • limit
    • amount
    • open_rate
    • current_rate
    • profit_amount
    • profit_ratio
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • exit_reason
    • order_type
    • open_date
    • close_date
    "},{"location":"webhook-config/#status","title":"Status","text":"

    The fields in webhook.status are used for regular status messages (Started / Stopped / ...). Parameters are filled using string.format.

    The only possible value here is {status}.

    "},{"location":"webhook-config/#discord","title":"Discord","text":"

    A special form of webhooks is available for discord. You can configure this as follows:

    \"discord\": {\n    \"enabled\": true,\n    \"webhook_url\": \"https://discord.com/api/webhooks/<Your webhook URL ...>\",\n    \"exit_fill\": [\n        {\"Trade ID\": \"{trade_id}\"},\n        {\"Exchange\": \"{exchange}\"},\n        {\"Pair\": \"{pair}\"},\n        {\"Direction\": \"{direction}\"},\n        {\"Open rate\": \"{open_rate}\"},\n        {\"Close rate\": \"{close_rate}\"},\n        {\"Amount\": \"{amount}\"},\n        {\"Open date\": \"{open_date:%Y-%m-%d %H:%M:%S}\"},\n        {\"Close date\": \"{close_date:%Y-%m-%d %H:%M:%S}\"},\n        {\"Profit\": \"{profit_amount} {stake_currency}\"},\n        {\"Profitability\": \"{profit_ratio:.2%}\"},\n        {\"Enter tag\": \"{enter_tag}\"},\n        {\"Exit Reason\": \"{exit_reason}\"},\n        {\"Strategy\": \"{strategy}\"},\n        {\"Timeframe\": \"{timeframe}\"},\n    ],\n    \"entry_fill\": [\n        {\"Trade ID\": \"{trade_id}\"},\n        {\"Exchange\": \"{exchange}\"},\n        {\"Pair\": \"{pair}\"},\n        {\"Direction\": \"{direction}\"},\n        {\"Open rate\": \"{open_rate}\"},\n        {\"Amount\": \"{amount}\"},\n        {\"Open date\": \"{open_date:%Y-%m-%d %H:%M:%S}\"},\n        {\"Enter tag\": \"{enter_tag}\"},\n        {\"Strategy\": \"{strategy} {timeframe}\"},\n    ]\n}\n

    The above represents the default (exit_fill and entry_fill are optional and will default to the above configuration) - modifications are obviously possible. To disable either of the two default values (entry_fill / exit_fill), you can assign them an empty array (exit_fill: []).

    Available fields correspond to the fields for webhooks and are documented in the corresponding webhook sections.

    The notifications will look as follows by default.

    Custom messages can be sent from a strategy to Discord endpoints via the dataprovider.send_msg() function. To enable this, set the allow_custom_messages option to true:

      \"discord\": {\n        \"enabled\": true,\n        \"webhook_url\": \"https://discord.com/api/webhooks/<Your webhook URL ...>\",\n        \"allow_custom_messages\": true,\n    },\n
    "},{"location":"windows_installation/","title":"Windows installation","text":"

    We strongly recommend that Windows users use Docker as this will work much easier and smoother (also more secure).

    If that is not possible, try using the Windows Linux subsystem (WSL) - for which the Ubuntu instructions should work. Otherwise, please follow the instructions below.

    All instructions assume that python 3.9+ is installed and available.

    "},{"location":"windows_installation/#clone-the-git-repository","title":"Clone the git repository","text":"

    First of all clone the repository by running:

    git clone https://github.com/freqtrade/freqtrade.git\n

    Now, choose your installation method, either automatically via script (recommended) or manually following the corresponding instructions.

    "},{"location":"windows_installation/#install-freqtrade-automatically","title":"Install freqtrade automatically","text":""},{"location":"windows_installation/#run-the-installation-script","title":"Run the installation script","text":"

    The script will ask you a few questions to determine which parts should be installed.

    Set-ExecutionPolicy -ExecutionPolicy Bypass\ncd freqtrade\n. .\\setup.ps1\n
    "},{"location":"windows_installation/#install-freqtrade-manually","title":"Install freqtrade manually","text":"

    64bit Python version

    Please make sure to use 64bit Windows and 64bit Python to avoid problems with backtesting or hyperopt due to the memory constraints 32bit applications have under Windows. 32bit python versions are no longer supported under Windows.

    Hint

    Using the Anaconda Distribution under Windows can greatly help with installation problems. Check out the Anaconda installation section in the documentation for more information.

    "},{"location":"windows_installation/#install-ta-lib","title":"Install ta-lib","text":"

    Install ta-lib according to the ta-lib documentation.

    As compiling from source on windows has heavy dependencies (requires a partial visual studio installation), Freqtrade provides these dependencies (in the binary wheel format) for the latest 3 Python versions (3.9, 3.10, 3.11 and 3.12) and for 64bit Windows. These Wheels are also used by CI running on windows, and are therefore tested together with freqtrade.

    Other versions must be downloaded from the above link.

    cd \\path\\freqtrade\npython -m venv .venv\n.venv\\Scripts\\activate.ps1\n# optionally install ta-lib from wheel\n# Eventually adjust the below filename to match the downloaded wheel\npip install --find-links build_helpers\\ TA-Lib -U\npip install -r requirements.txt\npip install -e .\nfreqtrade\n

    Use Powershell

    The above installation script assumes you're using powershell on a 64bit windows. Commands for the legacy CMD windows console may differ.

    "},{"location":"windows_installation/#error-during-installation-on-windows","title":"Error during installation on Windows","text":"
    error: Microsoft Visual C++ 14.0 is required. Get it with \"Microsoft Visual C++ Build Tools\": http://landinghub.visualstudio.com/visual-cpp-build-tools\n

    Unfortunately, many packages requiring compilation don't provide a pre-built wheel. It is therefore mandatory to have a C/C++ compiler installed and available for your python environment to use.

    You can download the Visual C++ build tools from here and install \"Desktop development with C++\" in it's default configuration. Unfortunately, this is a heavy download / dependency so you might want to consider WSL2 or docker compose first.

    "},{"location":"includes/cors/","title":"Cors","text":""},{"location":"includes/cors/#cors","title":"CORS","text":"

    This whole section is only necessary in cross-origin cases (where you multiple bot API's running on localhost:8081, localhost:8082, ...), and want to combine them into one FreqUI instance.

    Technical explanation

    All web-based front-ends are subject to CORS - Cross-Origin Resource Sharing. Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems. Also, the standard disallows * CORS policies for requests with credentials, so this setting must be set appropriately.

    Users can allow access from different origin URL's to the bot API via the CORS_origins configuration setting. It consists of a list of allowed URL's that are allowed to consume resources from the bot's API.

    Assuming your application is deployed as https://frequi.freqtrade.io/home/ - this would mean that the following configuration becomes necessary:

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"https://frequi.freqtrade.io\"],\n    //...\n}\n

    In the following (pretty common) case, FreqUI is accessible on http://localhost:8080/trade (this is what you see in your navbar when navigating to freqUI).

    The correct configuration for this case is http://localhost:8080 - the main part of the URL including the port.

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"http://localhost:8080\"],\n    //...\n}\n

    trailing Slash

    The trailing slash is not allowed in the CORS_origins configuration (e.g. \"http://localhots:8080/\"). Such a configuration will not take effect, and the cors errors will remain.

    Note

    We strongly recommend to also set jwt_secret_key to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"includes/pairlists/","title":"Pairlists","text":""},{"location":"includes/pairlists/#pairlists-and-pairlist-handlers","title":"Pairlists and Pairlist Handlers","text":"

    Pairlist Handlers define the list of pairs (pairlist) that the bot should trade. They are configured in the pairlists section of the configuration settings.

    In your configuration, you can use Static Pairlist (defined by the StaticPairList Pairlist Handler) and Dynamic Pairlist (defined by the VolumePairList and PercentChangePairList Pairlist Handlers).

    Additionally, AgeFilter, PrecisionFilter, PriceFilter, ShuffleFilter, SpreadFilter and VolatilityFilter act as Pairlist Filters, removing certain pairs and/or moving their positions in the pairlist.

    If multiple Pairlist Handlers are used, they are chained and a combination of all Pairlist Handlers forms the resulting pairlist the bot uses for trading and backtesting. Pairlist Handlers are executed in the sequence they are configured. You can define either StaticPairList, VolumePairList, ProducerPairList, RemotePairList, MarketCapPairList or PercentChangePairList as the starting Pairlist Handler.

    Inactive markets are always removed from the resulting pairlist. Explicitly blacklisted pairs (those in the pair_blacklist configuration setting) are also always removed from the resulting pairlist.

    "},{"location":"includes/pairlists/#pair-blacklist","title":"Pair blacklist","text":"

    The pair blacklist (configured via exchange.pair_blacklist in the configuration) disallows certain pairs from trading. This can be as simple as excluding DOGE/BTC - which will remove exactly this pair.

    The pair-blacklist does also support wildcards (in regex-style) - so BNB/.* will exclude ALL pairs that start with BNB. You may also use something like .*DOWN/BTC or .*UP/BTC to exclude leveraged tokens (check Pair naming conventions for your exchange!)

    "},{"location":"includes/pairlists/#available-pairlist-handlers","title":"Available Pairlist Handlers","text":"
    • StaticPairList (default, if not configured differently)
    • VolumePairList
    • PercentChangePairList
    • ProducerPairList
    • RemotePairList
    • MarketCapPairList
    • AgeFilter
    • FullTradesFilter
    • OffsetFilter
    • PerformanceFilter
    • PrecisionFilter
    • PriceFilter
    • ShuffleFilter
    • SpreadFilter
    • RangeStabilityFilter
    • VolatilityFilter

    Testing pairlists

    Pairlist configurations can be quite tricky to get right. Best use the test-pairlist utility sub-command to test your configuration quickly.

    "},{"location":"includes/pairlists/#static-pair-list","title":"Static Pair List","text":"

    By default, the StaticPairList method is used, which uses a statically defined pair whitelist from the configuration. The pairlist also supports wildcards (in regex-style) - so .*/BTC will include all pairs with BTC as a stake.

    It uses configuration from exchange.pair_whitelist and exchange.pair_blacklist.

    \"pairlists\": [\n    {\"method\": \"StaticPairList\"}\n],\n

    By default, only currently enabled pairs are allowed. To skip pair validation against active markets, set \"allow_inactive\": true within the StaticPairList configuration. This can be useful for backtesting expired pairs (like quarterly spot-markets). This option must be configured along with exchange.skip_pair_validation in the exchange configuration.

    When used in a \"follow-up\" position (e.g. after VolumePairlist), all pairs in 'pair_whitelist' will be added to the end of the pairlist.

    "},{"location":"includes/pairlists/#volume-pair-list","title":"Volume Pair List","text":"

    VolumePairList employs sorting/filtering of pairs by their trading volume. It selects number_assets top pairs with sorting based on the sort_key (which can only be quoteVolume).

    When used in the chain of Pairlist Handlers in a non-leading position (after StaticPairList and other Pairlist Filters), VolumePairList considers outputs of previous Pairlist Handlers, adding its sorting/selection of the pairs by the trading volume.

    When used in the leading position of the chain of Pairlist Handlers, the pair_whitelist configuration setting is ignored. Instead, VolumePairList selects the top assets from all available markets with matching stake-currency on the exchange.

    The refresh_period setting allows to define the period (in seconds), at which the pairlist will be refreshed. Defaults to 1800s (30 minutes). The pairlist cache (refresh_period) on VolumePairList is only applicable to generating pairlists. Filtering instances (not the first position in the list) will not apply any cache (beyond caching candles for the duration of the candle in advanced mode) and will always use up-to-date data.

    VolumePairList is per default based on the ticker data from exchange, as reported by the ccxt library:

    • The quoteVolume is the amount of quote (stake) currency traded (bought or sold) in last 24 hours.
    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"max_value\": 8000000,\n        \"refresh_period\": 1800\n    }\n],\n

    You can define a minimum volume with min_value - which will filter out pairs with a volume lower than the specified value in the specified timerange. In addition to that, you can also define a maximum volume with max_value - which will filter out pairs with a volume higher than the specified value in the specified timerange.

    "},{"location":"includes/pairlists/#volumepairlist-advanced-mode","title":"VolumePairList Advanced mode","text":"

    VolumePairList can also operate in an advanced mode to build volume over a given timerange of specified candle size. It utilizes exchange historical candle data, builds a typical price (calculated by (open+high+low)/3) and multiplies the typical price with every candle's volume. The sum is the quoteVolume over the given range. This allows different scenarios, for a more smoothened volume, when using longer ranges with larger candle sizes, or the opposite when using a short range with small candles.

    For convenience lookback_days can be specified, which will imply that 1d candles will be used for the lookback. In the example below the pairlist would be created based on the last 7 days:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 7\n    }\n],\n

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range based volume can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with VolumeFilter to narrow the pairlist down for further range volume calculation.

    Unsupported exchanges

    On some exchanges (like Gemini), regular VolumePairList does not work as the api does not natively provide 24h volume. This can be worked around by using candle data to build the volume. To roughly simulate 24h volume, you can use the following configuration. Please note that These pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    More sophisticated approach can be used, by using lookback_timeframe for candle size and lookback_period which specifies the amount of candles. This example will build the volume pairs based on a rolling period of 3 days of 1h candles:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    Note

    VolumePairList does not support backtesting mode.

    "},{"location":"includes/pairlists/#percent-change-pair-list","title":"Percent Change Pair List","text":"

    PercentChangePairList filters and sorts pairs based on the percentage change in their price over the last 24 hours or any defined timeframe as part of advanced options. This allows traders to focus on assets that have experienced significant price movements, either positive or negative.

    Configuration Options

    • number_assets: Specifies the number of top pairs to select based on the 24-hour percentage change.
    • min_value: Sets a minimum percentage change threshold. Pairs with a percentage change below this value will be filtered out.
    • max_value: Sets a maximum percentage change threshold. Pairs with a percentage change above this value will be filtered out.
    • sort_direction: Specifies the order in which pairs are sorted based on their percentage change. Accepts two values: asc for ascending order and desc for descending order.
    • refresh_period: Defines the interval (in seconds) at which the pairlist will be refreshed. The default is 1800 seconds (30 minutes).
    • lookback_days: Number of days to look back. When lookback_days is selected, the lookback_timeframe is defaulted to 1 day.
    • lookback_timeframe: Timeframe to use for the lookback period.
    • lookback_period: Number of periods to look back at.

    When PercentChangePairList is used after other Pairlist Handlers, it will operate on the outputs of those handlers. If it is the leading Pairlist Handler, it will select pairs from all available markets with the specified stake currency.

    PercentChangePairList uses ticker data from the exchange, provided via the ccxt library: The percentage change is calculated as the change in price over the last 24 hours.

    Unsupported exchanges

    On some exchanges (like HTX), regular PercentChangePairList does not work as the api does not natively provide 24h percent change in price. This can be worked around by using candle data to calculate the percentage change. To roughly simulate 24h percent change, you can use the following configuration. Please note that these pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 20,\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    Example Configuration to Read from Ticker

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"min_value\": -10,\n        \"max_value\": 50\n    }\n],\n

    In this configuration:

    1. The top 15 pairs are selected based on the highest percentage change in price over the last 24 hours.
    2. Only pairs with a percentage change between -10% and 50% are considered.

    Example Configuration to Read from Candles

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"sort_key\": \"percentage\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    This example builds the percent change pairs based on a rolling period of 3 days of 1-hour candles by using lookback_timeframe for candle size and lookback_period which specifies the number of candles.

    The percent change in price is calculated using the following formula, which expresses the percentage difference between the current candle's close price and the previous candle's close price, as defined by the specified timeframe and lookback period:

    \\[ Percent Change = (\\frac{Current Close - Previous Close}{Previous Close}) * 100 \\]

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range-based percent change can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with PercentChangePairList to narrow the pairlist down for further percent-change calculation.

    Backtesting

    PercentChangePairList does not support backtesting mode.

    "},{"location":"includes/pairlists/#producerpairlist","title":"ProducerPairList","text":"

    With ProducerPairList, you can reuse the pairlist from a Producer without explicitly defining the pairlist on each consumer.

    Consumer mode is required for this pairlist to work.

    The pairlist will perform a check on active pairs against the current exchange configuration to avoid attempting to trade on invalid markets.

    You can limit the length of the pairlist with the optional parameter number_assets. Using \"number_assets\"=0 or omitting this key will result in the reuse of all producer pairs valid for the current setup.

    \"pairlists\": [\n    {\n        \"method\": \"ProducerPairList\",\n        \"number_assets\": 5,\n        \"producer_name\": \"default\",\n    }\n],\n

    Combining pairlists

    This pairlist can be combined with all other pairlists and filters for further pairlist reduction, and can also act as an \"additional\" pairlist, on top of already defined pairs. ProducerPairList can also be used multiple times in sequence, combining the pairs from multiple producers. Obviously in complex such configurations, the Producer may not provide data for all pairs, so the strategy must be fit for this.

    "},{"location":"includes/pairlists/#remotepairlist","title":"RemotePairList","text":"

    It allows the user to fetch a pairlist from a remote server or a locally stored json file within the freqtrade directory, enabling dynamic updates and customization of the trading pairlist.

    The RemotePairList is defined in the pairlists section of the configuration settings. It uses the following configuration options:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"processing_mode\": \"filter\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"bearer_token\": \"my-bearer-token\",\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    The optional mode option specifies if the pairlist should be used as a blacklist or as a whitelist. The default value is \"whitelist\".

    The optional processing_mode option in the RemotePairList configuration determines how the retrieved pairlist is processed. It can have two values: \"filter\" or \"append\". The default value is \"filter\".

    In \"filter\" mode, the retrieved pairlist is used as a filter. Only the pairs present in both the original pairlist and the retrieved pairlist are included in the final pairlist. Other pairs are filtered out.

    In \"append\" mode, the retrieved pairlist is added to the original pairlist. All pairs from both lists are included in the final pairlist without any filtering.

    The pairlist_url option specifies the URL of the remote server where the pairlist is located, or the path to a local file (if file:/// is prepended). This allows the user to use either a remote server or a local file as the source for the pairlist.

    The save_to_file option, when provided with a valid filename, saves the processed pairlist to that file in JSON format. This option is optional, and by default, the pairlist is not saved to a file.

    Multi bot with shared pairlist example

    save_to_file can be used to save the pairlist to a file with Bot1:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    This saved pairlist file can be loaded by Bot2, or any additional bot with this configuration:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"file:///user_data/filename.json\",\n        \"number_assets\": 10,\n        \"refresh_period\": 10,\n        \"keep_pairlist_on_failure\": true,\n    }\n]\n

    The user is responsible for providing a server or local file that returns a JSON object with the following structure:

    {\n    \"pairs\": [\"XRP/USDT\", \"ETH/USDT\", \"LTC/USDT\"],\n    \"refresh_period\": 1800\n}\n

    The pairs property should contain a list of strings with the trading pairs to be used by the bot. The refresh_period property is optional and specifies the number of seconds that the pairlist should be cached before being refreshed.

    The optional keep_pairlist_on_failure specifies whether the previous received pairlist should be used if the remote server is not reachable or returns an error. The default value is true.

    The optional read_timeout specifies the maximum amount of time (in seconds) to wait for a response from the remote source, The default value is 60.

    The optional bearer_token will be included in the requests Authorization Header.

    Note

    In case of a server error the last received pairlist will be kept if keep_pairlist_on_failure is set to true, when set to false a empty pairlist is returned.

    "},{"location":"includes/pairlists/#marketcappairlist","title":"MarketCapPairList","text":"

    MarketCapPairList employs sorting/filtering of pairs by their marketcap rank based of CoinGecko. It will only recognize coins up to the coin placed at rank 250. The returned pairlist will be sorted based of their marketcap ranks.

    \"pairlists\": [\n    {\n        \"method\": \"MarketCapPairList\",\n        \"number_assets\": 20,\n        \"max_rank\": 50,\n        \"refresh_period\": 86400\n    }\n]\n

    number_assets defines the maximum number of pairs returned by the pairlist. max_rank will determine the maximum rank used in creating/filtering the pairlist. It's expected that some coins within the top max_rank marketcap will not be included in the resulting pairlist since not all pairs will have active trading pairs in your preferred market/stake/exchange combination.

    refresh_period setting defines the period (in seconds) at which the marketcap rank data will be refreshed. Defaults to 86,400s (1 day). The pairlist cache (refresh_period) is applicable on both generating pairlists (first position in the list) and filtering instances (not the first position in the list).

    "},{"location":"includes/pairlists/#agefilter","title":"AgeFilter","text":"

    Removes pairs that have been listed on the exchange for less than min_days_listed days (defaults to 10) or more than max_days_listed days (defaults None mean infinity).

    When pairs are first listed on an exchange they can suffer huge price drops and volatility in the first few days while the pair goes through its price-discovery period. Bots can often be caught out buying before the pair has finished dropping in price.

    This filter allows freqtrade to ignore pairs until they have been listed for at least min_days_listed days and listed before max_days_listed.

    "},{"location":"includes/pairlists/#fulltradesfilter","title":"FullTradesFilter","text":"

    Shrink whitelist to consist only in-trade pairs when the trade slots are full (when max_open_trades isn't being set to -1 in the config).

    When the trade slots are full, there is no need to calculate indicators of the rest of the pairs (except informative pairs) since no new trade can be opened. By shrinking the whitelist to just the in-trade pairs, you can improve calculation speeds and reduce CPU usage. When a trade slot is free (either a trade is closed or max_open_trades value in config is increased), then the whitelist will return to normal state.

    When multiple pairlist filters are being used, it's recommended to put this filter at second position directly below the primary pairlist, so when the trade slots are full, the bot doesn't have to download data for the rest of the filters.

    Backtesting

    FullTradesFilter does not support backtesting mode.

    "},{"location":"includes/pairlists/#offsetfilter","title":"OffsetFilter","text":"

    Offsets an incoming pairlist by a given offset value.

    As an example it can be used in conjunction with VolumeFilter to remove the top X volume pairs. Or to split a larger pairlist on two bot instances.

    Example to remove the first 10 pairs from the pairlist, and takes the next 20 (taking items 10-30 of the initial list):

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"OffsetFilter\",\n        \"offset\": 10,\n        \"number_assets\": 20\n    }\n],\n

    Warning

    When OffsetFilter is used to split a larger pairlist among multiple bots in combination with VolumeFilter it can not be guaranteed that pairs won't overlap due to slightly different refresh intervals for the VolumeFilter.

    Note

    An offset larger than the total length of the incoming pairlist will result in an empty pairlist.

    "},{"location":"includes/pairlists/#performancefilter","title":"PerformanceFilter","text":"

    Sorts pairs by past trade performance, as follows:

    1. Positive performance.
    2. No closed trades yet.
    3. Negative performance.

    Trade count is used as a tie breaker.

    You can use the minutes parameter to only consider performance of the past X minutes (rolling window). Not defining this parameter (or setting it to 0) will use all-time performance.

    The optional min_profit (as ratio -> a setting of 0.01 corresponds to 1%) parameter defines the minimum profit a pair must have to be considered. Pairs below this level will be filtered out. Using this parameter without minutes is highly discouraged, as it can lead to an empty pairlist without a way to recover.

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"PerformanceFilter\",\n        \"minutes\": 1440,  // rolling 24h\n        \"min_profit\": 0.01  // minimal profit 1%\n    }\n],\n

    As this Filter uses past performance of the bot, it'll have some startup-period - and should only be used after the bot has a few 100 trades in the database.

    Backtesting

    PerformanceFilter does not support backtesting mode.

    "},{"location":"includes/pairlists/#precisionfilter","title":"PrecisionFilter","text":"

    Filters low-value coins which would not allow setting stoplosses.

    Namely, pairs are blacklisted if a variance of one percent or more in the stop price would be caused by precision rounding on the exchange, i.e. rounded(stop_price) <= rounded(stop_price * 0.99). The idea is to avoid coins with a value VERY close to their lower trading boundary, not allowing setting of proper stoploss.

    PrecisionFilter is pointless for futures trading

    The above does not apply to shorts. And for longs, in theory the trade will be liquidated first.

    Backtesting

    PrecisionFilter does not support backtesting mode using multiple strategies.

    "},{"location":"includes/pairlists/#pricefilter","title":"PriceFilter","text":"

    The PriceFilter allows filtering of pairs by price. Currently the following price filters are supported:

    • min_price
    • max_price
    • max_value
    • low_price_ratio

    The min_price setting removes pairs where the price is below the specified price. This is useful if you wish to avoid trading very low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_price setting removes pairs where the price is above the specified price. This is useful if you wish to trade only low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_value setting removes pairs where the minimum value change is above a specified value. This is useful when an exchange has unbalanced limits. For example, if step-size = 1 (so you can only buy 1, or 2, or 3, but not 1.1 Coins) - and the price is pretty high (like 20$) as the coin has risen sharply since the last limit adaption. As a result of the above, you can only buy for 20$, or 40$ - but not for 25$. On exchanges that deduct fees from the receiving currency (e.g. binance) - this can result in high value coins / amounts that are unsellable as the amount is slightly below the limit.

    The low_price_ratio setting removes pairs where a raise of 1 price unit (pip) is above the low_price_ratio ratio. This option is disabled by default, and will only apply if set to > 0.

    For PriceFilter at least one of its min_price, max_price or low_price_ratio settings must be applied.

    Calculation example:

    Min price precision for SHITCOIN/BTC is 8 decimals. If its price is 0.00000011 - one price step above would be 0.00000012, which is ~9% higher than the previous price value. You may filter out this pair by using PriceFilter with low_price_ratio set to 0.09 (9%) or with min_price set to 0.00000011, correspondingly.

    Low priced pairs

    Low priced pairs with high \"1 pip movements\" are dangerous since they are often illiquid and it may also be impossible to place the desired stoploss, which can often result in high losses since price needs to be rounded to the next tradable price - so instead of having a stoploss of -5%, you could end up with a stoploss of -9% simply due to price rounding.

    "},{"location":"includes/pairlists/#shufflefilter","title":"ShuffleFilter","text":"

    Shuffles (randomizes) pairs in the pairlist. It can be used for preventing the bot from trading some of the pairs more frequently then others when you want all pairs be treated with the same priority.

    By default, ShuffleFilter will shuffle pairs once per candle. To shuffle on every iteration, set \"shuffle_frequency\" to \"iteration\" instead of the default of \"candle\".

        {\n        \"method\": \"ShuffleFilter\", \n        \"shuffle_frequency\": \"candle\",\n        \"seed\": 42\n    }\n

    Tip

    You may set the seed value for this Pairlist to obtain reproducible results, which can be useful for repeated backtesting sessions. If seed is not set, the pairs are shuffled in the non-repeatable random order. ShuffleFilter will automatically detect runmodes and apply the seed only for backtesting modes - if a seed value is set.

    "},{"location":"includes/pairlists/#spreadfilter","title":"SpreadFilter","text":"

    Removes pairs that have a difference between asks and bids above the specified ratio, max_spread_ratio (defaults to 0.005).

    Example:

    If DOGE/BTC maximum bid is 0.00000026 and minimum ask is 0.00000027, the ratio is calculated as: 1 - bid/ask ~= 0.037 which is > 0.005 and this pair will be filtered out.

    "},{"location":"includes/pairlists/#rangestabilityfilter","title":"RangeStabilityFilter","text":"

    Removes pairs where the difference between lowest low and highest high over lookback_days days is below min_rate_of_change or above max_rate_of_change. Since this is a filter that requires additional data, the results are cached for refresh_period.

    In the below example: If the trading range over the last 10 days is <1% or >99%, remove the pair from the whitelist.

    \"pairlists\": [\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"max_rate_of_change\": 0.99,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting for this pairlist.

    Tip

    This Filter can be used to automatically remove stable coin pairs, which have a very low trading range, and are therefore extremely difficult to trade with profit. Additionally, it can also be used to automatically remove pairs with extreme high/low variance over a given amount of time.

    "},{"location":"includes/pairlists/#volatilityfilter","title":"VolatilityFilter","text":"

    Volatility is the degree of historical variation of a pairs over time, it is measured by the standard deviation of logarithmic daily returns. Returns are assumed to be normally distributed, although actual distribution might be different. In a normal distribution, 68% of observations fall within one standard deviation and 95% of observations fall within two standard deviations. Assuming a volatility of 0.05 means that the expected returns for 20 out of 30 days is expected to be less than 5% (one standard deviation). Volatility is a positive ratio of the expected deviation of return and can be greater than 1.00. Please refer to the wikipedia definition of volatility.

    This filter removes pairs if the average volatility over a lookback_days days is below min_volatility or above max_volatility. Since this is a filter that requires additional data, the results are cached for refresh_period.

    This filter can be used to narrow down your pairs to a certain volatility or avoid very volatile pairs.

    In the below example: If the volatility over the last 10 days is not in the range of 0.05-0.50, remove the pair from the whitelist. The filter is applied every 24h.

    \"pairlists\": [\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting mode for this pairlist.

    "},{"location":"includes/pairlists/#full-example-of-pairlist-handlers","title":"Full example of Pairlist Handlers","text":"

    The below example blacklists BNB/BTC, uses VolumePairList with 20 assets, sorting pairs by quoteVolume and applies PrecisionFilter and PriceFilter, filtering all assets where 1 price unit is > 1%. Then the SpreadFilter and VolatilityFilter is applied and pairs are finally shuffled with the random seed set to some predefined value.

    \"exchange\": {\n    \"pair_whitelist\": [],\n    \"pair_blacklist\": [\"BNB/BTC\"]\n},\n\"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\"\n    },\n    {\"method\": \"AgeFilter\", \"min_days_listed\": 10},\n    {\"method\": \"PrecisionFilter\"},\n    {\"method\": \"PriceFilter\", \"low_price_ratio\": 0.01},\n    {\"method\": \"SpreadFilter\", \"max_spread_ratio\": 0.005},\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"refresh_period\": 86400\n    },\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    },\n    {\"method\": \"ShuffleFilter\", \"seed\": 42}\n],\n
    "},{"location":"includes/pricing/","title":"Pricing","text":""},{"location":"includes/pricing/#prices-used-for-orders","title":"Prices used for orders","text":"

    Prices for regular orders can be controlled via the parameter structures entry_pricing for trade entries and exit_pricing for trade exits. Prices are always retrieved right before an order is placed, either by querying the exchange tickers or by using the orderbook data.

    Note

    Orderbook data used by Freqtrade are the data retrieved from exchange by the ccxt's function fetch_order_book(), i.e. are usually data from the L2-aggregated orderbook, while the ticker data are the structures returned by the ccxt's fetch_ticker()/fetch_tickers() functions. Refer to the ccxt library documentation for more details.

    Using market orders

    Please read the section Market order pricing section when using market orders.

    "},{"location":"includes/pricing/#entry-price","title":"Entry price","text":""},{"location":"includes/pricing/#enter-price-side","title":"Enter price side","text":"

    The configuration setting entry_pricing.price_side defines the side of the orderbook the bot looks for when buying.

    The following displays an orderbook.

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If entry_pricing.price_side is set to \"bid\", then the bot will use 99 as entry price. In line with that, if entry_pricing.price_side is set to \"ask\", then the bot will use 101 as entry price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    direction Order setting price crosses spread long buy ask 101 yes long buy bid 99 no long buy same 99 no long buy other 101 yes short sell ask 101 no short sell bid 99 yes short sell same 101 no short sell other 99 yes

    Using the other side of the orderbook often guarantees quicker filled orders, but the bot can also end up paying more than what would have been necessary. Taker fees instead of maker fees will most likely apply even when using limit buy orders. Also, prices at the \"other\" side of the spread are higher than prices at the \"bid\" side in the orderbook, so the order behaves similar to a market order (however with a maximum price).

    "},{"location":"includes/pricing/#entry-price-with-orderbook-enabled","title":"Entry price with Orderbook enabled","text":"

    When entering a trade with the orderbook enabled (entry_pricing.use_order_book=True), Freqtrade fetches the entry_pricing.order_book_top entries from the orderbook and uses the entry specified as entry_pricing.order_book_top on the configured side (entry_pricing.price_side) of the orderbook. 1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"includes/pricing/#entry-price-without-orderbook-enabled","title":"Entry price without Orderbook enabled","text":"

    The following section uses side as the configured entry_pricing.price_side (defaults to \"same\").

    When not using orderbook (entry_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's below the last traded price from the ticker. Otherwise (when the side price is above the last price), it calculates a rate between side and last price based on entry_pricing.price_last_balance.

    The entry_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between ask and last price.

    "},{"location":"includes/pricing/#check-depth-of-market","title":"Check depth of market","text":"

    When check depth of market is enabled (entry_pricing.check_depth_of_market.enabled=True), the entry signals are filtered based on the orderbook depth (sum of all amounts) for each orderbook side.

    Orderbook bid (buy) side depth is then divided by the orderbook ask (sell) side depth and the resulting delta is compared to the value of the entry_pricing.check_depth_of_market.bids_to_ask_delta parameter. The entry order is only executed if the orderbook delta is greater than or equal to the configured delta value.

    Note

    A delta value below 1 means that ask (sell) orderbook side depth is greater than the depth of the bid (buy) orderbook side, while a value greater than 1 means opposite (depth of the buy side is higher than the depth of the sell side).

    "},{"location":"includes/pricing/#exit-price","title":"Exit price","text":""},{"location":"includes/pricing/#exit-price-side","title":"Exit price side","text":"

    The configuration setting exit_pricing.price_side defines the side of the spread the bot looks for when exiting a trade.

    The following displays an orderbook:

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If exit_pricing.price_side is set to \"ask\", then the bot will use 101 as exiting price. In line with that, if exit_pricing.price_side is set to \"bid\", then the bot will use 99 as exiting price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    Direction Order setting price crosses spread long sell ask 101 no long sell bid 99 yes long sell same 101 no long sell other 99 yes short buy ask 101 yes short buy bid 99 no short buy same 99 no short buy other 101 yes"},{"location":"includes/pricing/#exit-price-with-orderbook-enabled","title":"Exit price with Orderbook enabled","text":"

    When exiting with the orderbook enabled (exit_pricing.use_order_book=True), Freqtrade fetches the exit_pricing.order_book_top entries in the orderbook and uses the entry specified as exit_pricing.order_book_top from the configured side (exit_pricing.price_side) as trade exit price.

    1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"includes/pricing/#exit-price-without-orderbook-enabled","title":"Exit price without Orderbook enabled","text":"

    The following section uses side as the configured exit_pricing.price_side (defaults to \"ask\").

    When not using orderbook (exit_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's above the last traded price from the ticker. Otherwise (when the side price is below the last price), it calculates a rate between side and last price based on exit_pricing.price_last_balance.

    The exit_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between side and last price.

    "},{"location":"includes/pricing/#market-order-pricing","title":"Market order pricing","text":"

    When using market orders, prices should be configured to use the \"correct\" side of the orderbook to allow realistic pricing detection. Assuming both entry and exits are using market orders, a configuration similar to the following must be used

      \"order_types\": {\n    \"entry\": \"market\",\n    \"exit\": \"market\"\n    // ...\n  },\n  \"entry_pricing\": {\n    \"price_side\": \"other\",\n    // ...\n  },\n  \"exit_pricing\":{\n    \"price_side\": \"other\",\n    // ...\n  },\n

    Obviously, if only one side is using limit orders, different pricing combinations can be used.

    "},{"location":"includes/protections/","title":"Protections","text":""},{"location":"includes/protections/#protections","title":"Protections","text":"

    Beta feature

    This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.

    Protections will protect your strategy from unexpected events and market conditions by temporarily stop trading for either one pair, or for all pairs. All protection end times are rounded up to the next candle to avoid sudden, unexpected intra-candle buys.

    Note

    Not all Protections will work for all strategies, and parameters will need to be tuned for your strategy to improve performance.

    Tip

    Each Protection can be configured multiple times with different parameters, to allow different levels of protection (short-term / long-term).

    Backtesting

    Protections are supported by backtesting and hyperopt, but must be explicitly enabled by using the --enable-protections flag.

    Setting protections from the configuration

    Setting protections from the configuration via \"protections\": [], key should be considered deprecated and will be removed in a future version. It is also no longer guaranteed that your protections apply to the strategy in cases where the strategy defines protections as property.

    "},{"location":"includes/protections/#available-protections","title":"Available Protections","text":"
    • StoplossGuard Stop trading if a certain amount of stoploss occurred within a certain time window.
    • MaxDrawdown Stop trading if max-drawdown is reached.
    • LowProfitPairs Lock pairs with low profits
    • CooldownPeriod Don't enter a trade right after selling a trade.
    "},{"location":"includes/protections/#common-settings-to-all-protections","title":"Common settings to all Protections","text":"Parameter Description method Protection name to use. Datatype: String, selected from available Protections stop_duration_candles For how many candles should the lock be set? Datatype: Positive integer (in candles) stop_duration how many minutes should protections be locked. Cannot be used together with stop_duration_candles. Datatype: Float (in minutes) lookback_period_candles Only trades that completed within the last lookback_period_candles candles will be considered. This setting may be ignored by some Protections. Datatype: Positive integer (in candles). lookback_period Only trades that completed after current_time - lookback_period will be considered. Cannot be used together with lookback_period_candles. This setting may be ignored by some Protections. Datatype: Float (in minutes) trade_limit Number of trades required at minimum (not used by all Protections). Datatype: Positive integer unlock_at Time when trading will be unlocked regularly (not used by all Protections). Datatype: string Input Format: \"HH:MM\" (24-hours)

    Durations

    Durations (stop_duration* and lookback_period* can be defined in either minutes or candles). For more flexibility when testing different timeframes, all below examples will use the \"candle\" definition.

    "},{"location":"includes/protections/#stoploss-guard","title":"Stoploss Guard","text":"

    StoplossGuard selects all trades within lookback_period in minutes (or in candles when using lookback_period_candles). If trade_limit or more trades resulted in stoploss, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    This applies across all pairs, unless only_per_pair is set to true, which will then only look at one pair at a time.

    Similarly, this protection will by default look at all trades (long and short). For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long stoplosses.

    required_profit will determine the required relative profit (or loss) for stoplosses to consider. This should normally not be set and defaults to 0.0 - which means all losing stoplosses will be triggering a block.

    The below example stops trading for all pairs for 4 candles after the last trade if the bot hit stoploss 4 times within the last 24 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"StoplossGuard\",\n            \"lookback_period_candles\": 24,\n            \"trade_limit\": 4,\n            \"stop_duration_candles\": 4,\n            \"required_profit\": 0.0,\n            \"only_per_pair\": False,\n            \"only_per_side\": False\n        }\n    ]\n

    Note

    StoplossGuard considers all trades with the results \"stop_loss\", \"stoploss_on_exchange\" and \"trailing_stop_loss\" if the resulting profit was negative. trade_limit and lookback_period will need to be tuned for your strategy.

    "},{"location":"includes/protections/#maxdrawdown","title":"MaxDrawdown","text":"

    MaxDrawdown uses all trades within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the maximum drawdown. If the drawdown is below max_allowed_drawdown, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles) after the last trade - assuming that the bot needs some time to let markets recover.

    The below sample stops trading for 12 candles if max-drawdown is > 20% considering all pairs - with a minimum of trade_limit trades - within the last 48 candles. If desired, lookback_period and/or stop_duration can be used.

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"MaxDrawdown\",\n            \"lookback_period_candles\": 48,\n            \"trade_limit\": 20,\n            \"stop_duration_candles\": 12,\n            \"max_allowed_drawdown\": 0.2\n        },\n    ]\n
    "},{"location":"includes/protections/#low-profit-pairs","title":"Low Profit Pairs","text":"

    LowProfitPairs uses all trades for a pair within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the overall profit ratio. If that ratio is below required_profit, that pair will be locked for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long losses.

    The below example will stop trading a pair for 60 minutes if the pair does not have a required profit of 2% (and a minimum of 2 trades) within the last 6 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"LowProfitPairs\",\n            \"lookback_period_candles\": 6,\n            \"trade_limit\": 2,\n            \"stop_duration\": 60,\n            \"required_profit\": 0.02,\n            \"only_per_pair\": False,\n        }\n    ]\n
    "},{"location":"includes/protections/#cooldown-period","title":"Cooldown Period","text":"

    CooldownPeriod locks a pair for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at) after exiting, avoiding a re-entry for this pair for stop_duration minutes.

    The below example will stop trading a pair for 2 candles after closing a trade, allowing this pair to \"cool down\".

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": 2\n        }\n    ]\n

    Note

    This Protection applies only at pair-level, and will never lock all pairs globally. This Protection does not consider lookback_period as it only looks at the latest trade.

    "},{"location":"includes/protections/#full-example-of-protections","title":"Full example of Protections","text":"

    All protections can be combined at will, also with different parameters, creating a increasing wall for under-performing pairs. All protections are evaluated in the sequence they are defined.

    The below example assumes a timeframe of 1 hour:

    • Locks each pair after selling for an additional 5 candles (CooldownPeriod), giving other pairs a chance to get filled.
    • Stops trading for 4 hours (4 * 1h candles) if the last 2 days (48 * 1h candles) had 20 trades, which caused a max-drawdown of more than 20%. (MaxDrawdown).
    • Stops trading if more than 4 stoploss occur for all pairs within a 1 day (24 * 1h candles) limit (StoplossGuard).
    • Locks all pairs that had 2 Trades within the last 6 hours (6 * 1h candles) with a combined profit ratio of below 0.02 (<2%) (LowProfitPairs).
    • Locks all pairs for 2 candles that had a profit of below 0.01 (<1%) within the last 24h (24 * 1h candles), a minimum of 4 trades.
    from freqtrade.strategy import IStrategy\n\nclass AwesomeStrategy(IStrategy)\n    timeframe = '1h'\n\n    @property\n    def protections(self):\n        return [\n            {\n                \"method\": \"CooldownPeriod\",\n                \"stop_duration_candles\": 5\n            },\n            {\n                \"method\": \"MaxDrawdown\",\n                \"lookback_period_candles\": 48,\n                \"trade_limit\": 20,\n                \"stop_duration_candles\": 4,\n                \"max_allowed_drawdown\": 0.2\n            },\n            {\n                \"method\": \"StoplossGuard\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"only_per_pair\": False\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 6,\n                \"trade_limit\": 2,\n                \"stop_duration_candles\": 60,\n                \"required_profit\": 0.02\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"required_profit\": 0.01\n            }\n        ]\n    # ...\n
    "},{"location":"includes/release_template/","title":"Release template","text":""},{"location":"includes/release_template/#highlighted-changes","title":"Highlighted changes","text":"
    • ...
    "},{"location":"includes/release_template/#how-to-update","title":"How to update","text":"

    As always, you can update your bot using one of the following commands:

    "},{"location":"includes/release_template/#docker-compose","title":"docker-compose","text":"
    docker-compose pull\ndocker-compose up -d\n
    "},{"location":"includes/release_template/#installation-via-setup-script","title":"Installation via setup script","text":"
    # Deactivate venv and run \n./setup.sh --update\n
    "},{"location":"includes/release_template/#plain-native-installation","title":"Plain native installation","text":"
    git pull\npip install -U -r requirements.txt\n
    Expand full changelog
    <Paste your changelog here>\n
    "},{"location":"includes/showcase/","title":"Showcase","text":"

    This section will highlight a few projects from members of the community.

    Note

    The projects below are for the most part not maintained by the freqtrade , therefore use your own caution before using them.

    • Example freqtrade strategies
    • FrequentHippo - Grafana dashboard with dry/live runs and backtests (by hippocritical).
    • Online pairlist generator (by Blood4rc).
    • Freqtrade Backtesting Project (by Blood4rc).
    • Freqtrade analysis notebook (by Froggleston).
    • TUI for freqtrade (by Froggleston).
    • Bot Academy (by stash86) - Blog about crypto bot projects.
    "},{"location":"includes/strategy-imports/","title":"Strategy imports","text":""},{"location":"includes/strategy-imports/#imports-necessary-for-a-strategy","title":"Imports necessary for a strategy","text":"

    When creating a strategy, you will need to import the necessary modules and classes. The following imports are required for a strategy:

    By default, we recommend the following imports as a base line for your strategy: This will cover all imports necessary for freqtrade functions to work. Obviously you can add more imports as needed for your strategy.

    # flake8: noqa: F401\n# isort: skip_file\n# --- Do not remove these imports ---\nimport numpy as np\nimport pandas as pd\nfrom datetime import datetime, timedelta, timezone\nfrom pandas import DataFrame\nfrom typing import Dict, Optional, Union, Tuple\n\nfrom freqtrade.strategy import (\n    IStrategy,\n    Trade, \n    Order,\n    PairLocks,\n    informative,  # @informative decorator\n    # Hyperopt Parameters\n    BooleanParameter,\n    CategoricalParameter,\n    DecimalParameter,\n    IntParameter,\n    RealParameter,\n    # timeframe helpers\n    timeframe_to_minutes,\n    timeframe_to_next_date,\n    timeframe_to_prev_date,\n    # Strategy helper functions\n    merge_informative_pair,\n    stoploss_from_absolute,\n    stoploss_from_open,\n)\n\n# --------------------------------\n# Add your lib to import here\nimport talib.abstract as ta\nfrom technical import qtpylib\n
    "}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Home","text":"

    Star Fork Download

    "},{"location":"#introduction","title":"Introduction","text":"

    Freqtrade is a free and open source crypto trading bot written in Python. It is designed to support all major exchanges and be controlled via Telegram or webUI. It contains backtesting, plotting and money management tools as well as strategy optimization by machine learning.

    DISCLAIMER

    This software is for educational purposes only. Do not risk money which you are afraid to lose. USE THE SOFTWARE AT YOUR OWN RISK. THE AUTHORS AND ALL AFFILIATES ASSUME NO RESPONSIBILITY FOR YOUR TRADING RESULTS.

    Always start by running a trading bot in Dry-run and do not engage money before you understand how it works and what profit/loss you should expect.

    We strongly recommend you to have basic coding skills and Python knowledge. Do not hesitate to read the source code and understand the mechanisms of this bot, algorithms and techniques implemented in it.

    "},{"location":"#features","title":"Features","text":"
    • Develop your Strategy: Write your strategy in python, using pandas. Example strategies to inspire you are available in the strategy repository.
    • Download market data: Download historical data of the exchange and the markets your may want to trade with.
    • Backtest: Test your strategy on downloaded historical data.
    • Optimize: Find the best parameters for your strategy using hyperoptimization which employs machining learning methods. You can optimize buy, sell, take profit (ROI), stop-loss and trailing stop-loss parameters for your strategy.
    • Select markets: Create your static list or use an automatic one based on top traded volumes and/or prices (not available during backtesting). You can also explicitly blacklist markets you don't want to trade.
    • Run: Test your strategy with simulated money (Dry-Run mode) or deploy it with real money (Live-Trade mode).
    • Run using Edge (optional module): The concept is to find the best historical trade expectancy by markets based on variation of the stop-loss and then allow/reject markets to trade. The sizing of the trade is based on a risk of a percentage of your capital.
    • Control/Monitor: Use Telegram or a WebUI (start/stop the bot, show profit/loss, daily summary, current open trades results, etc.).
    • Analyze: Further analysis can be performed on either Backtesting data or Freqtrade trading history (SQL database), including automated standard plots, and methods to load the data into interactive environments.
    "},{"location":"#supported-exchange-marketplaces","title":"Supported exchange marketplaces","text":"

    Please read the exchange specific notes to learn about eventual, special configurations needed for each exchange.

    • Binance
    • Bitmart
    • BingX
    • Bybit
    • Gate.io
    • HTX (Former Huobi)
    • Kraken
    • OKX (Former OKEX)
    • potentially many others through . (We cannot guarantee they will work)
    "},{"location":"#supported-futures-exchanges-experimental","title":"Supported Futures Exchanges (experimental)","text":"
    • Binance
    • Gate.io
    • OKX
    • Bybit

    Please make sure to read the exchange specific notes, as well as the trading with leverage documentation before diving in.

    "},{"location":"#community-tested","title":"Community tested","text":"

    Exchanges confirmed working by the community:

    • Bitvavo
    • Kucoin
    "},{"location":"#community-showcase","title":"Community showcase","text":"

    This section will highlight a few projects from members of the community.

    Note

    The projects below are for the most part not maintained by the freqtrade , therefore use your own caution before using them.

    • Example freqtrade strategies
    • FrequentHippo - Grafana dashboard with dry/live runs and backtests (by hippocritical).
    • Online pairlist generator (by Blood4rc).
    • Freqtrade Backtesting Project (by Blood4rc).
    • Freqtrade analysis notebook (by Froggleston).
    • TUI for freqtrade (by Froggleston).
    • Bot Academy (by stash86) - Blog about crypto bot projects.
    "},{"location":"#requirements","title":"Requirements","text":""},{"location":"#hardware-requirements","title":"Hardware requirements","text":"

    To run this bot we recommend you a linux cloud instance with a minimum of:

    • 2GB RAM
    • 1GB disk space
    • 2vCPU
    "},{"location":"#software-requirements","title":"Software requirements","text":"
    • Docker (Recommended)

    Alternatively

    • Python 3.9+
    • pip (pip3)
    • git
    • TA-Lib
    • virtualenv (Recommended)
    "},{"location":"#support","title":"Support","text":""},{"location":"#help-discord","title":"Help / Discord","text":"

    For any questions not covered by the documentation or for further information about the bot, or to simply engage with like-minded individuals, we encourage you to join the Freqtrade discord server.

    "},{"location":"#ready-to-try","title":"Ready to try?","text":"

    Begin by reading the installation guide for docker (recommended), or for installation without docker.

    "},{"location":"advanced-backtesting/","title":"Advanced Backtesting Analysis","text":""},{"location":"advanced-backtesting/#analyze-the-buyentry-and-sellexit-tags","title":"Analyze the buy/entry and sell/exit tags","text":"

    It can be helpful to understand how a strategy behaves according to the buy/entry tags used to mark up different buy conditions. You might want to see more complex statistics about each buy and sell condition above those provided by the default backtesting output. You may also want to determine indicator values on the signal candle that resulted in a trade opening.

    Note

    The following buy reason analysis is only available for backtesting, not hyperopt.

    We need to run backtesting with the --export option set to signals to enable the exporting of signals and trades:

    freqtrade backtesting -c <config.json> --timeframe <tf> --strategy <strategy_name> --timerange=<timerange> --export=signals\n

    This will tell freqtrade to output a pickled dictionary of strategy, pairs and corresponding DataFrame of the candles that resulted in entry and exit signals. Depending on how many entries your strategy makes, this file may get quite large, so periodically check your user_data/backtest_results folder to delete old exports.

    Before running your next backtest, make sure you either delete your old backtest results or run backtesting with the --cache none option to make sure no cached results are used.

    If all goes well, you should now see a backtest-result-{timestamp}_signals.pkl and backtest-result-{timestamp}_exited.pkl files in the user_data/backtest_results folder.

    To analyze the entry/exit tags, we now need to use the freqtrade backtesting-analysis command with --analysis-groups option provided with space-separated arguments:

    freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 1 2 3 4 5\n

    This command will read from the last backtesting results. The --analysis-groups option is used to specify the various tabular outputs showing the profit of each group or trade, ranging from the simplest (0) to the most detailed per pair, per buy and per sell tag (4):

    • 0: overall winrate and profit summary by enter_tag
    • 1: profit summaries grouped by enter_tag
    • 2: profit summaries grouped by enter_tag and exit_tag
    • 3: profit summaries grouped by pair and enter_tag
    • 4: profit summaries grouped by pair, enter_ and exit_tag (this can get quite large)
    • 5: profit summaries grouped by exit_tag

    More options are available by running with the -h option.

    "},{"location":"advanced-backtesting/#using-export-filename","title":"Using export-filename","text":"

    Normally, backtesting-analysis uses the latest backtest results, but if you wanted to go back to a previous backtest output, you need to supply the --export-filename option. You can supply the same parameter to backtest-analysis with the name of the final backtest output file. This allows you to keep historical versions of backtest results and re-analyse them at a later date:

    freqtrade backtesting -c <config.json> --timeframe <tf> --strategy <strategy_name> --timerange=<timerange> --export=signals --export-filename=/tmp/mystrat_backtest.json\n

    You should see some output similar to below in the logs with the name of the timestamped filename that was exported:

    2022-06-14 16:28:32,698 - freqtrade.misc - INFO - dumping json to \"/tmp/mystrat_backtest-2022-06-14_16-28-32.json\"\n

    You can then use that filename in backtesting-analysis:

    freqtrade backtesting-analysis -c <config.json> --export-filename=/tmp/mystrat_backtest-2022-06-14_16-28-32.json\n
    "},{"location":"advanced-backtesting/#tuning-the-buy-tags-and-sell-tags-to-display","title":"Tuning the buy tags and sell tags to display","text":"

    To show only certain buy and sell tags in the displayed output, use the following two options:

    --enter-reason-list : Space-separated list of enter signals to analyse. Default: \"all\"\n--exit-reason-list : Space-separated list of exit signals to analyse. Default: \"all\"\n

    For example:

    freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss\n
    "},{"location":"advanced-backtesting/#outputting-signal-candle-indicators","title":"Outputting signal candle indicators","text":"

    The real power of freqtrade backtesting-analysis comes from the ability to print out the indicator values present on signal candles to allow fine-grained investigation and tuning of buy signal indicators. To print out a column for a given set of indicators, use the --indicator-list option:

    freqtrade backtesting-analysis -c <config.json> --analysis-groups 0 2 --enter-reason-list enter_tag_a enter_tag_b --exit-reason-list roi custom_exit_tag_a stop_loss --indicator-list rsi rsi_1h bb_lowerband ema_9 macd macdsignal\n

    The indicators have to be present in your strategy's main DataFrame (either for your main timeframe or for informative timeframes) otherwise they will simply be ignored in the script output.

    Indicator List

    The indicator values will be displayed for both entry and exit points. If --indicator-list all is specified, only the indicators at the entry point will be shown to avoid excessively large lists, which could occur depending on the strategy.

    There are a range of candle and trade-related fields that are included in the analysis so are automatically accessible by including them on the indicator-list, and these include:

    • open_date : trade open datetime
    • close_date : trade close datetime
    • min_rate : minimum price seen throughout the position
    • max_rate : maximum price seen throughout the position
    • open : signal candle open price
    • close : signal candle close price
    • high : signal candle high price
    • low : signal candle low price
    • volume : signal candle volume
    • profit_ratio : trade profit ratio
    • profit_abs : absolute profit return of the trade
    "},{"location":"advanced-backtesting/#sample-output-for-indicator-values","title":"Sample Output for Indicator Values","text":"
    freqtrade backtesting-analysis -c user_data/config.json --analysis-groups 0 --indicator-list chikou_span tenkan_sen \n

    In this example, we aim to display the chikou_span and tenkan_sen indicator values at both the entry and exit points of trades.

    A sample output for indicators might look like this:

    pair open_date enter_reason exit_reason chikou_span (entry) tenkan_sen (entry) chikou_span (exit) tenkan_sen (exit) DOGE/USDT 2024-07-06 00:35:00+00:00 exit_signal 0.105 0.106 0.105 0.107 BTC/USDT 2024-08-05 14:20:00+00:00 roi 54643.440 51696.400 54386.000 52072.010

    As shown in the table, chikou_span (entry) represents the indicator value at the time of trade entry, while chikou_span (exit) reflects its value at the time of exit. This detailed view of indicator values enhances the analysis.

    The (entry) and (exit) suffixes are added to indicators to distinguish the values at the entry and exit points of the trade.

    Trade-wide Indicators

    Certain trade-wide indicators do not have the (entry) or (exit) suffix. These indicators include: pair, stake_amount, max_stake_amount, amount, open_date, close_date, open_rate, close_rate, fee_open, fee_close, trade_duration, profit_ratio, profit_abs, exit_reason,initial_stop_loss_abs, initial_stop_loss_ratio, stop_loss_abs, stop_loss_ratio, min_rate, max_rate, is_open, enter_tag, leverage, is_short, open_timestamp, close_timestamp and orders

    "},{"location":"advanced-backtesting/#filtering-indicators-based-on-entry-or-exit-signals","title":"Filtering Indicators Based on Entry or Exit Signals","text":"

    The --indicator-list option, by default, displays indicator values for both entry and exit signals. To filter the indicator values exclusively for entry signals, you can use the --entry-only argument. Similarly, to display indicator values only at exit signals, use the --exit-only argument.

    Example: Display indicator values at entry signals:

    freqtrade backtesting-analysis -c user_data/config.json --analysis-groups 0 --indicator-list chikou_span tenkan_sen --entry-only\n

    Example: Display indicator values at exit signals:

    freqtrade backtesting-analysis -c user_data/config.json --analysis-groups 0 --indicator-list chikou_span tenkan_sen --exit-only\n

    Note

    When using these filters, the indicator names will not be suffixed with (entry) or (exit).

    "},{"location":"advanced-backtesting/#filtering-the-trade-output-by-date","title":"Filtering the trade output by date","text":"

    To show only trades between dates within your backtested timerange, supply the usual timerange option in YYYYMMDD-[YYYYMMDD] format:

    --timerange : Timerange to filter output trades, start date inclusive, end date exclusive. e.g. 20220101-20221231\n

    For example, if your backtest timerange was 20220101-20221231 but you only want to output trades in January:

    freqtrade backtesting-analysis -c <config.json> --timerange 20220101-20220201\n
    "},{"location":"advanced-backtesting/#printing-out-rejected-signals","title":"Printing out rejected signals","text":"

    Use the --rejected-signals option to print out rejected signals.

    freqtrade backtesting-analysis -c <config.json> --rejected-signals\n
    "},{"location":"advanced-backtesting/#writing-tables-to-csv","title":"Writing tables to CSV","text":"

    Some of the tabular outputs can become large, so printing them out to the terminal is not preferable. Use the --analysis-to-csv option to disable printing out of tables to standard out and write them to CSV files.

    freqtrade backtesting-analysis -c <config.json> --analysis-to-csv\n

    By default this will write one file per output table you specified in the backtesting-analysis command, e.g.

    freqtrade backtesting-analysis -c <config.json> --analysis-to-csv --rejected-signals --analysis-groups 0 1\n

    This will write to user_data/backtest_results:

    • rejected_signals.csv
    • group_0.csv
    • group_1.csv

    To override where the files will be written, also specify the --analysis-csv-path option.

    freqtrade backtesting-analysis -c <config.json> --analysis-to-csv --analysis-csv-path another/data/path/\n
    "},{"location":"advanced-hyperopt/","title":"Advanced Hyperopt","text":"

    This page explains some advanced Hyperopt topics that may require higher coding skills and Python knowledge than creation of an ordinal hyperoptimization class.

    "},{"location":"advanced-hyperopt/#creating-and-using-a-custom-loss-function","title":"Creating and using a custom loss function","text":"

    To use a custom loss function class, make sure that the function hyperopt_loss_function is defined in your custom hyperopt loss class. For the sample below, you then need to add the command line parameter --hyperopt-loss SuperDuperHyperOptLoss to your hyperopt call so this function is being used.

    A sample of this can be found below, which is identical to the Default Hyperopt loss implementation. A full sample can be found in userdata/hyperopts.

    from datetime import datetime\nfrom typing import Any, Dict\n\nfrom pandas import DataFrame\n\nfrom freqtrade.constants import Config\nfrom freqtrade.optimize.hyperopt import IHyperOptLoss\n\nTARGET_TRADES = 600\nEXPECTED_MAX_PROFIT = 3.0\nMAX_ACCEPTED_TRADE_DURATION = 300\n\nclass SuperDuperHyperOptLoss(IHyperOptLoss):\n    \"\"\"\n    Defines the default loss function for hyperopt\n    \"\"\"\n\n    @staticmethod\n    def hyperopt_loss_function(\n        *,\n        results: DataFrame,\n        trade_count: int,\n        min_date: datetime,\n        max_date: datetime,\n        config: Config,\n        processed: Dict[str, DataFrame],\n        backtest_stats: Dict[str, Any],\n        **kwargs,\n    ) -> float:\n        \"\"\"\n        Objective function, returns smaller number for better results\n        This is the legacy algorithm (used until now in freqtrade).\n        Weights are distributed as follows:\n        * 0.4 to trade duration\n        * 0.25: Avoiding trade loss\n        * 1.0 to total profit, compared to the expected value (`EXPECTED_MAX_PROFIT`) defined above\n        \"\"\"\n        total_profit = results['profit_ratio'].sum()\n        trade_duration = results['trade_duration'].mean()\n\n        trade_loss = 1 - 0.25 * exp(-(trade_count - TARGET_TRADES) ** 2 / 10 ** 5.8)\n        profit_loss = max(0, 1 - total_profit / EXPECTED_MAX_PROFIT)\n        duration_loss = 0.4 * min(trade_duration / MAX_ACCEPTED_TRADE_DURATION, 1)\n        result = trade_loss + profit_loss + duration_loss\n        return result\n

    Currently, the arguments are:

    • results: DataFrame containing the resulting trades. The following columns are available in results (corresponds to the output-file of backtesting when used with --export trades): pair, profit_ratio, profit_abs, open_date, open_rate, fee_open, close_date, close_rate, fee_close, amount, trade_duration, is_open, exit_reason, stake_amount, min_rate, max_rate, stop_loss_ratio, stop_loss_abs
    • trade_count: Amount of trades (identical to len(results))
    • min_date: Start date of the timerange used
    • min_date: End date of the timerange used
    • config: Config object used (Note: Not all strategy-related parameters will be updated here if they are part of a hyperopt space).
    • processed: Dict of Dataframes with the pair as keys containing the data used for backtesting.
    • backtest_stats: Backtesting statistics using the same format as the backtesting file \"strategy\" substructure. Available fields can be seen in generate_strategy_stats() in optimize_reports.py.

    This function needs to return a floating point number (float). Smaller numbers will be interpreted as better results. The parameters and balancing for this is up to you.

    Note

    This function is called once per epoch - so please make sure to have this as optimized as possible to not slow hyperopt down unnecessarily.

    *args and **kwargs

    Please keep the arguments *args and **kwargs in the interface to allow us to extend this interface in the future.

    "},{"location":"advanced-hyperopt/#overriding-pre-defined-spaces","title":"Overriding pre-defined spaces","text":"

    To override a pre-defined space (roi_space, generate_roi_table, stoploss_space, trailing_space, max_open_trades_space), define a nested class called Hyperopt and define the required spaces as follows:

    from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal\n\nclass MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        # Define a custom stoploss space.\n        def stoploss_space():\n            return [SKDecimal(-0.05, -0.01, decimals=3, name='stoploss')]\n\n        # Define custom ROI space\n        def roi_space() -> List[Dimension]:\n            return [\n                Integer(10, 120, name='roi_t1'),\n                Integer(10, 60, name='roi_t2'),\n                Integer(10, 40, name='roi_t3'),\n                SKDecimal(0.01, 0.04, decimals=3, name='roi_p1'),\n                SKDecimal(0.01, 0.07, decimals=3, name='roi_p2'),\n                SKDecimal(0.01, 0.20, decimals=3, name='roi_p3'),\n            ]\n\n        def generate_roi_table(params: Dict) -> Dict[int, float]:\n\n            roi_table = {}\n            roi_table[0] = params['roi_p1'] + params['roi_p2'] + params['roi_p3']\n            roi_table[params['roi_t3']] = params['roi_p1'] + params['roi_p2']\n            roi_table[params['roi_t3'] + params['roi_t2']] = params['roi_p1']\n            roi_table[params['roi_t3'] + params['roi_t2'] + params['roi_t1']] = 0\n\n            return roi_table\n\n        def trailing_space() -> List[Dimension]:\n            # All parameters here are mandatory, you can only modify their type or the range.\n            return [\n                # Fixed to true, if optimizing trailing_stop we assume to use trailing stop at all times.\n                Categorical([True], name='trailing_stop'),\n\n                SKDecimal(0.01, 0.35, decimals=3, name='trailing_stop_positive'),\n                # 'trailing_stop_positive_offset' should be greater than 'trailing_stop_positive',\n                # so this intermediate parameter is used as the value of the difference between\n                # them. The value of the 'trailing_stop_positive_offset' is constructed in the\n                # generate_trailing_params() method.\n                # This is similar to the hyperspace dimensions used for constructing the ROI tables.\n                SKDecimal(0.001, 0.1, decimals=3, name='trailing_stop_positive_offset_p1'),\n\n                Categorical([True, False], name='trailing_only_offset_is_reached'),\n        ]\n\n        # Define a custom max_open_trades space\n        def max_open_trades_space(self) -> List[Dimension]:\n            return [\n                Integer(-1, 10, name='max_open_trades'),\n            ]\n

    Note

    All overrides are optional and can be mixed/matched as necessary.

    "},{"location":"advanced-hyperopt/#dynamic-parameters","title":"Dynamic parameters","text":"

    Parameters can also be defined dynamically, but must be available to the instance once the bot_start() callback has been called.

    class MyAwesomeStrategy(IStrategy):\n\n    def bot_start(self, **kwargs) -> None:\n        self.buy_adx = IntParameter(20, 30, default=30, optimize=True)\n\n    # ...\n

    Warning

    Parameters created this way will not show up in the list-strategies parameter count.

    "},{"location":"advanced-hyperopt/#overriding-base-estimator","title":"Overriding Base estimator","text":"

    You can define your own estimator for Hyperopt by implementing generate_estimator() in the Hyperopt subclass.

    class MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        def generate_estimator(dimensions: List['Dimension'], **kwargs):\n            return \"RF\"\n

    Possible values are either one of \"GP\", \"RF\", \"ET\", \"GBRT\" (Details can be found in the scikit-optimize documentation), or \"an instance of a class that inherits from RegressorMixin (from sklearn) and where the predict method has an optional return_std argument, which returns std(Y | x) along with E[Y | x]\".

    Some research will be necessary to find additional Regressors.

    Example for ExtraTreesRegressor (\"ET\") with additional parameters:

    class MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        def generate_estimator(dimensions: List['Dimension'], **kwargs):\n            from skopt.learning import ExtraTreesRegressor\n            # Corresponds to \"ET\" - but allows additional parameters.\n            return ExtraTreesRegressor(n_estimators=100)\n

    The dimensions parameter is the list of skopt.space.Dimension objects corresponding to the parameters to be optimized. It can be used to create isotropic kernels for the skopt.learning.GaussianProcessRegressor estimator. Here's an example:

    class MyAwesomeStrategy(IStrategy):\n    class HyperOpt:\n        def generate_estimator(dimensions: List['Dimension'], **kwargs):\n            from skopt.utils import cook_estimator\n            from skopt.learning.gaussian_process.kernels import (Matern, ConstantKernel)\n            kernel_bounds = (0.0001, 10000)\n            kernel = (\n                ConstantKernel(1.0, kernel_bounds) * \n                Matern(length_scale=np.ones(len(dimensions)), length_scale_bounds=[kernel_bounds for d in dimensions], nu=2.5)\n            )\n            kernel += (\n                ConstantKernel(1.0, kernel_bounds) * \n                Matern(length_scale=np.ones(len(dimensions)), length_scale_bounds=[kernel_bounds for d in dimensions], nu=1.5)\n            )\n\n            return cook_estimator(\"GP\", space=dimensions, kernel=kernel, n_restarts_optimizer=2)\n

    Note

    While custom estimators can be provided, it's up to you as User to do research on possible parameters and analyze / understand which ones should be used. If you're unsure about this, best use one of the Defaults (\"ET\" has proven to be the most versatile) without further parameters.

    "},{"location":"advanced-hyperopt/#space-options","title":"Space options","text":"

    For the additional spaces, scikit-optimize (in combination with Freqtrade) provides the following space types:

    • Categorical - Pick from a list of categories (e.g. Categorical(['a', 'b', 'c'], name=\"cat\"))
    • Integer - Pick from a range of whole numbers (e.g. Integer(1, 10, name='rsi'))
    • SKDecimal - Pick from a range of decimal numbers with limited precision (e.g. SKDecimal(0.1, 0.5, decimals=3, name='adx')). Available only with freqtrade.
    • Real - Pick from a range of decimal numbers with full precision (e.g. Real(0.1, 0.5, name='adx')

    You can import all of these from freqtrade.optimize.space, although Categorical, Integer and Real are only aliases for their corresponding scikit-optimize Spaces. SKDecimal is provided by freqtrade for faster optimizations.

    from freqtrade.optimize.space import Categorical, Dimension, Integer, SKDecimal, Real  # noqa\n

    SKDecimal vs. Real

    We recommend to use SKDecimal instead of the Real space in almost all cases. While the Real space provides full accuracy (up to ~16 decimal places) - this precision is rarely needed, and leads to unnecessary long hyperopt times.

    Assuming the definition of a rather small space (SKDecimal(0.10, 0.15, decimals=2, name='xxx')) - SKDecimal will have 5 possibilities ([0.10, 0.11, 0.12, 0.13, 0.14, 0.15]).

    A corresponding real space Real(0.10, 0.15 name='xxx') on the other hand has an almost unlimited number of possibilities ([0.10, 0.010000000001, 0.010000000002, ... 0.014999999999, 0.01500000000]).

    "},{"location":"advanced-orderflow/","title":"Orderflow data","text":"

    This guide walks you through utilizing public trade data for advanced orderflow analysis in Freqtrade.

    Experimental Feature

    The orderflow feature is currently in beta and may be subject to changes in future releases. Please report any issues or feedback on the Freqtrade GitHub repository.

    Performance

    Orderflow requires raw trades data. This data is rather large, and can cause a slow initial startup, when freqtrade needs to download the trades data for the last X candles. Additionally, enabling this feature will cause increased memory usage. Please ensure to have sufficient resources available.

    "},{"location":"advanced-orderflow/#getting-started","title":"Getting Started","text":""},{"location":"advanced-orderflow/#enable-public-trades","title":"Enable Public Trades","text":"

    In your config.json file, set the use_public_trades option to true under the exchange section.

    \"exchange\": {\n   ...\n   \"use_public_trades\": true,\n}\n
    "},{"location":"advanced-orderflow/#configure-orderflow-processing","title":"Configure Orderflow Processing","text":"

    Define your desired settings for orderflow processing within the orderflow section of config.json. Here, you can adjust factors like:

    • cache_size: How many previous orderflow candles are saved into cache instead of calculated every new candle
    • max_candles: Filter how many candles would you like to get trades data for.
    • scale: This controls the price bin size for the footprint chart.
    • stacked_imbalance_range: Defines the minimum consecutive imbalanced price levels required for consideration.
    • imbalance_volume: Filters out imbalances with volume below this threshold.
    • imbalance_ratio: Filters out imbalances with a ratio (difference between ask and bid volume) lower than this value.
    \"orderflow\": {\n    \"cache_size\": 1000, \n    \"max_candles\": 1500, \n    \"scale\": 0.5, \n    \"stacked_imbalance_range\": 3, //  needs at least this amount of imbalance next to each other\n    \"imbalance_volume\": 1, //  filters out below\n    \"imbalance_ratio\": 3 //  filters out ratio lower than\n  },\n
    "},{"location":"advanced-orderflow/#downloading-trade-data-for-backtesting","title":"Downloading Trade Data for Backtesting","text":"

    To download historical trade data for backtesting, use the --dl-trades flag with the freqtrade download-data command.

    freqtrade download-data -p BTC/USDT:USDT --timerange 20230101- --trading-mode futures --timeframes 5m --dl-trades\n

    Data availability

    Not all exchanges provide public trade data. For supported exchanges, freqtrade will warn you if public trade data is not available if you start downloading data with the --dl-trades flag.

    "},{"location":"advanced-orderflow/#accessing-orderflow-data","title":"Accessing Orderflow Data","text":"

    Once activated, several new columns become available in your dataframe:

    dataframe[\"trades\"] # Contains information about each individual trade.\ndataframe[\"orderflow\"] # Represents a footprint chart dict (see below)\ndataframe[\"imbalances\"] # Contains information about imbalances in the order flow.\ndataframe[\"bid\"] # Total bid volume \ndataframe[\"ask\"] # Total ask volume\ndataframe[\"delta\"] # Difference between ask and bid volume.\ndataframe[\"min_delta\"] # Minimum delta within the candle\ndataframe[\"max_delta\"] # Maximum delta within the candle\ndataframe[\"total_trades\"] # Total number of trades\ndataframe[\"stacked_imbalances_bid\"] # Price level of stacked bid imbalance \ndataframe[\"stacked_imbalances_ask\"] # Price level of stacked ask imbalance  \n

    You can access these columns in your strategy code for further analysis. Here's an example:

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    # Calculating cumulative delta\n    dataframe[\"cum_delta\"] = cumulative_delta(dataframe[\"delta\"])\n    # Accessing total trades\n    total_trades = dataframe[\"total_trades\"]\n    ...\n\ndef cumulative_delta(delta: Series):\n    cumdelta = delta.cumsum()\n    return cumdelta\n
    "},{"location":"advanced-orderflow/#footprint-chart-dataframeorderflow","title":"Footprint chart (dataframe[\"orderflow\"])","text":"

    This column provides a detailed breakdown of buy and sell orders at different price levels, offering valuable insights into order flow dynamics. The scale parameter in your configuration determines the price bin size for this representation

    The orderflow column contains a dict with the following structure:

    {\n    \"price\": {\n        \"bid_amount\": 0.0,\n        \"ask_amount\": 0.0,\n        \"bid\": 0,\n        \"ask\": 0,\n        \"delta\": 0.0,\n        \"total_volume\": 0.0,\n        \"total_trades\": 0\n    }\n}\n
    "},{"location":"advanced-orderflow/#orderflow-column-explanation","title":"Orderflow column explanation","text":"
    • key: Price bin - binned at scale intervals
    • bid_amount: Total volume bought at each price level.
    • ask_amount: Total volume sold at each price level.
    • bid: Number of buy orders at each price level.
    • ask: Number of sell orders at each price level.
    • delta: Difference between ask and bid volume at each price level.
    • total_volume: Total volume (ask amount + bid amount) at each price level.
    • total_trades: Total number of trades (ask + bid) at each price level.

    By leveraging these features, you can gain valuable insights into market sentiment and potential trading opportunities based on order flow analysis.

    "},{"location":"advanced-orderflow/#raw-trades-data-dataframetrades","title":"Raw trades data (dataframe[\"trades\"])","text":"

    List with the individual trades that occurred during the candle. This data can be used for more granular analysis of order flow dynamics.

    Each individual entry contains a dict with the following keys:

    • timestamp: Timestamp of the trade.
    • date: Date of the trade.
    • price: Price of the trade.
    • amount: Volume of the trade.
    • side: Buy or sell.
    • id: Unique identifier for the trade.
    • cost: Total cost of the trade (price * amount).
    "},{"location":"advanced-orderflow/#imbalances-dataframeimbalances","title":"Imbalances (dataframe[\"imbalances\"])","text":"

    This column provides a dict with information about imbalances in the order flow. An imbalance occurs when there is a significant difference between the ask and bid volume at a given price level.

    Each row looks as follows - with price as index, and the corresponding bid and ask imbalance values as columns

    {\n    \"price\": {\n        \"bid_imbalance\": False,\n        \"ask_imbalance\": False\n    }\n}\n
    "},{"location":"advanced-setup/","title":"Advanced Post-installation Tasks","text":"

    This page explains some advanced tasks and configuration options that can be performed after the bot installation and may be uselful in some environments.

    If you do not know what things mentioned here mean, you probably do not need it.

    "},{"location":"advanced-setup/#running-multiple-instances-of-freqtrade","title":"Running multiple instances of Freqtrade","text":"

    This section will show you how to run multiple bots at the same time, on the same machine.

    "},{"location":"advanced-setup/#things-to-consider","title":"Things to consider","text":"
    • Use different database files.
    • Use different Telegram bots (requires multiple different configuration files; applies only when Telegram is enabled).
    • Use different ports (applies only when Freqtrade REST API webserver is enabled).
    "},{"location":"advanced-setup/#different-database-files","title":"Different database files","text":"

    In order to keep track of your trades, profits, etc., freqtrade is using a SQLite database where it stores various types of information such as the trades you performed in the past and the current position(s) you are holding at any time. This allows you to keep track of your profits, but most importantly, keep track of ongoing activity if the bot process would be restarted or would be terminated unexpectedly.

    Freqtrade will, by default, use separate database files for dry-run and live bots (this assumes no database-url is given in either configuration nor via command line argument). For live trading mode, the default database will be tradesv3.sqlite and for dry-run it will be tradesv3.dryrun.sqlite.

    The optional argument to the trade command used to specify the path of these files is --db-url, which requires a valid SQLAlchemy url. So when you are starting a bot with only the config and strategy arguments in dry-run mode, the following 2 commands would have the same outcome.

    freqtrade trade -c MyConfig.json -s MyStrategy\n# is equivalent to\nfreqtrade trade -c MyConfig.json -s MyStrategy --db-url sqlite:///tradesv3.dryrun.sqlite\n

    It means that if you are running the trade command in two different terminals, for example to test your strategy both for trades in USDT and in another instance for trades in BTC, you will have to run them with different databases.

    If you specify the URL of a database which does not exist, freqtrade will create one with the name you specified. So to test your custom strategy with BTC and USDT stake currencies, you could use the following commands (in 2 separate terminals):

    # Terminal 1:\nfreqtrade trade -c MyConfigBTC.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesBTC.dryrun.sqlite\n# Terminal 2:\nfreqtrade trade -c MyConfigUSDT.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesUSDT.dryrun.sqlite\n

    Conversely, if you wish to do the same thing in production mode, you will also have to create at least one new database (in addition to the default one) and specify the path to the \"live\" databases, for example:

    # Terminal 1:\nfreqtrade trade -c MyConfigBTC.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesBTC.live.sqlite\n# Terminal 2:\nfreqtrade trade -c MyConfigUSDT.json -s MyCustomStrategy --db-url sqlite:///user_data/tradesUSDT.live.sqlite\n

    For more information regarding usage of the sqlite databases, for example to manually enter or remove trades, please refer to the SQL Cheatsheet.

    "},{"location":"advanced-setup/#multiple-instances-using-docker","title":"Multiple instances using docker","text":"

    To run multiple instances of freqtrade using docker you will need to edit the docker-compose.yml file and add all the instances you want as separate services. Remember, you can separate your configuration into multiple files, so it's a good idea to think about making them modular, then if you need to edit something common to all bots, you can do that in a single config file.

    ---\nversion: '3'\nservices:\n  freqtrade1:\n    image: freqtradeorg/freqtrade:stable\n    # image: freqtradeorg/freqtrade:develop\n    # Use plotting image\n    # image: freqtradeorg/freqtrade:develop_plot\n    # Build step - only needed when additional dependencies are needed\n    # build:\n    #   context: .\n    #   dockerfile: \"./docker/Dockerfile.custom\"\n    restart: always\n    container_name: freqtrade1\n    volumes:\n      - \"./user_data:/freqtrade/user_data\"\n    # Expose api on port 8080 (localhost only)\n    # Please read the https://www.freqtrade.io/en/latest/rest-api/ documentation\n    # before enabling this.\n     ports:\n     - \"127.0.0.1:8080:8080\"\n    # Default command used when running `docker compose up`\n    command: >\n      trade\n      --logfile /freqtrade/user_data/logs/freqtrade1.log\n      --db-url sqlite:////freqtrade/user_data/tradesv3_freqtrade1.sqlite\n      --config /freqtrade/user_data/config.json\n      --config /freqtrade/user_data/config.freqtrade1.json\n      --strategy SampleStrategy\n\n  freqtrade2:\n    image: freqtradeorg/freqtrade:stable\n    # image: freqtradeorg/freqtrade:develop\n    # Use plotting image\n    # image: freqtradeorg/freqtrade:develop_plot\n    # Build step - only needed when additional dependencies are needed\n    # build:\n    #   context: .\n    #   dockerfile: \"./docker/Dockerfile.custom\"\n    restart: always\n    container_name: freqtrade2\n    volumes:\n      - \"./user_data:/freqtrade/user_data\"\n    # Expose api on port 8080 (localhost only)\n    # Please read the https://www.freqtrade.io/en/latest/rest-api/ documentation\n    # before enabling this.\n    ports:\n      - \"127.0.0.1:8081:8080\"\n    # Default command used when running `docker compose up`\n    command: >\n      trade\n      --logfile /freqtrade/user_data/logs/freqtrade2.log\n      --db-url sqlite:////freqtrade/user_data/tradesv3_freqtrade2.sqlite\n      --config /freqtrade/user_data/config.json\n      --config /freqtrade/user_data/config.freqtrade2.json\n      --strategy SampleStrategy\n

    You can use whatever naming convention you want, freqtrade1 and 2 are arbitrary. Note, that you will need to use different database files, port mappings and telegram configurations for each instance, as mentioned above.

    "},{"location":"advanced-setup/#use-a-different-database-system","title":"Use a different database system","text":"

    Freqtrade is using SQLAlchemy, which supports multiple different database systems. As such, a multitude of database systems should be supported. Freqtrade does not depend or install any additional database driver. Please refer to the SQLAlchemy docs on installation instructions for the respective database systems.

    The following systems have been tested and are known to work with freqtrade:

    • sqlite (default)
    • PostgreSQL
    • MariaDB

    Warning

    By using one of the below database systems, you acknowledge that you know how to manage such a system. The freqtrade team will not provide any support with setup or maintenance (or backups) of the below database systems.

    "},{"location":"advanced-setup/#postgresql","title":"PostgreSQL","text":"

    Installation: pip install psycopg2-binary

    Usage: ... --db-url postgresql+psycopg2://<username>:<password>@localhost:5432/<database>

    Freqtrade will automatically create the tables necessary upon startup.

    If you're running different instances of Freqtrade, you must either setup one database per Instance or use different users / schemas for your connections.

    "},{"location":"advanced-setup/#mariadb-mysql","title":"MariaDB / MySQL","text":"

    Freqtrade supports MariaDB by using SQLAlchemy, which supports multiple different database systems.

    Installation: pip install pymysql

    Usage: ... --db-url mysql+pymysql://<username>:<password>@localhost:3306/<database>

    "},{"location":"advanced-setup/#configure-the-bot-running-as-a-systemd-service","title":"Configure the bot running as a systemd service","text":"

    Copy the freqtrade.service file to your systemd user directory (usually ~/.config/systemd/user) and update WorkingDirectory and ExecStart to match your setup.

    Note

    Certain systems (like Raspbian) don't load service unit files from the user directory. In this case, copy freqtrade.service into /etc/systemd/user/ (requires superuser permissions).

    After that you can start the daemon with:

    systemctl --user start freqtrade\n

    For this to be persistent (run when user is logged out) you'll need to enable linger for your freqtrade user.

    sudo loginctl enable-linger \"$USER\"\n

    If you run the bot as a service, you can use systemd service manager as a software watchdog monitoring freqtrade bot state and restarting it in the case of failures. If the internals.sd_notify parameter is set to true in the configuration or the --sd-notify command line option is used, the bot will send keep-alive ping messages to systemd using the sd_notify (systemd notifications) protocol and will also tell systemd its current state (Running or Stopped) when it changes.

    The freqtrade.service.watchdog file contains an example of the service unit configuration file which uses systemd as the watchdog.

    Note

    The sd_notify communication between the bot and the systemd service manager will not work if the bot runs in a Docker container.

    "},{"location":"advanced-setup/#advanced-logging","title":"Advanced Logging","text":"

    On many Linux systems the bot can be configured to send its log messages to syslog or journald system services. Logging to a remote syslog server is also available on Windows. The special values for the --logfile command line option can be used for this.

    "},{"location":"advanced-setup/#logging-to-syslog","title":"Logging to syslog","text":"

    To send Freqtrade log messages to a local or remote syslog service use the --logfile command line option with the value in the following format:

    • --logfile syslog:<syslog_address> -- send log messages to syslog service using the <syslog_address> as the syslog address.

    The syslog address can be either a Unix domain socket (socket filename) or a UDP socket specification, consisting of IP address and UDP port, separated by the : character.

    So, the following are the examples of possible usages:

    • --logfile syslog:/dev/log -- log to syslog (rsyslog) using the /dev/log socket, suitable for most systems.
    • --logfile syslog -- same as above, the shortcut for /dev/log.
    • --logfile syslog:/var/run/syslog -- log to syslog (rsyslog) using the /var/run/syslog socket. Use this on MacOS.
    • --logfile syslog:localhost:514 -- log to local syslog using UDP socket, if it listens on port 514.
    • --logfile syslog:<ip>:514 -- log to remote syslog at IP address and port 514. This may be used on Windows for remote logging to an external syslog server.

    Log messages are send to syslog with the user facility. So you can see them with the following commands:

    • tail -f /var/log/user, or
    • install a comprehensive graphical viewer (for instance, 'Log File Viewer' for Ubuntu).

    On many systems syslog (rsyslog) fetches data from journald (and vice versa), so both --logfile syslog or --logfile journald can be used and the messages be viewed with both journalctl and a syslog viewer utility. You can combine this in any way which suites you better.

    For rsyslog the messages from the bot can be redirected into a separate dedicated log file. To achieve this, add

    if $programname startswith \"freqtrade\" then -/var/log/freqtrade.log\n

    to one of the rsyslog configuration files, for example at the end of the /etc/rsyslog.d/50-default.conf.

    For syslog (rsyslog), the reduction mode can be switched on. This will reduce the number of repeating messages. For instance, multiple bot Heartbeat messages will be reduced to a single message when nothing else happens with the bot. To achieve this, set in /etc/rsyslog.conf:

    # Filter duplicated messages\n$RepeatedMsgReduction on\n
    "},{"location":"advanced-setup/#logging-to-journald","title":"Logging to journald","text":"

    This needs the cysystemd python package installed as dependency (pip install cysystemd), which is not available on Windows. Hence, the whole journald logging functionality is not available for a bot running on Windows.

    To send Freqtrade log messages to journald system service use the --logfile command line option with the value in the following format:

    • --logfile journald -- send log messages to journald.

    Log messages are send to journald with the user facility. So you can see them with the following commands:

    • journalctl -f -- shows Freqtrade log messages sent to journald along with other log messages fetched by journald.
    • journalctl -f -u freqtrade.service -- this command can be used when the bot is run as a systemd service.

    There are many other options in the journalctl utility to filter the messages, see manual pages for this utility.

    On many systems syslog (rsyslog) fetches data from journald (and vice versa), so both --logfile syslog or --logfile journald can be used and the messages be viewed with both journalctl and a syslog viewer utility. You can combine this in any way which suites you better.

    "},{"location":"backtesting/","title":"Backtesting","text":"

    This page explains how to validate your strategy performance by using Backtesting.

    Backtesting requires historic data to be available. To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    "},{"location":"backtesting/#backtesting-command-reference","title":"Backtesting command reference","text":"
    usage: freqtrade backtesting [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                             [-d PATH] [--userdir PATH] [-s NAME]\n                             [--strategy-path PATH] [-i TIMEFRAME]\n                             [--timerange TIMERANGE]\n                             [--data-format-ohlcv {json,jsongz,hdf5}]\n                             [--max-open-trades INT]\n                             [--stake-amount STAKE_AMOUNT] [--fee FLOAT]\n                             [-p PAIRS [PAIRS ...]] [--eps] [--dmmp]\n                             [--enable-protections]\n                             [--dry-run-wallet DRY_RUN_WALLET]\n                             [--timeframe-detail TIMEFRAME_DETAIL]\n                             [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]\n                             [--export {none,trades,signals}]\n                             [--export-filename PATH]\n                             [--breakdown {day,week,month} [{day,week,month} ...]]\n                             [--cache {none,day,week,month}]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --max-open-trades INT\n                        Override the value of the `max_open_trades`\n                        configuration setting.\n  --stake-amount STAKE_AMOUNT\n                        Override the value of the `stake_amount` configuration\n                        setting.\n  --fee FLOAT           Specify fee ratio. Will be applied twice (on trade\n                        entry and exit).\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --eps, --enable-position-stacking\n                        Allow buying the same pair multiple times (position\n                        stacking).\n  --dmmp, --disable-max-market-positions\n                        Disable applying `max_open_trades` during backtest\n                        (same as setting `max_open_trades` to a very high\n                        number).\n  --enable-protections, --enableprotections\n                        Enable protections for backtesting.Will slow\n                        backtesting down by a considerable amount, but will\n                        include configured protections\n  --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET\n                        Starting balance, used for backtesting / hyperopt and\n                        dry-runs.\n  --timeframe-detail TIMEFRAME_DETAIL\n                        Specify detail timeframe for backtesting (`1m`, `5m`,\n                        `30m`, `1h`, `1d`).\n  --strategy-list STRATEGY_LIST [STRATEGY_LIST ...]\n                        Provide a space-separated list of strategies to\n                        backtest. Please note that timeframe needs to be set\n                        either in config or via command line. When using this\n                        together with `--export trades`, the strategy-name is\n                        injected into the filename (so `backtest-data.json`\n                        becomes `backtest-data-SampleStrategy.json`\n  --export {none,trades,signals}\n                        Export backtest results (default: trades).\n  --export-filename PATH, --backtest-filename PATH\n                        Use this filename for backtest results.Requires\n                        `--export` to be set as well. Example: `--export-filen\n                        ame=user_data/backtest_results/backtest_today.json`\n  --breakdown {day,week,month} [{day,week,month} ...]\n                        Show backtesting breakdown per [day, week, month].\n  --cache {none,day,week,month}\n                        Load a cached backtest result no older than specified\n                        age (default: day).\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n
    "},{"location":"backtesting/#test-your-strategy-with-backtesting","title":"Test your strategy with Backtesting","text":"

    Now you have good Entry and exit strategies and some historic data, you want to test it against real data. This is what we call backtesting.

    Backtesting will use the crypto-currencies (pairs) from your config file and load historical candle (OHLCV) data from user_data/data/<exchange> by default. If no data is available for the exchange / pair / timeframe combination, backtesting will ask you to download them first using freqtrade download-data. For details on downloading, please refer to the Data Downloading section in the documentation.

    The result of backtesting will confirm if your bot has better odds of making a profit than a loss.

    All profit calculations include fees, and freqtrade will use the exchange's default fees for the calculation.

    Using dynamic pairlists for backtesting

    Using dynamic pairlists is possible (not all of the handlers are allowed to be used in backtest mode), however it relies on the current market conditions - which will not reflect the historic status of the pairlist. Also, when using pairlists other than StaticPairlist, reproducibility of backtesting-results cannot be guaranteed. Please read the pairlists documentation for more information.

    To achieve reproducible results, best generate a pairlist via the test-pairlist command and use that as static pairlist.

    Note

    By default, Freqtrade will export backtesting results to user_data/backtest_results. The exported trades can be used for further analysis or can be used by the plotting sub-command (freqtrade plot-dataframe) in the scripts directory.

    "},{"location":"backtesting/#starting-balance","title":"Starting balance","text":"

    Backtesting will require a starting balance, which can be provided as --dry-run-wallet <balance> or --starting-balance <balance> command line argument, or via dry_run_wallet configuration setting. This amount must be higher than stake_amount, otherwise the bot will not be able to simulate any trade.

    "},{"location":"backtesting/#dynamic-stake-amount","title":"Dynamic stake amount","text":"

    Backtesting supports dynamic stake amount by configuring stake_amount as \"unlimited\", which will split the starting balance into max_open_trades pieces. Profits from early trades will result in subsequent higher stake amounts, resulting in compounding of profits over the backtesting period.

    "},{"location":"backtesting/#example-backtesting-commands","title":"Example backtesting commands","text":"

    With 5 min candle (OHLCV) data (per default)

    freqtrade backtesting --strategy AwesomeStrategy\n

    Where --strategy AwesomeStrategy / -s AwesomeStrategy refers to the class name of the strategy, which is within a python file in the user_data/strategies directory.

    With 1 min candle (OHLCV) data

    freqtrade backtesting --strategy AwesomeStrategy --timeframe 1m\n

    Providing a custom starting balance of 1000 (in stake currency)

    freqtrade backtesting --strategy AwesomeStrategy --dry-run-wallet 1000\n

    Using a different on-disk historical candle (OHLCV) data source

    Assume you downloaded the history data from the Binance exchange and kept it in the user_data/data/binance-20180101 directory. You can then use this data for backtesting as follows:

    freqtrade backtesting --strategy AwesomeStrategy --datadir user_data/data/binance-20180101 \n

    Comparing multiple Strategies

    freqtrade backtesting --strategy-list SampleStrategy1 AwesomeStrategy --timeframe 5m\n

    Where SampleStrategy1 and AwesomeStrategy refer to class names of strategies.

    Prevent exporting trades to file

    freqtrade backtesting --strategy backtesting --export none --config config.json \n

    Only use this if you're sure you'll not want to plot or analyze your results further.

    Exporting trades to file specifying a custom filename

    freqtrade backtesting --strategy backtesting --export trades --export-filename=backtest_samplestrategy.json\n

    Please also read about the strategy startup period.

    Supplying custom fee value

    Sometimes your account has certain fee rebates (fee reductions starting with a certain account size or monthly volume), which are not visible to ccxt. To account for this in backtesting, you can use the --fee command line option to supply this value to backtesting. This fee must be a ratio, and will be applied twice (once for trade entry, and once for trade exit).

    For example, if the commission fee per order is 0.1% (i.e., 0.001 written as ratio), then you would run backtesting as the following:

    freqtrade backtesting --fee 0.001\n

    Note

    Only supply this option (or the corresponding configuration parameter) if you want to experiment with different fee values. By default, Backtesting fetches the default fee from the exchange pair/market info.

    Running backtest with smaller test-set by using timerange

    Use the --timerange argument to change how much of the test-set you want to use.

    For example, running backtesting with the --timerange=20190501- option will use all available data starting with May 1st, 2019 from your input data.

    freqtrade backtesting --timerange=20190501-\n

    You can also specify particular date ranges.

    The full timerange specification:

    • Use data until 2018/01/31: --timerange=-20180131
    • Use data since 2018/01/31: --timerange=20180131-
    • Use data since 2018/01/31 till 2018/03/01 : --timerange=20180131-20180301
    • Use data between POSIX / epoch timestamps 1527595200 1527618600: --timerange=1527595200-1527618600
    "},{"location":"backtesting/#understand-the-backtesting-result","title":"Understand the backtesting result","text":"

    The most important in the backtesting is to understand the result.

    A backtesting result will look like that:

    ================================================ BACKTESTING REPORT =================================================\n| Pair     | Trades |   Avg Profit % |   Tot Profit BTC |   Tot Profit % | Avg Duration |  Wins Draws Loss   Win%  |\n|----------+--------+----------------+------------------+----------------+--------------+--------------------------|\n| ADA/BTC  |     35 |          -0.11 |      -0.00019428 |          -1.94 | 4:35:00      |    14     0    21   40.0 |\n| ARK/BTC  |     11 |          -0.41 |      -0.00022647 |          -2.26 | 2:03:00      |     3     0     8   27.3 |\n| BTS/BTC  |     32 |           0.31 |       0.00048938 |           4.89 | 5:05:00      |    18     0    14   56.2 |\n| DASH/BTC |     13 |          -0.08 |      -0.00005343 |          -0.53 | 4:39:00      |     6     0     7   46.2 |\n| ENG/BTC  |     18 |           1.36 |       0.00122807 |          12.27 | 2:50:00      |     8     0    10   44.4 |\n| EOS/BTC  |     36 |           0.08 |       0.00015304 |           1.53 | 3:34:00      |    16     0    20   44.4 |\n| ETC/BTC  |     26 |           0.37 |       0.00047576 |           4.75 | 6:14:00      |    11     0    15   42.3 |\n| ETH/BTC  |     33 |           0.30 |       0.00049856 |           4.98 | 7:31:00      |    16     0    17   48.5 |\n| IOTA/BTC |     32 |           0.03 |       0.00005444 |           0.54 | 3:12:00      |    14     0    18   43.8 |\n| LSK/BTC  |     15 |           1.75 |       0.00131413 |          13.13 | 2:58:00      |     6     0     9   40.0 |\n| LTC/BTC  |     32 |          -0.04 |      -0.00006886 |          -0.69 | 4:49:00      |    11     0    21   34.4 |\n| NANO/BTC |     17 |           1.26 |       0.00107058 |          10.70 | 1:55:00      |    10     0     7   58.5 |\n| NEO/BTC  |     23 |           0.82 |       0.00094936 |           9.48 | 2:59:00      |    10     0    13   43.5 |\n| REQ/BTC  |      9 |           1.17 |       0.00052734 |           5.27 | 3:47:00      |     4     0     5   44.4 |\n| XLM/BTC  |     16 |           1.22 |       0.00097800 |           9.77 | 3:15:00      |     7     0     9   43.8 |\n| XMR/BTC  |     23 |          -0.18 |      -0.00020696 |          -2.07 | 5:30:00      |    12     0    11   52.2 |\n| XRP/BTC  |     35 |           0.66 |       0.00114897 |          11.48 | 3:49:00      |    12     0    23   34.3 |\n| ZEC/BTC  |     22 |          -0.46 |      -0.00050971 |          -5.09 | 2:22:00      |     7     0    15   31.8 |\n| TOTAL    |    429 |           0.36 |       0.00762792 |          76.20 | 4:12:00      |   186     0   243   43.4 |\n============================================= LEFT OPEN TRADES REPORT =============================================\n| Pair     |  Trades |   Avg Profit % |   Tot Profit BTC |   Tot Profit % | Avg Duration   |  Win Draw Loss Win% |\n|----------+---------+----------------+------------------+----------------+----------------+---------------------|\n| ADA/BTC  |       1 |           0.89 |       0.00004434 |           0.44 | 6:00:00        |    1    0    0  100 |\n| LTC/BTC  |       1 |           0.68 |       0.00003421 |           0.34 | 2:00:00        |    1    0    0  100 |\n| TOTAL    |       2 |           0.78 |       0.00007855 |           0.78 | 4:00:00        |    2    0    0  100 |\n==================== EXIT REASON STATS ====================\n| Exit Reason        |   Exits |  Wins |  Draws |  Losses |\n|--------------------+---------+-------+--------+---------|\n| trailing_stop_loss |     205 |   150 |      0 |      55 |\n| stop_loss          |     166 |     0 |      0 |     166 |\n| exit_signal        |      56 |    36 |      0 |      20 |\n| force_exit         |       2 |     0 |      0 |       2 |\n\n================== SUMMARY METRICS ==================\n| Metric                      | Value               |\n|-----------------------------+---------------------|\n| Backtesting from            | 2019-01-01 00:00:00 |\n| Backtesting to              | 2019-05-01 00:00:00 |\n| Trading Mode                | Spot                |\n| Max open trades             | 3                   |\n|                             |                     |\n| Total/Daily Avg Trades      | 429 / 3.575         |\n| Starting balance            | 0.01000000 BTC      |\n| Final balance               | 0.01762792 BTC      |\n| Absolute profit             | 0.00762792 BTC      |\n| Total profit %              | 76.2%               |\n| CAGR %                      | 460.87%             |\n| Sortino                     | 1.88                |\n| Sharpe                      | 2.97                |\n| Calmar                      | 6.29                |\n| Profit factor               | 1.11                |\n| Expectancy (Ratio)          | -0.15 (-0.05)       |\n| Avg. stake amount           | 0.001      BTC      |\n| Total trade volume          | 0.429      BTC      |\n|                             |                     |\n| Long / Short                | 352 / 77            |\n| Total profit Long %         | 1250.58%            |\n| Total profit Short %        | -15.02%             |\n| Absolute profit Long        | 0.00838792 BTC      |\n| Absolute profit Short       | -0.00076 BTC        |\n|                             |                     |\n| Best Pair                   | LSK/BTC 26.26%      |\n| Worst Pair                  | ZEC/BTC -10.18%     |\n| Best Trade                  | LSK/BTC 4.25%       |\n| Worst Trade                 | ZEC/BTC -10.25%     |\n| Best day                    | 0.00076 BTC         |\n| Worst day                   | -0.00036 BTC        |\n| Days win/draw/lose          | 12 / 82 / 25        |\n| Avg. Duration Winners       | 4:23:00             |\n| Avg. Duration Loser         | 6:55:00             |\n| Max Consecutive Wins / Loss | 3 / 4               |\n| Rejected Entry signals      | 3089                |\n| Entry/Exit Timeouts         | 0 / 0               |\n| Canceled Trade Entries      | 34                  |\n| Canceled Entry Orders       | 123                 |\n| Replaced Entry Orders       | 89                  |\n|                             |                     |\n| Min balance                 | 0.00945123 BTC      |\n| Max balance                 | 0.01846651 BTC      |\n| Max % of account underwater | 25.19%              |\n| Absolute Drawdown (Account) | 13.33%              |\n| Drawdown                    | 0.0015 BTC          |\n| Drawdown high               | 0.0013 BTC          |\n| Drawdown low                | -0.0002 BTC         |\n| Drawdown Start              | 2019-02-15 14:10:00 |\n| Drawdown End                | 2019-04-11 18:15:00 |\n| Market change               | -5.88%              |\n=====================================================\n
    "},{"location":"backtesting/#backtesting-report-table","title":"Backtesting report table","text":"

    The 1st table contains all trades the bot made, including \"left open trades\".

    The last line will give you the overall performance of your strategy, here:

    | TOTAL    |    429 |           0.36 |         152.41 |       0.00762792 |          76.20 | 4:12:00      |   186     0   243   43.4 |\n

    The bot has made 429 trades for an average duration of 4:12:00, with a performance of 76.20% (profit), that means it has earned a total of 0.00762792 BTC starting with a capital of 0.01 BTC.

    The column Avg Profit % shows the average profit for all trades made. The column Tot Profit % shows instead the total profit % in relation to the starting balance. In the above results, we have a starting balance of 0.01 BTC and an absolute profit of 0.00762792 BTC - so the Tot Profit % will be (0.00762792 / 0.01) * 100 ~= 76.2%.

    Your strategy performance is influenced by your entry strategy, your exit strategy, and also by the minimal_roi and stop_loss you have set.

    For example, if your minimal_roi is only \"0\": 0.01 you cannot expect the bot to make more profit than 1% (because it will exit every time a trade reaches 1%).

    \"minimal_roi\": {\n    \"0\":  0.01\n},\n

    On the other hand, if you set a too high minimal_roi like \"0\": 0.55 (55%), there is almost no chance that the bot will ever reach this profit. Hence, keep in mind that your performance is an integral mix of all different elements of the strategy, your configuration, and the crypto-currency pairs you have set up.

    "},{"location":"backtesting/#exit-reasons-table","title":"Exit reasons table","text":"

    The 2nd table contains a recap of exit reasons. This table can tell you which area needs some additional work (e.g. all or many of the exit_signal trades are losses, so you should work on improving the exit signal, or consider disabling it).

    "},{"location":"backtesting/#left-open-trades-table","title":"Left open trades table","text":"

    The 3rd table contains all trades the bot had to force_exit at the end of the backtesting period to present you the full picture. This is necessary to simulate realistic behavior, since the backtest period has to end at some point, while realistically, you could leave the bot running forever. These trades are also included in the first table, but are also shown separately in this table for clarity.

    "},{"location":"backtesting/#summary-metrics","title":"Summary metrics","text":"

    The last element of the backtest report is the summary metrics table. It contains some useful key metrics about performance of your strategy on backtesting data.

    ================== SUMMARY METRICS ==================\n| Metric                      | Value               |\n|-----------------------------+---------------------|\n| Backtesting from            | 2019-01-01 00:00:00 |\n| Backtesting to              | 2019-05-01 00:00:00 |\n| Trading Mode                | Spot                |\n| Max open trades             | 3                   |\n|                             |                     |\n| Total/Daily Avg Trades      | 429 / 3.575         |\n| Starting balance            | 0.01000000 BTC      |\n| Final balance               | 0.01762792 BTC      |\n| Absolute profit             | 0.00762792 BTC      |\n| Total profit %              | 76.2%               |\n| CAGR %                      | 460.87%             |\n| Sortino                     | 1.88                |\n| Sharpe                      | 2.97                |\n| Calmar                      | 6.29                |\n| Profit factor               | 1.11                |\n| Expectancy (Ratio)          | -0.15 (-0.05)       |\n| Avg. stake amount           | 0.001      BTC      |\n| Total trade volume          | 0.429      BTC      |\n|                             |                     |\n| Long / Short                | 352 / 77            |\n| Total profit Long %         | 1250.58%            |\n| Total profit Short %        | -15.02%             |\n| Absolute profit Long        | 0.00838792 BTC      |\n| Absolute profit Short       | -0.00076 BTC        |\n|                             |                     |\n| Best Pair                   | LSK/BTC 26.26%      |\n| Worst Pair                  | ZEC/BTC -10.18%     |\n| Best Trade                  | LSK/BTC 4.25%       |\n| Worst Trade                 | ZEC/BTC -10.25%     |\n| Best day                    | 0.00076 BTC         |\n| Worst day                   | -0.00036 BTC        |\n| Days win/draw/lose          | 12 / 82 / 25        |\n| Avg. Duration Winners       | 4:23:00             |\n| Avg. Duration Loser         | 6:55:00             |\n| Max Consecutive Wins / Loss | 3 / 4               |\n| Rejected Entry signals      | 3089                |\n| Entry/Exit Timeouts         | 0 / 0               |\n| Canceled Trade Entries      | 34                  |\n| Canceled Entry Orders       | 123                 |\n| Replaced Entry Orders       | 89                  |\n|                             |                     |\n| Min balance                 | 0.00945123 BTC      |\n| Max balance                 | 0.01846651 BTC      |\n| Max % of account underwater | 25.19%              |\n| Absolute Drawdown (Account) | 13.33%              |\n| Drawdown                    | 0.0015 BTC          |\n| Drawdown high               | 0.0013 BTC          |\n| Drawdown low                | -0.0002 BTC         |\n| Drawdown Start              | 2019-02-15 14:10:00 |\n| Drawdown End                | 2019-04-11 18:15:00 |\n| Market change               | -5.88%              |\n=====================================================\n
    • Backtesting from / Backtesting to: Backtesting range (usually defined with the --timerange option).
    • Max open trades: Setting of max_open_trades (or --max-open-trades) - or number of pairs in the pairlist (whatever is lower).
    • Trading Mode: Spot or Futures trading.
    • Total/Daily Avg Trades: Identical to the total trades of the backtest output table / Total trades divided by the backtesting duration in days (this will give you information about how many trades to expect from the strategy).
    • Starting balance: Start balance - as given by dry-run-wallet (config or command line).
    • Final balance: Final balance - starting balance + absolute profit.
    • Absolute profit: Profit made in stake currency.
    • Total profit %: Total profit. Aligned to the TOTAL row's Tot Profit % from the first table. Calculated as (End capital \u2212 Starting capital) / Starting capital.
    • CAGR %: Compound annual growth rate.
    • Sortino: Annualized Sortino ratio.
    • Sharpe: Annualized Sharpe ratio.
    • Calmar: Annualized Calmar ratio.
    • Profit factor: profit / loss.
    • Avg. stake amount: Average stake amount, either stake_amount or the average when using dynamic stake amount.
    • Total trade volume: Volume generated on the exchange to reach the above profit.
    • Best Pair / Worst Pair: Best and worst performing pair, and it's corresponding Tot Profit %.
    • Best Trade / Worst Trade: Biggest single winning trade and biggest single losing trade.
    • Best day / Worst day: Best and worst day based on daily profit.
    • Days win/draw/lose: Winning / Losing days (draws are usually days without closed trade).
    • Avg. Duration Winners / Avg. Duration Loser: Average durations for winning and losing trades.
    • Max Consecutive Wins / Loss: Maximum consecutive wins/losses in a row.
    • Rejected Entry signals: Trade entry signals that could not be acted upon due to max_open_trades being reached.
    • Entry/Exit Timeouts: Entry/exit orders which did not fill (only applicable if custom pricing is used).
    • Canceled Trade Entries: Number of trades that have been canceled by user request via adjust_entry_price.
    • Canceled Entry Orders: Number of entry orders that have been canceled by user request via adjust_entry_price.
    • Replaced Entry Orders: Number of entry orders that have been replaced by user request via adjust_entry_price.
    • Min balance / Max balance: Lowest and Highest Wallet balance during the backtest period.
    • Max % of account underwater: Maximum percentage your account has decreased from the top since the simulation started. Calculated as the maximum of (Max Balance - Current Balance) / (Max Balance).
    • Absolute Drawdown (Account): Maximum Account Drawdown experienced. Calculated as (Absolute Drawdown) / (DrawdownHigh + startingBalance).
    • Drawdown: Maximum, absolute drawdown experienced. Difference between Drawdown High and Subsequent Low point.
    • Drawdown high / Drawdown low: Profit at the beginning and end of the largest drawdown period. A negative low value means initial capital lost.
    • Drawdown Start / Drawdown End: Start and end datetime for this largest drawdown (can also be visualized via the plot-dataframe sub-command).
    • Market change: Change of the market during the backtest period. Calculated as average of all pairs changes from the first to the last candle using the \"close\" column.
    • Long / Short: Split long/short values (Only shown when short trades were made).
    • Total profit Long % / Absolute profit Long: Profit long trades only (Only shown when short trades were made).
    • Total profit Short % / Absolute profit Short: Profit short trades only (Only shown when short trades were made).
    "},{"location":"backtesting/#daily-weekly-monthly-breakdown","title":"Daily / Weekly / Monthly breakdown","text":"

    You can get an overview over daily / weekly or monthly results by using the --breakdown <> switch.

    To visualize daily and weekly breakdowns, you can use the following:

    freqtrade backtesting --strategy MyAwesomeStrategy --breakdown day week\n
    ======================== DAY BREAKDOWN =========================\n|        Day |   Tot Profit USDT |   Wins |   Draws |   Losses |\n|------------+-------------------+--------+---------+----------|\n| 03/07/2021 |           200.0   |      2 |       0 |        0 |\n| 04/07/2021 |           -50.31  |      0 |       0 |        2 |\n| 05/07/2021 |           220.611 |      3 |       2 |        0 |\n| 06/07/2021 |           150.974 |      3 |       0 |        2 |\n| 07/07/2021 |           -70.193 |      1 |       0 |        2 |\n| 08/07/2021 |           212.413 |      2 |       0 |        3 |\n

    The output will show a table containing the realized absolute Profit (in stake currency) for the given timeperiod, as well as wins, draws and losses that materialized (closed) on this day. Below that there will be a second table for the summarized values of weeks indicated by the date of the closing Sunday. The same would apply to a monthly breakdown indicated by the last day of the month.

    "},{"location":"backtesting/#backtest-result-caching","title":"Backtest result caching","text":"

    To save time, by default backtest will reuse a cached result from within the last day when the backtested strategy and config match that of a previous backtest. To force a new backtest despite existing result for an identical run specify --cache none parameter.

    Warning

    Caching is automatically disabled for open-ended timeranges (--timerange 20210101-), as freqtrade cannot ensure reliably that the underlying data didn't change. It can also use cached results where it shouldn't if the original backtest had missing data at the end, which was fixed by downloading more data. In this instance, please use --cache none once to force a fresh backtest.

    "},{"location":"backtesting/#further-backtest-result-analysis","title":"Further backtest-result analysis","text":"

    To further analyze your backtest results, freqtrade will export the trades to file by default. You can then load the trades to perform further analysis as shown in the data analysis backtesting section.

    "},{"location":"backtesting/#assumptions-made-by-backtesting","title":"Assumptions made by backtesting","text":"

    Since backtesting lacks some detailed information about what happens within a candle, it needs to take a few assumptions:

    • Exchange trading limits are respected
    • Entries happen at open-price unless a custom price logic has been specified
    • All orders are filled at the requested price (no slippage) as long as the price is within the candle's high/low range
    • Exit-signal exits happen at open-price of the consecutive candle
    • Exits free their trade slot for a new trade with a different pair
    • Exit-signal is favored over Stoploss, because exit-signals are assumed to trigger on candle's open
    • ROI
      • Exits are compared to high - but the ROI value is used (e.g. ROI = 2%, high=5% - so the exit will be at 2%)
      • Exits are never \"below the candle\", so a ROI of 2% may result in a exit at 2.4% if low was at 2.4% profit
      • ROI entries which came into effect on the triggering candle (e.g. 120: 0.02 for 1h candles, from 60: 0.05) will use the candle's open as exit rate
      • Force-exits caused by <N>=-1 ROI entries use low as exit value, unless N falls on the candle open (e.g. 120: -1 for 1h candles)
    • Stoploss exits happen exactly at stoploss price, even if low was lower, but the loss will be 2 * fees higher than the stoploss price
    • Stoploss is evaluated before ROI within one candle. So you can often see more trades with the stoploss exit reason comparing to the results obtained with the same strategy in the Dry Run/Live Trade modes
    • Low happens before high for stoploss, protecting capital first
    • Trailing stoploss
      • Trailing Stoploss is only adjusted if it's below the candle's low (otherwise it would be triggered)
      • On trade entry candles that trigger trailing stoploss, the \"minimum offset\" (stop_positive_offset) is assumed (instead of high) - and the stop is calculated from this point. This rule is NOT applicable to custom-stoploss scenarios, since there's no information about the stoploss logic available.
      • High happens first - adjusting stoploss
      • Low uses the adjusted stoploss (so exits with large high-low difference are backtested correctly)
      • ROI applies before trailing-stop, ensuring profits are \"top-capped\" at ROI if both ROI and trailing stop applies
    • Exit-reason does not explain if a trade was positive or negative, just what triggered the exit (this can look odd if negative ROI values are used)
    • Evaluation sequence (if multiple signals happen on the same candle)
      • Exit-signal
      • Stoploss
      • ROI
      • Trailing stoploss

    Taking these assumptions, backtesting tries to mirror real trading as closely as possible. However, backtesting will never replace running a strategy in dry-run mode. Also, keep in mind that past results don't guarantee future success.

    In addition to the above assumptions, strategy authors should carefully read the Common Mistakes section, to avoid using data in backtesting which is not available in real market conditions.

    "},{"location":"backtesting/#trading-limits-in-backtesting","title":"Trading limits in backtesting","text":"

    Exchanges have certain trading limits, like minimum (and maximum) base currency, or minimum/maximum stake (quote) currency. These limits are usually listed in the exchange documentation as \"trading rules\" or similar and can be quite different between different pairs.

    Backtesting (as well as live and dry-run) does honor these limits, and will ensure that a stoploss can be placed below this value - so the value will be slightly higher than what the exchange specifies. Freqtrade has however no information about historic limits.

    This can lead to situations where trading-limits are inflated by using a historic price, resulting in minimum amounts > 50$.

    For example:

    BTC minimum tradable amount is 0.001. BTC trades at 22.000$ today (0.001 BTC is related to this) - but the backtesting period includes prices as high as 50.000$. Today's minimum would be 0.001 * 22_000 - or 22$. However the limit could also be 50$ - based on 0.001 * 50_000 in some historic setting.

    "},{"location":"backtesting/#trading-precision-limits","title":"Trading precision limits","text":"

    Most exchanges pose precision limits on both price and amounts, so you cannot buy 1.0020401 of a pair, or at a price of 1.24567123123. Instead, these prices and amounts will be rounded or truncated (based on the exchange definition) to the defined trading precision. The above values may for example be rounded to an amount of 1.002, and a price of 1.24567.

    These precision values are based on current exchange limits (as described in the above section), as historic precision limits are not available.

    "},{"location":"backtesting/#improved-backtest-accuracy","title":"Improved backtest accuracy","text":"

    One big limitation of backtesting is it's inability to know how prices moved intra-candle (was high before close, or vice-versa?). So assuming you run backtesting with a 1h timeframe, there will be 4 prices for that candle (Open, High, Low, Close).

    While backtesting does take some assumptions (read above) about this - this can never be perfect, and will always be biased in one way or the other. To mitigate this, freqtrade can use a lower (faster) timeframe to simulate intra-candle movements.

    To utilize this, you can append --timeframe-detail 5m to your regular backtesting command.

    freqtrade backtesting --strategy AwesomeStrategy --timeframe 1h --timeframe-detail 5m\n

    This will load 1h data as well as 5m data for the timeframe. The strategy will be analyzed with the 1h timeframe, and Entry orders will only be placed at the main timeframe, however Order fills and exit signals will be evaluated at the 5m candle, simulating intra-candle movements.

    All callback functions (custom_exit(), custom_stoploss(), ... ) will be running for each 5m candle once the trade is opened (so 12 times in the above example of 1h timeframe, and 5m detailed timeframe).

    --timeframe-detail must be smaller than the original timeframe, otherwise backtesting will fail to start.

    Obviously this will require more memory (5m data is bigger than 1h data), and will also impact runtime (depending on the amount of trades and trade durations). Also, data must be available / downloaded already.

    Tip

    You can use this function as the last part of strategy development, to ensure your strategy is not exploiting one of the backtesting assumptions. Strategies that perform similarly well with this mode have a good chance to perform well in dry/live modes too (although only forward-testing (dry-mode) can really confirm a strategy).

    "},{"location":"backtesting/#backtesting-multiple-strategies","title":"Backtesting multiple strategies","text":"

    To compare multiple strategies, a list of Strategies can be provided to backtesting.

    This is limited to 1 timeframe value per run. However, data is only loaded once from disk so if you have multiple strategies you'd like to compare, this will give a nice runtime boost.

    All listed Strategies need to be in the same directory, unless also --recursive-strategy-search is specified, where sub-directories within the strategy directory are also considered.

    freqtrade backtesting --timerange 20180401-20180410 --timeframe 5m --strategy-list Strategy001 Strategy002 --export trades\n

    This will save the results to user_data/backtest_results/backtest-result-<datetime>.json, including results for both Strategy001 and Strategy002. There will be an additional table comparing win/losses of the different strategies (identical to the \"Total\" row in the first table). Detailed output for all strategies one after the other will be available, so make sure to scroll up to see the details per strategy.

    ================================================== STRATEGY SUMMARY ===================================================================\n| Strategy    |  Trades |   Avg Profit % |   Tot Profit BTC |   Tot Profit % | Avg Duration   |  Wins |  Draws | Losses | Drawdown % |\n|-------------+---------+----------------+------------------+----------------+----------------+-------+--------+--------+------------|\n| Strategy1   |     429 |           0.36 |       0.00762792 |          76.20 | 4:12:00        |   186 |      0 |    243 |       45.2 |\n| Strategy2   |    1487 |          -0.13 |      -0.00988917 |         -98.79 | 4:43:00        |   662 |      0 |    825 |     241.68 |\n
    "},{"location":"backtesting/#next-step","title":"Next step","text":"

    Great, your strategy is profitable. What if the bot can give your the optimal parameters to use for your strategy? Your next step is to learn how to find optimal parameters with Hyperopt

    "},{"location":"bot-basics/","title":"Freqtrade basics","text":"

    This page provides you some basic concepts on how Freqtrade works and operates.

    "},{"location":"bot-basics/#freqtrade-terminology","title":"Freqtrade terminology","text":"
    • Strategy: Your trading strategy, telling the bot what to do.
    • Trade: Open position.
    • Open Order: Order which is currently placed on the exchange, and is not yet complete.
    • Pair: Tradable pair, usually in the format of Base/Quote (e.g. XRP/USDT for spot, XRP/USDT:USDT for futures).
    • Timeframe: Candle length to use (e.g. \"5m\", \"1h\", ...).
    • Indicators: Technical indicators (SMA, EMA, RSI, ...).
    • Limit order: Limit orders which execute at the defined limit price or better.
    • Market order: Guaranteed to fill, may move price depending on the order size.
    • Current Profit: Currently pending (unrealized) profit for this trade. This is mainly used throughout the bot and UI.
    • Realized Profit: Already realized profit. Only relevant in combination with partial exits - which also explains the calculation logic for this.
    • Total Profit: Combined realized and unrealized profit. The relative number (%) is calculated against the total investment in this trade.
    "},{"location":"bot-basics/#fee-handling","title":"Fee handling","text":"

    All profit calculations of Freqtrade include fees. For Backtesting / Hyperopt / Dry-run modes, the exchange default fee is used (lowest tier on the exchange). For live operations, fees are used as applied by the exchange (this includes BNB rebates etc.).

    "},{"location":"bot-basics/#pair-naming","title":"Pair naming","text":"

    Freqtrade follows the ccxt naming convention for currencies. Using the wrong naming convention in the wrong market will usually result in the bot not recognizing the pair, usually resulting in errors like \"this pair is not available\".

    "},{"location":"bot-basics/#spot-pair-naming","title":"Spot pair naming","text":"

    For spot pairs, naming will be base/quote (e.g. ETH/USDT).

    "},{"location":"bot-basics/#futures-pair-naming","title":"Futures pair naming","text":"

    For futures pairs, naming will be base/quote:settle (e.g. ETH/USDT:USDT).

    "},{"location":"bot-basics/#bot-execution-logic","title":"Bot execution logic","text":"

    Starting freqtrade in dry-run or live mode (using freqtrade trade) will start the bot and start the bot iteration loop. This will also run the bot_start() callback.

    By default, the bot loop runs every few seconds (internals.process_throttle_secs) and performs the following actions:

    • Fetch open trades from persistence.
    • Calculate current list of tradable pairs.
    • Download OHLCV data for the pairlist including all informative pairs This step is only executed once per Candle to avoid unnecessary network traffic.
    • Call bot_loop_start() strategy callback.
    • Analyze strategy per pair.
      • Call populate_indicators()
      • Call populate_entry_trend()
      • Call populate_exit_trend()
    • Update trades open order state from exchange.
      • Call order_filled() strategy callback for filled orders.
      • Check timeouts for open orders.
        • Calls check_entry_timeout() strategy callback for open entry orders.
        • Calls check_exit_timeout() strategy callback for open exit orders.
        • Calls adjust_entry_price() strategy callback for open entry orders.
    • Verifies existing positions and eventually places exit orders.
      • Considers stoploss, ROI and exit-signal, custom_exit() and custom_stoploss().
      • Determine exit-price based on exit_pricing configuration setting or by using the custom_exit_price() callback.
      • Before a exit order is placed, confirm_trade_exit() strategy callback is called.
    • Check position adjustments for open trades if enabled by calling adjust_trade_position() and place additional order if required.
    • Check if trade-slots are still available (if max_open_trades is reached).
    • Verifies entry signal trying to enter new positions.
      • Determine entry-price based on entry_pricing configuration setting, or by using the custom_entry_price() callback.
      • In Margin and Futures mode, leverage() strategy callback is called to determine the desired leverage.
      • Determine stake size by calling the custom_stake_amount() callback.
      • Before an entry order is placed, confirm_trade_entry() strategy callback is called.

    This loop will be repeated again and again until the bot is stopped.

    "},{"location":"bot-basics/#backtesting-hyperopt-execution-logic","title":"Backtesting / Hyperopt execution logic","text":"

    backtesting or hyperopt do only part of the above logic, since most of the trading operations are fully simulated.

    • Load historic data for configured pairlist.
    • Calls bot_start() once.
    • Calculate indicators (calls populate_indicators() once per pair).
    • Calculate entry / exit signals (calls populate_entry_trend() and populate_exit_trend() once per pair).
    • Loops per candle simulating entry and exit points.
      • Calls bot_loop_start() strategy callback.
      • Check for Order timeouts, either via the unfilledtimeout configuration, or via check_entry_timeout() / check_exit_timeout() strategy callbacks.
      • Calls adjust_entry_price() strategy callback for open entry orders.
      • Check for trade entry signals (enter_long / enter_short columns).
      • Confirm trade entry / exits (calls confirm_trade_entry() and confirm_trade_exit() if implemented in the strategy).
      • Call custom_entry_price() (if implemented in the strategy) to determine entry price (Prices are moved to be within the opening candle).
      • In Margin and Futures mode, leverage() strategy callback is called to determine the desired leverage.
      • Determine stake size by calling the custom_stake_amount() callback.
      • Check position adjustments for open trades if enabled and call adjust_trade_position() to determine if an additional order is requested.
      • Call order_filled() strategy callback for filled entry orders.
      • Call custom_stoploss() and custom_exit() to find custom exit points.
      • For exits based on exit-signal, custom-exit and partial exits: Call custom_exit_price() to determine exit price (Prices are moved to be within the closing candle).
      • Call order_filled() strategy callback for filled exit orders.
    • Generate backtest report output

    Note

    Both Backtesting and Hyperopt include exchange default Fees in the calculation. Custom fees can be passed to backtesting / hyperopt by specifying the --fee argument.

    Callback call frequency

    Backtesting will call each callback at max. once per candle (--timeframe-detail modifies this behavior to once per detailed candle). Most callbacks will be called once per iteration in live (usually every ~5s) - which can cause backtesting mismatches.

    "},{"location":"bot-usage/","title":"Start the bot","text":"

    This page explains the different parameters of the bot and how to run it.

    Note

    If you've used setup.sh, don't forget to activate your virtual environment (source .venv/bin/activate) before running freqtrade commands.

    Up-to-date clock

    The clock on the system running the bot must be accurate, synchronized to a NTP server frequently enough to avoid problems with communication to the exchanges.

    "},{"location":"bot-usage/#bot-commands","title":"Bot commands","text":"
    usage: freqtrade [-h] [-V]\n                 {trade,create-userdir,new-config,show-config,new-strategy,download-data,convert-data,convert-trade-data,trades-to-ohlcv,list-data,backtesting,backtesting-show,backtesting-analysis,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-markets,list-pairs,list-strategies,list-freqaimodels,list-timeframes,show-trades,test-pairlist,convert-db,install-ui,plot-dataframe,plot-profit,webserver,strategy-updater,lookahead-analysis,recursive-analysis}\n                 ...\n\nFree, open source crypto trading bot\n\npositional arguments:\n  {trade,create-userdir,new-config,show-config,new-strategy,download-data,convert-data,convert-trade-data,trades-to-ohlcv,list-data,backtesting,backtesting-show,backtesting-analysis,edge,hyperopt,hyperopt-list,hyperopt-show,list-exchanges,list-markets,list-pairs,list-strategies,list-freqaimodels,list-timeframes,show-trades,test-pairlist,convert-db,install-ui,plot-dataframe,plot-profit,webserver,strategy-updater,lookahead-analysis,recursive-analysis}\n    trade               Trade module.\n    create-userdir      Create user-data directory.\n    new-config          Create new config\n    show-config         Show resolved config\n    new-strategy        Create new strategy\n    download-data       Download backtesting data.\n    convert-data        Convert candle (OHLCV) data from one format to\n                        another.\n    convert-trade-data  Convert trade data from one format to another.\n    trades-to-ohlcv     Convert trade data to OHLCV data.\n    list-data           List downloaded data.\n    backtesting         Backtesting module.\n    backtesting-show    Show past Backtest results\n    backtesting-analysis\n                        Backtest Analysis module.\n    edge                Edge module.\n    hyperopt            Hyperopt module.\n    hyperopt-list       List Hyperopt results\n    hyperopt-show       Show details of Hyperopt results\n    list-exchanges      Print available exchanges.\n    list-markets        Print markets on exchange.\n    list-pairs          Print pairs on exchange.\n    list-strategies     Print available strategies.\n    list-freqaimodels   Print available freqAI models.\n    list-timeframes     Print available timeframes for the exchange.\n    show-trades         Show trades.\n    test-pairlist       Test your pairlist configuration.\n    convert-db          Migrate database to different system\n    install-ui          Install FreqUI\n    plot-dataframe      Plot candles with indicators.\n    plot-profit         Generate plot showing profits.\n    webserver           Webserver module.\n    strategy-updater    updates outdated strategy files to the current version\n    lookahead-analysis  Check for potential look ahead bias.\n    recursive-analysis  Check for potential recursive formula issue.\n\noptions:\n  -h, --help            show this help message and exit\n  -V, --version         show program's version number and exit\n
    "},{"location":"bot-usage/#bot-trading-commands","title":"Bot trading commands","text":"
    usage: freqtrade trade [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                       [--userdir PATH] [-s NAME] [--strategy-path PATH]\n                       [--db-url PATH] [--sd-notify] [--dry-run]\n                       [--dry-run-wallet DRY_RUN_WALLET]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --sd-notify           Notify systemd service manager.\n  --dry-run             Enforce dry-run for trading (removes Exchange secrets\n                        and simulates trades).\n  --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET\n                        Starting balance, used for backtesting / hyperopt and\n                        dry-runs.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n
    "},{"location":"bot-usage/#how-to-specify-which-configuration-file-be-used","title":"How to specify which configuration file be used?","text":"

    The bot allows you to select which configuration file you want to use by means of the -c/--config command line option:

    freqtrade trade -c path/far/far/away/config.json\n

    Per default, the bot loads the config.json configuration file from the current working directory.

    "},{"location":"bot-usage/#how-to-use-multiple-configuration-files","title":"How to use multiple configuration files?","text":"

    The bot allows you to use multiple configuration files by specifying multiple -c/--config options in the command line. Configuration parameters defined in the latter configuration files override parameters with the same name defined in the previous configuration files specified in the command line earlier.

    For example, you can make a separate configuration file with your key and secret for the Exchange you use for trading, specify default configuration file with empty key and secret values while running in the Dry Mode (which does not actually require them):

    freqtrade trade -c ./config.json\n

    and specify both configuration files when running in the normal Live Trade Mode:

    freqtrade trade -c ./config.json -c path/to/secrets/keys.config.json\n

    This could help you hide your private Exchange key and Exchange secret on you local machine by setting appropriate file permissions for the file which contains actual secrets and, additionally, prevent unintended disclosure of sensitive private data when you publish examples of your configuration in the project issues or in the Internet.

    See more details on this technique with examples in the documentation page on configuration.

    "},{"location":"bot-usage/#where-to-store-custom-data","title":"Where to store custom data","text":"

    Freqtrade allows the creation of a user-data directory using freqtrade create-userdir --userdir someDirectory. This directory will look as follows:

    user_data/\n\u251c\u2500\u2500 backtest_results\n\u251c\u2500\u2500 data\n\u251c\u2500\u2500 hyperopts\n\u251c\u2500\u2500 hyperopt_results\n\u251c\u2500\u2500 plot\n\u2514\u2500\u2500 strategies\n

    You can add the entry \"user_data_dir\" setting to your configuration, to always point your bot to this directory. Alternatively, pass in --userdir to every command. The bot will fail to start if the directory does not exist, but will create necessary subdirectories.

    This directory should contain your custom strategies, custom hyperopts and hyperopt loss functions, backtesting historical data (downloaded using either backtesting command or the download script) and plot outputs.

    It is recommended to use version control to keep track of changes to your strategies.

    "},{"location":"bot-usage/#how-to-use-strategy","title":"How to use --strategy?","text":"

    This parameter will allow you to load your custom strategy class. To test the bot installation, you can use the SampleStrategy installed by the create-userdir subcommand (usually user_data/strategy/sample_strategy.py).

    The bot will search your strategy file within user_data/strategies. To use other directories, please read the next section about --strategy-path.

    To load a strategy, simply pass the class name (e.g.: CustomStrategy) in this parameter.

    Example: In user_data/strategies you have a file my_awesome_strategy.py which has a strategy class called AwesomeStrategy to load it:

    freqtrade trade --strategy AwesomeStrategy\n

    If the bot does not find your strategy file, it will display in an error message the reason (File not found, or errors in your code).

    Learn more about strategy file in Strategy Customization.

    "},{"location":"bot-usage/#how-to-use-strategy-path","title":"How to use --strategy-path?","text":"

    This parameter allows you to add an additional strategy lookup path, which gets checked before the default locations (The passed path must be a directory!):

    freqtrade trade --strategy AwesomeStrategy --strategy-path /some/directory\n
    "},{"location":"bot-usage/#how-to-install-a-strategy","title":"How to install a strategy?","text":"

    This is very simple. Copy paste your strategy file into the directory user_data/strategies or use --strategy-path. And voila, the bot is ready to use it.

    "},{"location":"bot-usage/#how-to-use-db-url","title":"How to use --db-url?","text":"

    When you run the bot in Dry-run mode, per default no transactions are stored in a database. If you want to store your bot actions in a DB using --db-url. This can also be used to specify a custom database in production mode. Example command:

    freqtrade trade -c config.json --db-url sqlite:///tradesv3.dry_run.sqlite\n
    "},{"location":"bot-usage/#next-step","title":"Next step","text":"

    The optimal strategy of the bot will change with time depending of the market trends. The next step is to Strategy Customization.

    "},{"location":"configuration/","title":"Configure the bot","text":"

    Freqtrade has many configurable features and possibilities. By default, these settings are configured via the configuration file (see below).

    "},{"location":"configuration/#the-freqtrade-configuration-file","title":"The Freqtrade configuration file","text":"

    The bot uses a set of configuration parameters during its operation that all together conform to the bot configuration. It normally reads its configuration from a file (Freqtrade configuration file).

    Per default, the bot loads the configuration from the config.json file, located in the current working directory.

    You can specify a different configuration file used by the bot with the -c/--config command-line option.

    If you used the Quick start method for installing the bot, the installation script should have already created the default configuration file (config.json) for you.

    If the default configuration file is not created we recommend to use freqtrade new-config --config user_data/config.json to generate a basic configuration file.

    The Freqtrade configuration file is to be written in JSON format.

    Additionally to the standard JSON syntax, you may use one-line // ... and multi-line /* ... */ comments in your configuration files and trailing commas in the lists of parameters.

    Do not worry if you are not familiar with JSON format -- simply open the configuration file with an editor of your choice, make some changes to the parameters you need, save your changes and, finally, restart the bot or, if it was previously stopped, run it again with the changes you made to the configuration. The bot validates the syntax of the configuration file at startup and will warn you if you made any errors editing it, pointing out problematic lines.

    "},{"location":"configuration/#environment-variables","title":"Environment variables","text":"

    Set options in the Freqtrade configuration via environment variables. This takes priority over the corresponding value in configuration or strategy.

    Environment variables must be prefixed with FREQTRADE__ to be loaded to the freqtrade configuration.

    __ serves as level separator, so the format used should correspond to FREQTRADE__{section}__{key}. As such - an environment variable defined as export FREQTRADE__STAKE_AMOUNT=200 would result in {stake_amount: 200}.

    A more complex example might be export FREQTRADE__EXCHANGE__KEY=<yourExchangeKey> to keep your exchange key secret. This will move the value to the exchange.key section of the configuration. Using this scheme, all configuration settings will also be available as environment variables.

    Please note that Environment variables will overwrite corresponding settings in your configuration, but command line Arguments will always win.

    Common example:

    FREQTRADE__TELEGRAM__CHAT_ID=<telegramchatid>\nFREQTRADE__TELEGRAM__TOKEN=<telegramToken>\nFREQTRADE__EXCHANGE__KEY=<yourExchangeKey>\nFREQTRADE__EXCHANGE__SECRET=<yourExchangeSecret>\n

    Note

    Environment variables detected are logged at startup - so if you can't find why a value is not what you think it should be based on the configuration, make sure it's not loaded from an environment variable.

    Validate combined result

    You can use the show-config subcommand to see the final, combined configuration.

    Loading sequence

    Environment variables are loaded after the initial configuration. As such, you cannot provide the path to the configuration through environment variables. Please use --config path/to/config.json for that. This also applies to user_dir to some degree. while the user directory can be set through environment variables - the configuration will not be loaded from that location.

    "},{"location":"configuration/#multiple-configuration-files","title":"Multiple configuration files","text":"

    Multiple configuration files can be specified and used by the bot or the bot can read its configuration parameters from the process standard input stream.

    You can specify additional configuration files in add_config_files. Files specified in this parameter will be loaded and merged with the initial config file. The files are resolved relative to the initial configuration file. This is similar to using multiple --config parameters, but simpler in usage as you don't have to specify all files for all commands.

    Validate combined result

    You can use the show-config subcommand to see the final, combined configuration.

    Use multiple configuration files to keep secrets secret

    You can use a 2nd configuration file containing your secrets. That way you can share your \"primary\" configuration file, while still keeping your API keys for yourself. The 2nd file should only specify what you intend to override. If a key is in more than one of the configurations, then the \"last specified configuration\" wins (in the above example, config-private.json).

    For one-off commands, you can also use the below syntax by specifying multiple \"--config\" parameters.

    freqtrade trade --config user_data/config1.json --config user_data/config-private.json <...>\n

    The below is equivalent to the example above - but having 2 configuration files in the configuration, for easier reuse.

    user_data/config.json
    \"add_config_files\": [\n    \"config1.json\",\n    \"config-private.json\"\n]\n
    freqtrade trade --config user_data/config.json <...>\n
    config collision handling

    If the same configuration setting takes place in both config.json and config-import.json, then the parent configuration wins. In the below case, max_open_trades would be 3 after the merging - as the reusable \"import\" configuration has this key overwritten.

    user_data/config.json
    {\n    \"max_open_trades\": 3,\n    \"stake_currency\": \"USDT\",\n    \"add_config_files\": [\n        \"config-import.json\"\n    ]\n}\n
    user_data/config-import.json
    {\n    \"max_open_trades\": 10,\n    \"stake_amount\": \"unlimited\",\n}\n

    Resulting combined configuration:

    Result
    {\n    \"max_open_trades\": 3,\n    \"stake_currency\": \"USDT\",\n    \"stake_amount\": \"unlimited\"\n}\n

    If multiple files are in the add_config_files section, then they will be assumed to be at identical levels, having the last occurrence override the earlier config (unless a parent already defined such a key).

    "},{"location":"configuration/#editor-autocomplete-and-validation","title":"Editor autocomplete and validation","text":"

    If you are using an editor that supports JSON schema, you can use the schema provided by Freqtrade to get autocompletion and validation of your configuration file by adding the following line to the top of your configuration file:

    {\n    \"$schema\": \"https://schema.freqtrade.io/schema.json\",\n}\n
    Develop version

    The develop schema is available as https://schema.freqtrade.io/schema_dev.json - though we recommend to stick to the stable version for the best experience.

    "},{"location":"configuration/#configuration-parameters","title":"Configuration parameters","text":"

    The table below will list all configuration parameters available.

    Freqtrade can also load many options via command line (CLI) arguments (check out the commands --help output for details).

    "},{"location":"configuration/#configuration-option-prevalence","title":"Configuration option prevalence","text":"

    The prevalence for all Options is as follows:

    • CLI arguments override any other option
    • Environment Variables
    • Configuration files are used in sequence (the last file wins) and override Strategy configurations.
    • Strategy configurations are only used if they are not set via configuration or command-line arguments. These options are marked with Strategy Override in the below table.
    "},{"location":"configuration/#parameters-table","title":"Parameters table","text":"

    Mandatory parameters are marked as Required, which means that they are required to be set in one of the possible ways.

    Parameter Description max_open_trades Required. Number of open trades your bot is allowed to have. Only one open trade per pair is possible, so the length of your pairlist is another limitation that can apply. If -1 then it is ignored (i.e. potentially unlimited open trades, limited by the pairlist). More information below. Strategy Override. Datatype: Positive integer or -1. stake_currency Required. Crypto-currency used for trading. Datatype: String stake_amount Required. Amount of crypto-currency your bot will use for each trade. Set it to \"unlimited\" to allow the bot to use all available balance. More information below. Datatype: Positive float or \"unlimited\". tradable_balance_ratio Ratio of the total account balance the bot is allowed to trade. More information below. Defaults to 0.99 99%). Datatype: Positive float between 0.1 and 1.0. available_capital Available starting capital for the bot. Useful when running multiple bots on the same exchange account. More information below. Datatype: Positive float. amend_last_stake_amount Use reduced last stake amount if necessary. More information below. Defaults to false. Datatype: Boolean last_stake_amount_min_ratio Defines minimum stake amount that has to be left and executed. Applies only to the last stake amount when it's amended to a reduced value (i.e. if amend_last_stake_amount is set to true). More information below. Defaults to 0.5. Datatype: Float (as ratio) amount_reserve_percent Reserve some amount in min pair stake amount. The bot will reserve amount_reserve_percent + stoploss value when calculating min pair stake amount in order to avoid possible trade refusals. Defaults to 0.05 (5%). Datatype: Positive Float as ratio. timeframe The timeframe to use (e.g 1m, 5m, 15m, 30m, 1h ...). Usually missing in configuration, and specified in the strategy. Strategy Override. Datatype: String fiat_display_currency Fiat currency used to show your profits. More information below. Datatype: String dry_run Required. Define if the bot must be in Dry Run or production mode. Defaults to true. Datatype: Boolean dry_run_wallet Define the starting amount in stake currency for the simulated wallet used by the bot running in Dry Run mode.Defaults to 1000. Datatype: Float cancel_open_orders_on_exit Cancel open orders when the /stop RPC command is issued, Ctrl+C is pressed or the bot dies unexpectedly. When set to true, this allows you to use /stop to cancel unfilled and partially filled orders in the event of a market crash. It does not impact open positions. Defaults to false. Datatype: Boolean process_only_new_candles Enable processing of indicators only when new candles arrive. If false each loop populates the indicators, this will mean the same candle is processed many times creating system load but can be useful of your strategy depends on tick data not only candle. Strategy Override. Defaults to true. Datatype: Boolean minimal_roi Required. Set the threshold as ratio the bot will use to exit a trade. More information below. Strategy Override. Datatype: Dict stoploss Required. Value as ratio of the stoploss used by the bot. More details in the stoploss documentation. Strategy Override. Datatype: Float (as ratio) trailing_stop Enables trailing stoploss (based on stoploss in either configuration or strategy file). More details in the stoploss documentation. Strategy Override. Datatype: Boolean trailing_stop_positive Changes stoploss once profit has been reached. More details in the stoploss documentation. Strategy Override. Datatype: Float trailing_stop_positive_offset Offset on when to apply trailing_stop_positive. Percentage value which should be positive. More details in the stoploss documentation. Strategy Override. Defaults to 0.0 (no offset). Datatype: Float trailing_only_offset_is_reached Only apply trailing stoploss when the offset is reached. stoploss documentation. Strategy Override. Defaults to false. Datatype: Boolean fee Fee used during backtesting / dry-runs. Should normally not be configured, which has freqtrade fall back to the exchange default fee. Set as ratio (e.g. 0.001 = 0.1%). Fee is applied twice for each trade, once when buying, once when selling. Datatype: Float (as ratio) futures_funding_rate User-specified funding rate to be used when historical funding rates are not available from the exchange. This does not overwrite real historical rates. It is recommended that this be set to 0 unless you are testing a specific coin and you understand how the funding rate will affect freqtrade's profit calculations. More information here Defaults to None. Datatype: Float trading_mode Specifies if you want to trade regularly, trade with leverage, or trade contracts whose prices are derived from matching cryptocurrency prices. leverage documentation. Defaults to \"spot\". Datatype: String margin_mode When trading with leverage, this determines if the collateral owned by the trader will be shared or isolated to each trading pair leverage documentation. Datatype: String liquidation_buffer A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price leverage documentation. Defaults to 0.05. Datatype: Float Unfilled timeout unfilledtimeout.entry Required. How long (in minutes or seconds) the bot will wait for an unfilled entry order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. Strategy Override. Datatype: Integer unfilledtimeout.exit Required. How long (in minutes or seconds) the bot will wait for an unfilled exit order to complete, after which the order will be cancelled and repeated at current (new) price, as long as there is a signal. Strategy Override. Datatype: Integer unfilledtimeout.unit Unit to use in unfilledtimeout setting. Note: If you set unfilledtimeout.unit to \"seconds\", \"internals.process_throttle_secs\" must be inferior or equal to timeout Strategy Override. Defaults to \"minutes\". Datatype: String unfilledtimeout.exit_timeout_count How many times can exit orders time out. Once this number of timeouts is reached, an emergency exit is triggered. 0 to disable and allow unlimited order cancels. Strategy Override.Defaults to 0. Datatype: Integer Pricing entry_pricing.price_side Select the side of the spread the bot should look at to get the entry rate. More information below. Defaults to \"same\". Datatype: String (either ask, bid, same or other). entry_pricing.price_last_balance Required. Interpolate the bidding price. More information below. entry_pricing.use_order_book Enable entering using the rates in Order Book Entry. Defaults to true. Datatype: Boolean entry_pricing.order_book_top Bot will use the top N rate in Order Book \"price_side\" to enter a trade. I.e. a value of 2 will allow the bot to pick the 2nd entry in Order Book Entry. Defaults to 1. Datatype: Positive Integer entry_pricing. check_depth_of_market.enabled Do not enter if the difference of buy orders and sell orders is met in Order Book. Check market depth. Defaults to false. Datatype: Boolean entry_pricing. check_depth_of_market.bids_to_ask_delta The difference ratio of buy orders and sell orders found in Order Book. A value below 1 means sell order size is greater, while value greater than 1 means buy order size is higher. Check market depth Defaults to 0. Datatype: Float (as ratio) exit_pricing.price_side Select the side of the spread the bot should look at to get the exit rate. More information below. Defaults to \"same\". Datatype: String (either ask, bid, same or other). exit_pricing.price_last_balance Interpolate the exiting price. More information below. exit_pricing.use_order_book Enable exiting of open trades using Order Book Exit. Defaults to true. Datatype: Boolean exit_pricing.order_book_top Bot will use the top N rate in Order Book \"price_side\" to exit. I.e. a value of 2 will allow the bot to pick the 2nd ask rate in Order Book ExitDefaults to 1. Datatype: Positive Integer custom_price_max_distance_ratio Configure maximum distance ratio between current and custom entry or exit price. Defaults to 0.02 2%). Datatype: Positive float TODO use_exit_signal Use exit signals produced by the strategy in addition to the minimal_roi. Setting this to false disables the usage of \"exit_long\" and \"exit_short\" columns. Has no influence on other exit methods (Stoploss, ROI, callbacks). Strategy Override. Defaults to true. Datatype: Boolean exit_profit_only Wait until the bot reaches exit_profit_offset before taking an exit decision. Strategy Override. Defaults to false. Datatype: Boolean exit_profit_offset Exit-signal is only active above this value. Only active in combination with exit_profit_only=True. Strategy Override. Defaults to 0.0. Datatype: Float (as ratio) ignore_roi_if_entry_signal Do not exit if the entry signal is still active. This setting takes preference over minimal_roi and use_exit_signal. Strategy Override. Defaults to false. Datatype: Boolean ignore_buying_expired_candle_after Specifies the number of seconds until a buy signal is no longer used. Datatype: Integer order_types Configure order-types depending on the action (\"entry\", \"exit\", \"stoploss\", \"stoploss_on_exchange\"). More information below. Strategy Override. Datatype: Dict order_time_in_force Configure time in force for entry and exit orders. More information below. Strategy Override. Datatype: Dict position_adjustment_enable Enables the strategy to use position adjustments (additional buys or sells). More information here. Strategy Override. Defaults to false. Datatype: Boolean max_entry_position_adjustment Maximum additional order(s) for each open trade on top of the first entry Order. Set it to -1 for unlimited additional orders. More information here. Strategy Override. Defaults to -1. Datatype: Positive Integer or -1 Exchange exchange.name Required. Name of the exchange class to use. Datatype: String exchange.key API key to use for the exchange. Only required when you are in production mode.Keep it in secret, do not disclose publicly. Datatype: String exchange.secret API secret to use for the exchange. Only required when you are in production mode.Keep it in secret, do not disclose publicly. Datatype: String exchange.password API password to use for the exchange. Only required when you are in production mode and for exchanges that use password for API requests.Keep it in secret, do not disclose publicly. Datatype: String exchange.uid API uid to use for the exchange. Only required when you are in production mode and for exchanges that use uid for API requests.Keep it in secret, do not disclose publicly. Datatype: String exchange.pair_whitelist List of pairs to use by the bot for trading and to check for potential trades during backtesting. Supports regex pairs as .*/BTC. Not used by VolumePairList. More information. Datatype: List exchange.pair_blacklist List of pairs the bot must absolutely avoid for trading and backtesting. More information. Datatype: List exchange.ccxt_config Additional CCXT parameters passed to both ccxt instances (sync and async). This is usually the correct place for additional ccxt configurations. Parameters may differ from exchange to exchange and are documented in the ccxt documentation. Please avoid adding exchange secrets here (use the dedicated fields instead), as they may be contained in logs. Datatype: Dict exchange.ccxt_sync_config Additional CCXT parameters passed to the regular (sync) ccxt instance. Parameters may differ from exchange to exchange and are documented in the ccxt documentation Datatype: Dict exchange.ccxt_async_config Additional CCXT parameters passed to the async ccxt instance. Parameters may differ from exchange to exchange and are documented in the ccxt documentation Datatype: Dict exchange.enable_ws Enable the usage of Websockets for the exchange. More information.Defaults to true. Datatype: Boolean exchange.markets_refresh_interval The interval in minutes in which markets are reloaded. Defaults to 60 minutes. Datatype: Positive Integer exchange.skip_pair_validation Skip pairlist validation on startup.Defaults to false Datatype: Boolean exchange.skip_open_order_update Skips open order updates on startup should the exchange cause problems. Only relevant in live conditions.Defaults to false Datatype: Boolean exchange.unknown_fee_rate Fallback value to use when calculating trading fees. This can be useful for exchanges which have fees in non-tradable currencies. The value provided here will be multiplied with the \"fee cost\".Defaults to None Datatype:* float exchange.log_responses Log relevant exchange responses. For debug mode only - use with care.Defaults to false Datatype: Boolean experimental.block_bad_exchanges Block exchanges known to not work with freqtrade. Leave on default unless you want to test if that exchange works now. Defaults to true. Datatype: Boolean Plugins edge.* Please refer to edge configuration document for detailed explanation of all possible configuration options. pairlists Define one or more pairlists to be used. More information. Defaults to StaticPairList. Datatype: List of Dicts protections Define one or more protections to be used. More information. Datatype: List of Dicts Telegram telegram.enabled Enable the usage of Telegram. Datatype: Boolean telegram.token Your Telegram bot token. Only required if telegram.enabled is true. Keep it in secret, do not disclose publicly. Datatype: String telegram.chat_id Your personal Telegram account id. Only required if telegram.enabled is true. Keep it in secret, do not disclose publicly. Datatype: String telegram.balance_dust_level Dust-level (in stake currency) - currencies with a balance below this will not be shown by /balance. Datatype: float telegram.reload Allow \"reload\" buttons on telegram messages. Defaults to true. Datatype:* boolean telegram.notification_settings.* Detailed notification settings. Refer to the telegram documentation for details. Datatype: dictionary telegram.allow_custom_messages Enable the sending of Telegram messages from strategies via the dataprovider.send_msg() function. Datatype: Boolean Webhook webhook.enabled Enable usage of Webhook notifications Datatype: Boolean webhook.url URL for the webhook. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.entry Payload to send on entry. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.entry_cancel Payload to send on entry order cancel. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.entry_fill Payload to send on entry order filled. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.exit Payload to send on exit. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.exit_cancel Payload to send on exit order cancel. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.exit_fill Payload to send on exit order filled. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.status Payload to send on status calls. Only required if webhook.enabled is true. See the webhook documentation for more details. Datatype: String webhook.allow_custom_messages Enable the sending of Webhook messages from strategies via the dataprovider.send_msg() function. Datatype: Boolean Rest API / FreqUI / Producer-Consumer api_server.enabled Enable usage of API Server. See the API Server documentation for more details. Datatype: Boolean api_server.listen_ip_address Bind IP address. See the API Server documentation for more details. Datatype: IPv4 api_server.listen_port Bind Port. See the API Server documentation for more details. Datatype: Integer between 1024 and 65535 api_server.verbosity Logging verbosity. info will print all RPC Calls, while \"error\" will only display errors. Datatype: Enum, either info or error. Defaults to info. api_server.username Username for API server. See the API Server documentation for more details. Keep it in secret, do not disclose publicly. Datatype: String api_server.password Password for API server. See the API Server documentation for more details. Keep it in secret, do not disclose publicly. Datatype: String api_server.ws_token API token for the Message WebSocket. See the API Server documentation for more details. Keep it in secret, do not disclose publicly. Datatype: String bot_name Name of the bot. Passed via API to a client - can be shown to distinguish / name bots. Defaults to freqtrade Datatype: String external_message_consumer Enable Producer/Consumer mode for more details. Datatype: Dict Other initial_state Defines the initial application state. If set to stopped, then the bot has to be explicitly started via /start RPC command. Defaults to stopped. Datatype: Enum, either stopped or running force_entry_enable Enables the RPC Commands to force a Trade entry. More information below. Datatype: Boolean disable_dataframe_checks Disable checking the OHLCV dataframe returned from the strategy methods for correctness. Only use when intentionally changing the dataframe and understand what you are doing. Strategy Override. Defaults to False. Datatype: Boolean internals.process_throttle_secs Set the process throttle, or minimum loop duration for one bot iteration loop. Value in second. Defaults to 5 seconds. Datatype: Positive Integer internals.heartbeat_interval Print heartbeat message every N seconds. Set to 0 to disable heartbeat messages. Defaults to 60 seconds. Datatype: Positive Integer or 0 internals.sd_notify Enables use of the sd_notify protocol to tell systemd service manager about changes in the bot state and issue keep-alive pings. See here for more details. Datatype: Boolean strategy Required Defines Strategy class to use. Recommended to be set via --strategy NAME. Datatype: ClassName strategy_path Adds an additional strategy lookup path (must be a directory). Datatype: String recursive_strategy_search Set to true to recursively search sub-directories inside user_data/strategies for a strategy. Datatype: Boolean user_data_dir Directory containing user data. Defaults to ./user_data/. Datatype: String db_url Declares database URL to use. NOTE: This defaults to sqlite:///tradesv3.dryrun.sqlite if dry_run is true, and to sqlite:///tradesv3.sqlite for production instances. Datatype: String, SQLAlchemy connect string logfile Specifies logfile name. Uses a rolling strategy for log file rotation for 10 files with the 1MB limit per file. Datatype: String add_config_files Additional config files. These files will be loaded and merged with the current config file. The files are resolved relative to the initial file. Defaults to []. Datatype: List of strings dataformat_ohlcv Data format to use to store historical candle (OHLCV) data. Defaults to feather. Datatype: String dataformat_trades Data format to use to store historical trades data. Defaults to feather. Datatype: String reduce_df_footprint Recast all numeric columns to float32/int32, with the objective of reducing ram/disk usage (and decreasing train/inference timing in FreqAI). (Currently only affects FreqAI use-cases) Datatype: Boolean. Default: False."},{"location":"configuration/#parameters-in-the-strategy","title":"Parameters in the strategy","text":"

    The following parameters can be set in the configuration file or strategy. Values set in the configuration file always overwrite values set in the strategy.

    • minimal_roi
    • timeframe
    • stoploss
    • max_open_trades
    • trailing_stop
    • trailing_stop_positive
    • trailing_stop_positive_offset
    • trailing_only_offset_is_reached
    • use_custom_stoploss
    • process_only_new_candles
    • order_types
    • order_time_in_force
    • unfilledtimeout
    • disable_dataframe_checks
    • use_exit_signal
    • exit_profit_only
    • exit_profit_offset
    • ignore_roi_if_entry_signal
    • ignore_buying_expired_candle_after
    • position_adjustment_enable
    • max_entry_position_adjustment
    "},{"location":"configuration/#configuring-amount-per-trade","title":"Configuring amount per trade","text":"

    There are several methods to configure how much of the stake currency the bot will use to enter a trade. All methods respect the available balance configuration as explained below.

    "},{"location":"configuration/#minimum-trade-stake","title":"Minimum trade stake","text":"

    The minimum stake amount will depend on exchange and pair and is usually listed in the exchange support pages.

    Assuming the minimum tradable amount for XRP/USD is 20 XRP (given by the exchange), and the price is 0.6\\(, the minimum stake amount to buy this pair is 20 * 0.6 ~= 12. This exchange has also a limit on USD - where all orders must be > 10\\) - which however does not apply in this case.

    To guarantee safe execution, freqtrade will not allow buying with a stake-amount of 10.1$, instead, it'll make sure that there's enough space to place a stoploss below the pair (+ an offset, defined by amount_reserve_percent, which defaults to 5%).

    With a reserve of 5%, the minimum stake amount would be ~12.6$ (12 * (1 + 0.05)). If we take into account a stoploss of 10% on top of that - we'd end up with a value of ~14$ (12.6 / (1 - 0.1)).

    To limit this calculation in case of large stoploss values, the calculated minimum stake-limit will never be more than 50% above the real limit.

    Warning

    Since the limits on exchanges are usually stable and are not updated often, some pairs can show pretty high minimum limits, simply because the price increased a lot since the last limit adjustment by the exchange. Freqtrade adjusts the stake-amount to this value, unless it's > 30% more than the calculated/desired stake-amount - in which case the trade is rejected.

    "},{"location":"configuration/#tradable-balance","title":"Tradable balance","text":"

    By default, the bot assumes that the complete amount - 1% is at it's disposal, and when using dynamic stake amount, it will split the complete balance into max_open_trades buckets per trade. Freqtrade will reserve 1% for eventual fees when entering a trade and will therefore not touch that by default.

    You can configure the \"untouched\" amount by using the tradable_balance_ratio setting.

    For example, if you have 10 ETH available in your wallet on the exchange and tradable_balance_ratio=0.5 (which is 50%), then the bot will use a maximum amount of 5 ETH for trading and considers this as an available balance. The rest of the wallet is untouched by the trades.

    Danger

    This setting should not be used when running multiple bots on the same account. Please look at Available Capital to the bot instead.

    Warning

    The tradable_balance_ratio setting applies to the current balance (free balance + tied up in trades). Therefore, assuming the starting balance of 1000, a configuration with tradable_balance_ratio=0.99 will not guarantee that 10 currency units will always remain available on the exchange. For example, the free amount may reduce to 5 units if the total balance is reduced to 500 (either by a losing streak or by withdrawing balance).

    "},{"location":"configuration/#assign-available-capital","title":"Assign available Capital","text":"

    To fully utilize compounding profits when using multiple bots on the same exchange account, you'll want to limit each bot to a certain starting balance. This can be accomplished by setting available_capital to the desired starting balance.

    Assuming your account has 10000 USDT and you want to run 2 different strategies on this exchange. You'd set available_capital=5000 - granting each bot an initial capital of 5000 USDT. The bot will then split this starting balance equally into max_open_trades buckets. Profitable trades will result in increased stake-sizes for this bot - without affecting the stake-sizes of the other bot.

    Adjusting available_capital requires reloading the configuration to take effect. Adjusting the available_capital adds the difference between the previous available_capital and the new available_capital. Decreasing the available capital when trades are open doesn't exit the trades. The difference is returned to the wallet when the trades conclude. The outcome of this differs depending on the price movement between the adjustment and exiting the trades.

    Incompatible with tradable_balance_ratio

    Setting this option will replace any configuration of tradable_balance_ratio.

    "},{"location":"configuration/#amend-last-stake-amount","title":"Amend last stake amount","text":"

    Assuming we have the tradable balance of 1000 USDT, stake_amount=400, and max_open_trades=3. The bot would open 2 trades and will be unable to fill the last trading slot, since the requested 400 USDT are no longer available since 800 USDT are already tied in other trades.

    To overcome this, the option amend_last_stake_amount can be set to True, which will enable the bot to reduce stake_amount to the available balance to fill the last trade slot.

    In the example above this would mean:

    • Trade1: 400 USDT
    • Trade2: 400 USDT
    • Trade3: 200 USDT

    Note

    This option only applies with Static stake amount - since Dynamic stake amount divides the balances evenly.

    Note

    The minimum last stake amount can be configured using last_stake_amount_min_ratio - which defaults to 0.5 (50%). This means that the minimum stake amount that's ever used is stake_amount * 0.5. This avoids very low stake amounts, that are close to the minimum tradable amount for the pair and can be refused by the exchange.

    "},{"location":"configuration/#static-stake-amount","title":"Static stake amount","text":"

    The stake_amount configuration statically configures the amount of stake-currency your bot will use for each trade.

    The minimal configuration value is 0.0001, however, please check your exchange's trading minimums for the stake currency you're using to avoid problems.

    This setting works in combination with max_open_trades. The maximum capital engaged in trades is stake_amount * max_open_trades. For example, the bot will at most use (0.05 BTC x 3) = 0.15 BTC, assuming a configuration of max_open_trades=3 and stake_amount=0.05.

    Note

    This setting respects the available balance configuration.

    "},{"location":"configuration/#dynamic-stake-amount","title":"Dynamic stake amount","text":"

    Alternatively, you can use a dynamic stake amount, which will use the available balance on the exchange, and divide that equally by the number of allowed trades (max_open_trades).

    To configure this, set stake_amount=\"unlimited\". We also recommend to set tradable_balance_ratio=0.99 (99%) - to keep a minimum balance for eventual fees.

    In this case a trade amount is calculated as:

    currency_balance / (max_open_trades - current_open_trades)\n

    To allow the bot to trade all the available stake_currency in your account (minus tradable_balance_ratio) set

    \"stake_amount\" : \"unlimited\",\n\"tradable_balance_ratio\": 0.99,\n

    Compounding profits

    This configuration will allow increasing/decreasing stakes depending on the performance of the bot (lower stake if the bot is losing, higher stakes if the bot has a winning record since higher balances are available), and will result in profit compounding.

    When using Dry-Run Mode

    When using \"stake_amount\" : \"unlimited\", in combination with Dry-Run, Backtesting or Hyperopt, the balance will be simulated starting with a stake of dry_run_wallet which will evolve. It is therefore important to set dry_run_wallet to a sensible value (like 0.05 or 0.01 for BTC and 1000 or 100 for USDT, for example), otherwise, it may simulate trades with 100 BTC (or more) or 0.05 USDT (or less) at once - which may not correspond to your real available balance or is less than the exchange minimal limit for the order amount for the stake currency.

    "},{"location":"configuration/#dynamic-stake-amount-with-position-adjustment","title":"Dynamic stake amount with position adjustment","text":"

    When you want to use position adjustment with unlimited stakes, you must also implement custom_stake_amount to a return a value depending on your strategy. Typical value would be in the range of 25% - 50% of the proposed stakes, but depends highly on your strategy and how much you wish to leave into the wallet as position adjustment buffer.

    For example if your position adjustment assumes it can do 2 additional buys with the same stake amounts then your buffer should be 66.6667% of the initially proposed unlimited stake amount.

    Or another example if your position adjustment assumes it can do 1 additional buy with 3x the original stake amount then custom_stake_amount should return 25% of proposed stake amount and leave 75% for possible later position adjustments.

    "},{"location":"configuration/#prices-used-for-orders","title":"Prices used for orders","text":"

    Prices for regular orders can be controlled via the parameter structures entry_pricing for trade entries and exit_pricing for trade exits. Prices are always retrieved right before an order is placed, either by querying the exchange tickers or by using the orderbook data.

    Note

    Orderbook data used by Freqtrade are the data retrieved from exchange by the ccxt's function fetch_order_book(), i.e. are usually data from the L2-aggregated orderbook, while the ticker data are the structures returned by the ccxt's fetch_ticker()/fetch_tickers() functions. Refer to the ccxt library documentation for more details.

    Using market orders

    Please read the section Market order pricing section when using market orders.

    "},{"location":"configuration/#entry-price","title":"Entry price","text":""},{"location":"configuration/#enter-price-side","title":"Enter price side","text":"

    The configuration setting entry_pricing.price_side defines the side of the orderbook the bot looks for when buying.

    The following displays an orderbook.

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If entry_pricing.price_side is set to \"bid\", then the bot will use 99 as entry price. In line with that, if entry_pricing.price_side is set to \"ask\", then the bot will use 101 as entry price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    direction Order setting price crosses spread long buy ask 101 yes long buy bid 99 no long buy same 99 no long buy other 101 yes short sell ask 101 no short sell bid 99 yes short sell same 101 no short sell other 99 yes

    Using the other side of the orderbook often guarantees quicker filled orders, but the bot can also end up paying more than what would have been necessary. Taker fees instead of maker fees will most likely apply even when using limit buy orders. Also, prices at the \"other\" side of the spread are higher than prices at the \"bid\" side in the orderbook, so the order behaves similar to a market order (however with a maximum price).

    "},{"location":"configuration/#entry-price-with-orderbook-enabled","title":"Entry price with Orderbook enabled","text":"

    When entering a trade with the orderbook enabled (entry_pricing.use_order_book=True), Freqtrade fetches the entry_pricing.order_book_top entries from the orderbook and uses the entry specified as entry_pricing.order_book_top on the configured side (entry_pricing.price_side) of the orderbook. 1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"configuration/#entry-price-without-orderbook-enabled","title":"Entry price without Orderbook enabled","text":"

    The following section uses side as the configured entry_pricing.price_side (defaults to \"same\").

    When not using orderbook (entry_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's below the last traded price from the ticker. Otherwise (when the side price is above the last price), it calculates a rate between side and last price based on entry_pricing.price_last_balance.

    The entry_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between ask and last price.

    "},{"location":"configuration/#check-depth-of-market","title":"Check depth of market","text":"

    When check depth of market is enabled (entry_pricing.check_depth_of_market.enabled=True), the entry signals are filtered based on the orderbook depth (sum of all amounts) for each orderbook side.

    Orderbook bid (buy) side depth is then divided by the orderbook ask (sell) side depth and the resulting delta is compared to the value of the entry_pricing.check_depth_of_market.bids_to_ask_delta parameter. The entry order is only executed if the orderbook delta is greater than or equal to the configured delta value.

    Note

    A delta value below 1 means that ask (sell) orderbook side depth is greater than the depth of the bid (buy) orderbook side, while a value greater than 1 means opposite (depth of the buy side is higher than the depth of the sell side).

    "},{"location":"configuration/#exit-price","title":"Exit price","text":""},{"location":"configuration/#exit-price-side","title":"Exit price side","text":"

    The configuration setting exit_pricing.price_side defines the side of the spread the bot looks for when exiting a trade.

    The following displays an orderbook:

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If exit_pricing.price_side is set to \"ask\", then the bot will use 101 as exiting price. In line with that, if exit_pricing.price_side is set to \"bid\", then the bot will use 99 as exiting price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    Direction Order setting price crosses spread long sell ask 101 no long sell bid 99 yes long sell same 101 no long sell other 99 yes short buy ask 101 yes short buy bid 99 no short buy same 99 no short buy other 101 yes"},{"location":"configuration/#exit-price-with-orderbook-enabled","title":"Exit price with Orderbook enabled","text":"

    When exiting with the orderbook enabled (exit_pricing.use_order_book=True), Freqtrade fetches the exit_pricing.order_book_top entries in the orderbook and uses the entry specified as exit_pricing.order_book_top from the configured side (exit_pricing.price_side) as trade exit price.

    1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"configuration/#exit-price-without-orderbook-enabled","title":"Exit price without Orderbook enabled","text":"

    The following section uses side as the configured exit_pricing.price_side (defaults to \"ask\").

    When not using orderbook (exit_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's above the last traded price from the ticker. Otherwise (when the side price is below the last price), it calculates a rate between side and last price based on exit_pricing.price_last_balance.

    The exit_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between side and last price.

    "},{"location":"configuration/#market-order-pricing","title":"Market order pricing","text":"

    When using market orders, prices should be configured to use the \"correct\" side of the orderbook to allow realistic pricing detection. Assuming both entry and exits are using market orders, a configuration similar to the following must be used

      \"order_types\": {\n    \"entry\": \"market\",\n    \"exit\": \"market\"\n    // ...\n  },\n  \"entry_pricing\": {\n    \"price_side\": \"other\",\n    // ...\n  },\n  \"exit_pricing\":{\n    \"price_side\": \"other\",\n    // ...\n  },\n

    Obviously, if only one side is using limit orders, different pricing combinations can be used.

    "},{"location":"configuration/#further-configuration-details","title":"Further Configuration details","text":""},{"location":"configuration/#understand-minimal_roi","title":"Understand minimal_roi","text":"

    The minimal_roi configuration parameter is a JSON object where the key is a duration in minutes and the value is the minimum ROI as a ratio. See the example below:

    \"minimal_roi\": {\n    \"40\": 0.0,    # Exit after 40 minutes if the profit is not negative\n    \"30\": 0.01,   # Exit after 30 minutes if there is at least 1% profit\n    \"20\": 0.02,   # Exit after 20 minutes if there is at least 2% profit\n    \"0\":  0.04    # Exit immediately if there is at least 4% profit\n},\n

    Most of the strategy files already include the optimal minimal_roi value. This parameter can be set in either Strategy or Configuration file. If you use it in the configuration file, it will override the minimal_roi value from the strategy file. If it is not set in either Strategy or Configuration, a default of 1000% {\"0\": 10} is used, and minimal ROI is disabled unless your trade generates 1000% profit.

    Special case to forceexit after a specific time

    A special case presents using \"<N>\": -1 as ROI. This forces the bot to exit a trade after N Minutes, no matter if it's positive or negative, so represents a time-limited force-exit.

    "},{"location":"configuration/#understand-force_entry_enable","title":"Understand force_entry_enable","text":"

    The force_entry_enable configuration parameter enables the usage of force-enter (/forcelong, /forceshort) commands via Telegram and REST API. For security reasons, it's disabled by default, and freqtrade will show a warning message on startup if enabled. For example, you can send /forceenter ETH/BTC to the bot, which will result in freqtrade buying the pair and holds it until a regular exit-signal (ROI, stoploss, /forceexit) appears.

    This can be dangerous with some strategies, so use with care.

    See the telegram documentation for details on usage.

    "},{"location":"configuration/#ignoring-expired-candles","title":"Ignoring expired candles","text":"

    When working with larger timeframes (for example 1h or more) and using a low max_open_trades value, the last candle can be processed as soon as a trade slot becomes available. When processing the last candle, this can lead to a situation where it may not be desirable to use the buy signal on that candle. For example, when using a condition in your strategy where you use a cross-over, that point may have passed too long ago for you to start a trade on it.

    In these situations, you can enable the functionality to ignore candles that are beyond a specified period by setting ignore_buying_expired_candle_after to a positive number, indicating the number of seconds after which the buy signal becomes expired.

    For example, if your strategy is using a 1h timeframe, and you only want to buy within the first 5 minutes when a new candle comes in, you can add the following configuration to your strategy:

      {\n    //...\n    \"ignore_buying_expired_candle_after\": 300,\n    // ...\n  }\n

    Note

    This setting resets with each new candle, so it will not prevent sticking-signals from executing on the 2nd or 3rd candle they're active. Best use a \"trigger\" selector for buy signals, which are only active for one candle.

    "},{"location":"configuration/#understand-order_types","title":"Understand order_types","text":"

    The order_types configuration parameter maps actions (entry, exit, stoploss, emergency_exit, force_exit, force_entry) to order-types (market, limit, ...) as well as configures stoploss to be on the exchange and defines stoploss on exchange update interval in seconds.

    This allows to enter using limit orders, exit using limit-orders, and create stoplosses using market orders. It also allows to set the stoploss \"on exchange\" which means stoploss order would be placed immediately once the buy order is fulfilled.

    order_types set in the configuration file overwrites values set in the strategy as a whole, so you need to configure the whole order_types dictionary in one place.

    If this is configured, the following 4 values (entry, exit, stoploss and stoploss_on_exchange) need to be present, otherwise, the bot will fail to start.

    For information on (emergency_exit,force_exit, force_entry, stoploss_on_exchange,stoploss_on_exchange_interval,stoploss_on_exchange_limit_ratio) please see stop loss documentation stop loss on exchange

    Syntax for Strategy:

    order_types = {\n    \"entry\": \"limit\",\n    \"exit\": \"limit\",\n    \"emergency_exit\": \"market\",\n    \"force_entry\": \"market\",\n    \"force_exit\": \"market\",\n    \"stoploss\": \"market\",\n    \"stoploss_on_exchange\": False,\n    \"stoploss_on_exchange_interval\": 60,\n    \"stoploss_on_exchange_limit_ratio\": 0.99,\n}\n

    Configuration:

    \"order_types\": {\n    \"entry\": \"limit\",\n    \"exit\": \"limit\",\n    \"emergency_exit\": \"market\",\n    \"force_entry\": \"market\",\n    \"force_exit\": \"market\",\n    \"stoploss\": \"market\",\n    \"stoploss_on_exchange\": false,\n    \"stoploss_on_exchange_interval\": 60\n}\n

    Market order support

    Not all exchanges support \"market\" orders. The following message will be shown if your exchange does not support market orders: \"Exchange <yourexchange> does not support market orders.\" and the bot will refuse to start.

    Using market orders

    Please carefully read the section Market order pricing section when using market orders.

    Stoploss on exchange

    order_types.stoploss_on_exchange_interval is not mandatory. Do not change its value if you are unsure of what you are doing. For more information about how stoploss works please refer to the stoploss documentation.

    If order_types.stoploss_on_exchange is enabled and the stoploss is cancelled manually on the exchange, then the bot will create a new stoploss order.

    Warning: order_types.stoploss_on_exchange failures

    If stoploss on exchange creation fails for some reason, then an \"emergency exit\" is initiated. By default, this will exit the trade using a market order. The order-type for the emergency-exit can be changed by setting the emergency_exit value in the order_types dictionary - however, this is not advised.

    "},{"location":"configuration/#understand-order_time_in_force","title":"Understand order_time_in_force","text":"

    The order_time_in_force configuration parameter defines the policy by which the order is executed on the exchange. Three commonly used time in force are:

    GTC (Good Till Canceled):

    This is most of the time the default time in force. It means the order will remain on exchange till it is cancelled by the user. It can be fully or partially fulfilled. If partially fulfilled, the remaining will stay on the exchange till cancelled.

    FOK (Fill Or Kill):

    It means if the order is not executed immediately AND fully then it is cancelled by the exchange.

    IOC (Immediate Or Canceled):

    It is the same as FOK (above) except it can be partially fulfilled. The remaining part is automatically cancelled by the exchange.

    PO (Post only):

    Post only order. The order is either placed as a maker order, or it is canceled. This means the order must be placed on orderbook for at least time in an unfilled state.

    "},{"location":"configuration/#time_in_force-config","title":"time_in_force config","text":"

    The order_time_in_force parameter contains a dict with entry and exit time in force policy values. This can be set in the configuration file or in the strategy. Values set in the configuration file overwrites values set in the strategy.

    The possible values are: GTC (default), FOK or IOC.

    \"order_time_in_force\": {\n    \"entry\": \"GTC\",\n    \"exit\": \"GTC\"\n},\n

    Warning

    This is ongoing work. For now, it is supported only for binance, gate and kucoin. Please don't change the default value unless you know what you are doing and have researched the impact of using different values for your particular exchange.

    "},{"location":"configuration/#fiat-conversion","title":"Fiat conversion","text":"

    Freqtrade uses the Coingecko API to convert the coin value to it's corresponding fiat value for the Telegram reports. The FIAT currency can be set in the configuration file as fiat_display_currency.

    Removing fiat_display_currency completely from the configuration will skip initializing coingecko, and will not show any FIAT currency conversion. This has no importance for the correct functioning of the bot.

    "},{"location":"configuration/#what-values-can-be-used-for-fiat_display_currency","title":"What values can be used for fiat_display_currency?","text":"

    The fiat_display_currency configuration parameter sets the base currency to use for the conversion from coin to fiat in the bot Telegram reports.

    The valid values are:

    \"AUD\", \"BRL\", \"CAD\", \"CHF\", \"CLP\", \"CNY\", \"CZK\", \"DKK\", \"EUR\", \"GBP\", \"HKD\", \"HUF\", \"IDR\", \"ILS\", \"INR\", \"JPY\", \"KRW\", \"MXN\", \"MYR\", \"NOK\", \"NZD\", \"PHP\", \"PKR\", \"PLN\", \"RUB\", \"SEK\", \"SGD\", \"THB\", \"TRY\", \"TWD\", \"ZAR\", \"USD\"\n

    In addition to fiat currencies, a range of crypto currencies is supported.

    The valid values are:

    \"BTC\", \"ETH\", \"XRP\", \"LTC\", \"BCH\", \"BNB\"\n
    "},{"location":"configuration/#coingecko-rate-limit-problems","title":"Coingecko Rate limit problems","text":"

    On some IP ranges, coingecko is heavily rate-limiting. In such cases, you may want to add your coingecko API key to the configuration.

    {\n    \"fiat_display_currency\": \"USD\",\n    \"coingecko\": {\n        \"api_key\": \"your-api\",\n        \"is_demo\": true\n    }\n}\n

    Freqtrade supports both Demo and Pro coingecko API keys.

    The Coingecko API key is NOT required for the bot to function correctly. It is only used for the conversion of coin to fiat in the Telegram reports, which usually also work without API key.

    "},{"location":"configuration/#consuming-exchange-websockets","title":"Consuming exchange Websockets","text":"

    Freqtrade can consume websockets through ccxt.pro.

    Freqtrade aims ensure data is available at all times. Should the websocket connection fail (or be disabled), the bot will fall back to REST API calls.

    Should you experience problems you suspect are caused by websockets, you can disable these via the setting exchange.enable_ws, which defaults to true.

    \"exchange\": {\n    // ...\n    \"enable_ws\": false,\n    // ...\n}\n

    Should you be required to use a proxy, please refer to the proxy section for more information.

    Rollout

    We're implementing this out slowly, ensuring stability of your bots. Currently, usage is limited to ohlcv data streams. It's also limited to a few exchanges, with new exchanges being added on an ongoing basis.

    "},{"location":"configuration/#using-dry-run-mode","title":"Using Dry-run mode","text":"

    We recommend starting the bot in the Dry-run mode to see how your bot will behave and what is the performance of your strategy. In the Dry-run mode, the bot does not engage your money. It only runs a live simulation without creating trades on the exchange.

    1. Edit your config.json configuration file.
    2. Switch dry-run to true and specify db_url for a persistence database.
    \"dry_run\": true,\n\"db_url\": \"sqlite:///tradesv3.dryrun.sqlite\",\n
    1. Remove your Exchange API key and secret (change them by empty values or fake credentials):
    \"exchange\": {\n    \"name\": \"binance\",\n    \"key\": \"key\",\n    \"secret\": \"secret\",\n    ...\n}\n

    Once you will be happy with your bot performance running in the Dry-run mode, you can switch it to production mode.

    Note

    A simulated wallet is available during dry-run mode and will assume a starting capital of dry_run_wallet (defaults to 1000).

    "},{"location":"configuration/#considerations-for-dry-run","title":"Considerations for dry-run","text":"
    • API-keys may or may not be provided. Only Read-Only operations (i.e. operations that do not alter account state) on the exchange are performed in dry-run mode.
    • Wallets (/balance) are simulated based on dry_run_wallet.
    • Orders are simulated, and will not be posted to the exchange.
    • Market orders fill based on orderbook volume the moment the order is placed, with a maximum slippage of 5%.
    • Limit orders fill once the price reaches the defined level - or time out based on unfilledtimeout settings.
    • Limit orders will be converted to market orders if they cross the price by more than 1%, and will be filled immediately based regular market order rules (see point about Market orders above).
    • In combination with stoploss_on_exchange, the stop_loss price is assumed to be filled.
    • Open orders (not trades, which are stored in the database) are kept open after bot restarts, with the assumption that they were not filled while being offline.
    "},{"location":"configuration/#switch-to-production-mode","title":"Switch to production mode","text":"

    In production mode, the bot will engage your money. Be careful, since a wrong strategy can lose all your money. Be aware of what you are doing when you run it in production mode.

    When switching to Production mode, please make sure to use a different / fresh database to avoid dry-run trades messing with your exchange money and eventually tainting your statistics.

    "},{"location":"configuration/#setup-your-exchange-account","title":"Setup your exchange account","text":"

    You will need to create API Keys (usually you get key and secret, some exchanges require an additional password) from the Exchange website and you'll need to insert this into the appropriate fields in the configuration or when asked by the freqtrade new-config command. API Keys are usually only required for live trading (trading for real money, bot running in \"production mode\", executing real orders on the exchange) and are not required for the bot running in dry-run (trade simulation) mode. When you set up the bot in dry-run mode, you may fill these fields with empty values.

    "},{"location":"configuration/#to-switch-your-bot-in-production-mode","title":"To switch your bot in production mode","text":"

    Edit your config.json file.

    Switch dry-run to false and don't forget to adapt your database URL if set:

    \"dry_run\": false,\n

    Insert your Exchange API key (change them by fake API keys):

    {\n    \"exchange\": {\n        \"name\": \"binance\",\n        \"key\": \"af8ddd35195e9dc500b9a6f799f6f5c93d89193b\",\n        \"secret\": \"08a9dc6db3d7b53e1acebd9275677f4b0a04f1a5\",\n        //\"password\": \"\", // Optional, not needed by all exchanges)\n        // ...\n    }\n    //...\n}\n

    You should also make sure to read the Exchanges section of the documentation to be aware of potential configuration details specific to your exchange.

    Keep your secrets secret

    To keep your secrets secret, we recommend using a 2nd configuration for your API keys. Simply use the above snippet in a new configuration file (e.g. config-private.json) and keep your settings in this file. You can then start the bot with freqtrade trade --config user_data/config.json --config user_data/config-private.json <...> to have your keys loaded.

    NEVER share your private configuration file or your exchange keys with anyone!

    "},{"location":"configuration/#using-a-proxy-with-freqtrade","title":"Using a proxy with Freqtrade","text":"

    To use a proxy with freqtrade, export your proxy settings using the variables \"HTTP_PROXY\" and \"HTTPS_PROXY\" set to the appropriate values. This will have the proxy settings applied to everything (telegram, coingecko, ...) except for exchange requests.

    export HTTP_PROXY=\"http://addr:port\"\nexport HTTPS_PROXY=\"http://addr:port\"\nfreqtrade\n
    "},{"location":"configuration/#proxy-exchange-requests","title":"Proxy exchange requests","text":"

    To use a proxy for exchange connections - you will have to define the proxies as part of the ccxt configuration.

    { \n  \"exchange\": {\n    \"ccxt_config\": {\n      \"httpsProxy\": \"http://addr:port\",\n      \"wsProxy\": \"http://addr:port\",\n    }\n  }\n}\n

    For more information on available proxy types, please consult the ccxt proxy documentation.

    "},{"location":"configuration/#next-step","title":"Next step","text":"

    Now you have configured your config.json, the next step is to start your bot.

    "},{"location":"data-analysis/","title":"Analyzing bot data with Jupyter notebooks","text":"

    You can analyze the results of backtests and trading history easily using Jupyter notebooks. Sample notebooks are located at user_data/notebooks/ after initializing the user directory with freqtrade create-userdir --userdir user_data.

    "},{"location":"data-analysis/#quick-start-with-docker","title":"Quick start with docker","text":"

    Freqtrade provides a docker-compose file which starts up a jupyter lab server. You can run this server using the following command: docker compose -f docker/docker-compose-jupyter.yml up

    This will create a dockercontainer running jupyter lab, which will be accessible using https://127.0.0.1:8888/lab. Please use the link that's printed in the console after startup for simplified login.

    For more information, Please visit the Data analysis with Docker section.

    "},{"location":"data-analysis/#pro-tips","title":"Pro tips","text":"
    • See jupyter.org for usage instructions.
    • Don't forget to start a Jupyter notebook server from within your conda or venv environment or use nb_conda_kernels*
    • Copy the example notebook before use so your changes don't get overwritten with the next freqtrade update.
    "},{"location":"data-analysis/#using-virtual-environment-with-system-wide-jupyter-installation","title":"Using virtual environment with system-wide Jupyter installation","text":"

    Sometimes it can be desired to use a system-wide installation of Jupyter notebook, and use a jupyter kernel from the virtual environment. This prevents you from installing the full jupyter suite multiple times per system, and provides an easy way to switch between tasks (freqtrade / other analytics tasks).

    For this to work, first activate your virtual environment and run the following commands:

    # Activate virtual environment\nsource .venv/bin/activate\n\npip install ipykernel\nipython kernel install --user --name=freqtrade\n# Restart jupyter (lab / notebook)\n# select kernel \"freqtrade\" in the notebook\n

    Note

    This section is provided for completeness, the Freqtrade Team won't provide full support for problems with this setup and will recommend to install Jupyter in the virtual environment directly, as that is the easiest way to get jupyter notebooks up and running. For help with this setup please refer to the Project Jupyter documentation or help channels.

    Warning

    Some tasks don't work especially well in notebooks. For example, anything using asynchronous execution is a problem for Jupyter. Also, freqtrade's primary entry point is the shell cli, so using pure python in a notebook bypasses arguments that provide required objects and parameters to helper functions. You may need to set those values or create expected objects manually.

    "},{"location":"data-analysis/#recommended-workflow","title":"Recommended workflow","text":"Task Tool Bot operations CLI Repetitive tasks Shell scripts Data analysis & visualization Notebook
    1. Use the CLI to

      * download historical data * run a backtest * run with real-time data * export results

    2. Collect these actions in shell scripts

      * save complicated commands with arguments * execute multi-step operations * automate testing strategies and preparing data for analysis

    3. Use a notebook to

      * visualize data * mangle and plot to generate insights

    "},{"location":"data-analysis/#example-utility-snippets","title":"Example utility snippets","text":""},{"location":"data-analysis/#change-directory-to-root","title":"Change directory to root","text":"

    Jupyter notebooks execute from the notebook directory. The following snippet searches for the project root, so relative paths remain consistent.

    import os\nfrom pathlib import Path\n\n# Change directory\n# Modify this cell to insure that the output shows the correct path.\n# Define all paths relative to the project root shown in the cell output\nproject_root = \"somedir/freqtrade\"\ni=0\ntry:\n    os.chdir(project_root)\n    assert Path('LICENSE').is_file()\nexcept:\n    while i<4 and (not Path('LICENSE').is_file()):\n        os.chdir(Path(Path.cwd(), '../'))\n        i+=1\n    project_root = Path.cwd()\nprint(Path.cwd())\n
    "},{"location":"data-analysis/#load-multiple-configuration-files","title":"Load multiple configuration files","text":"

    This option can be useful to inspect the results of passing in multiple configs. This will also run through the whole Configuration initialization, so the configuration is completely initialized to be passed to other methods.

    import json\nfrom freqtrade.configuration import Configuration\n\n# Load config from multiple files\nconfig = Configuration.from_files([\"config1.json\", \"config2.json\"])\n\n# Show the config in memory\nprint(json.dumps(config['original_config'], indent=2))\n

    For Interactive environments, have an additional configuration specifying user_data_dir and pass this in last, so you don't have to change directories while running the bot. Best avoid relative paths, since this starts at the storage location of the jupyter notebook, unless the directory is changed.

    {\n    \"user_data_dir\": \"~/.freqtrade/\"\n}\n
    "},{"location":"data-analysis/#further-data-analysis-documentation","title":"Further Data analysis documentation","text":"
    • Strategy debugging - also available as Jupyter notebook (user_data/notebooks/strategy_analysis_example.ipynb)
    • Plotting
    • Tag Analysis

    Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.

    "},{"location":"data-download/","title":"Data Downloading","text":""},{"location":"data-download/#getting-data-for-backtesting-and-hyperopt","title":"Getting data for backtesting and hyperopt","text":"

    To download data (candles / OHLCV) needed for backtesting and hyperoptimization use the freqtrade download-data command.

    If no additional parameter is specified, freqtrade will download data for \"1m\" and \"5m\" timeframes for the last 30 days. Exchange and pairs will come from config.json (if specified using -c/--config). Without provided configuration, --exchange becomes mandatory.

    You can use a relative timerange (--days 20) or an absolute starting point (--timerange 20200101-). For incremental downloads, the relative approach should be used.

    Tip: Updating existing data

    If you already have backtesting data available in your data-directory and would like to refresh this data up to today, freqtrade will automatically calculate the data missing for the existing pairs and the download will occur from the latest available point until \"now\", neither --days or --timerange parameters are required. Freqtrade will keep the available data and only download the missing data. If you are updating existing data after inserting new pairs that you have no data for, use --new-pairs-days xx parameter. Specified number of days will be downloaded for new pairs while old pairs will be updated with missing data only. If you use --days xx parameter alone - data for specified number of days will be downloaded for all pairs. Be careful, if specified number of days is smaller than gap between now and last downloaded candle - freqtrade will delete all existing data to avoid gaps in candle data.

    "},{"location":"data-download/#usage","title":"Usage","text":"
    usage: freqtrade download-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                               [-d PATH] [--userdir PATH]\n                               [-p PAIRS [PAIRS ...]] [--pairs-file FILE]\n                               [--days INT] [--new-pairs-days INT]\n                               [--include-inactive-pairs]\n                               [--timerange TIMERANGE] [--dl-trades]\n                               [--convert] [--exchange EXCHANGE]\n                               [-t TIMEFRAMES [TIMEFRAMES ...]] [--erase]\n                               [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                               [--data-format-trades {json,jsongz,hdf5,feather,parquet}]\n                               [--trading-mode {spot,margin,futures}]\n                               [--prepend]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --pairs-file FILE     File containing a list of pairs. Takes precedence over\n                        --pairs or pairs configured in the configuration.\n  --days INT            Download data for given number of days.\n  --new-pairs-days INT  Download data of new pairs for given number of days.\n                        Default: `None`.\n  --include-inactive-pairs\n                        Also download data from inactive pairs.\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --dl-trades           Download trades instead of OHLCV data. The bot will\n                        resample trades to the desired timeframe as specified\n                        as --timeframes/-t.\n  --convert             Convert downloaded trades to OHLCV data. Only\n                        applicable in combination with `--dl-trades`. Will be\n                        automatic for exchanges which don't have historic\n                        OHLCV (e.g. Kraken). If not provided, use `trades-to-\n                        ohlcv` to convert trades data to OHLCV data.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  -t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]\n                        Specify which tickers to download. Space-separated\n                        list. Default: `1m 5m`.\n  --erase               Clean all existing data for the selected\n                        exchange/pairs/timeframes.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --data-format-trades {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded trades data. (default:\n                        `feather`).\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n  --prepend             Allow data prepending. (Data-appending is disabled)\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Downloading all data for one quote currency

    Often, you'll want to download data for all pairs of a specific quote-currency. In such cases, you can use the following shorthand: freqtrade download-data --exchange binance --pairs .*/USDT <...>. The provided \"pairs\" string will be expanded to contain all active pairs on the exchange. To also download data for inactive (delisted) pairs, add --include-inactive-pairs to the command.

    Startup period

    download-data is a strategy-independent command. The idea is to download a big chunk of data once, and then iteratively increase the amount of data stored.

    For that reason, download-data does not care about the \"startup-period\" defined in a strategy. It's up to the user to download additional days if the backtest should start at a specific point in time (while respecting startup period).

    "},{"location":"data-download/#start-download","title":"Start download","text":"

    A very simple command (assuming an available config.json file) can look as follows.

    freqtrade download-data --exchange binance\n

    This will download historical candle (OHLCV) data for all the currency pairs defined in the configuration.

    Alternatively, specify the pairs directly

    freqtrade download-data --exchange binance --pairs ETH/USDT XRP/USDT BTC/USDT\n

    or as regex (in this case, to download all active USDT pairs)

    freqtrade download-data --exchange binance --pairs .*/USDT\n
    "},{"location":"data-download/#other-notes","title":"Other Notes","text":"
    • To use a different directory than the exchange specific default, use --datadir user_data/data/some_directory.
    • To change the exchange used to download the historical data from, please use a different configuration file (you'll probably need to adjust rate limits etc.)
    • To use pairs.json from some other directory, use --pairs-file some_other_dir/pairs.json.
    • To download historical candle (OHLCV) data for only 10 days, use --days 10 (defaults to 30 days).
    • To download historical candle (OHLCV) data from a fixed starting point, use --timerange 20200101- - which will download all data from January 1st, 2020.
    • Use --timeframes to specify what timeframe download the historical candle (OHLCV) data for. Default is --timeframes 1m 5m which will download 1-minute and 5-minute data.
    • To use exchange, timeframe and list of pairs as defined in your configuration file, use the -c/--config option. With this, the script uses the whitelist defined in the config as the list of currency pairs to download data for and does not require the pairs.json file. You can combine -c/--config with most other options.
    Permission denied errors

    If your configuration directory user_data was made by docker, you may get the following error:

    cp: cannot create regular file 'user_data/data/binance/pairs.json': Permission denied\n

    You can fix the permissions of your user-data directory as follows:

    sudo chown -R $UID:$GID user_data\n
    "},{"location":"data-download/#download-additional-data-before-the-current-timerange","title":"Download additional data before the current timerange","text":"

    Assuming you downloaded all data from 2022 (--timerange 20220101-) - but you'd now like to also backtest with earlier data. You can do so by using the --prepend flag, combined with --timerange - specifying an end-date.

    freqtrade download-data --exchange binance --pairs ETH/USDT XRP/USDT BTC/USDT --prepend --timerange 20210101-20220101\n

    Note

    Freqtrade will ignore the end-date in this mode if data is available, updating the end-date to the existing data start point.

    "},{"location":"data-download/#data-format","title":"Data format","text":"

    Freqtrade currently supports the following data-formats:

    • feather - a dataformat based on Apache Arrow
    • json - plain \"text\" json files
    • jsongz - a gzip-zipped version of json files
    • hdf5 - a high performance datastore
    • parquet - columnar datastore (OHLCV only)

    By default, both OHLCV data and trades data are stored in the feather format.

    This can be changed via the --data-format-ohlcv and --data-format-trades command line arguments respectively. To persist this change, you should also add the following snippet to your configuration, so you don't have to insert the above arguments each time:

        // ...\n    \"dataformat_ohlcv\": \"hdf5\",\n    \"dataformat_trades\": \"hdf5\",\n    // ...\n

    If the default data-format has been changed during download, then the keys dataformat_ohlcv and dataformat_trades in the configuration file need to be adjusted to the selected dataformat as well.

    Note

    You can convert between data-formats using the convert-data and convert-trade-data methods.

    "},{"location":"data-download/#dataformat-comparison","title":"Dataformat comparison","text":"

    The following comparisons have been made with the following data, and by using the linux time command.

    Found 6 pair / timeframe combinations.\n+----------+-------------+--------+---------------------+---------------------+\n|     Pair |   Timeframe |   Type |                From |                  To |\n|----------+-------------+--------+---------------------+---------------------|\n| BTC/USDT |          5m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:25:00 |\n| ETH/USDT |          1m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:26:00 |\n| BTC/USDT |          1m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:30:00 |\n| XRP/USDT |          5m |   spot | 2018-05-04 08:10:00 | 2022-09-13 19:15:00 |\n| XRP/USDT |          1m |   spot | 2018-05-04 08:11:00 | 2022-09-13 19:22:00 |\n| ETH/USDT |          5m |   spot | 2017-08-17 04:00:00 | 2022-09-13 19:20:00 |\n+----------+-------------+--------+---------------------+---------------------+\n

    Timings have been taken in a not very scientific way with the following command, which forces reading the data into memory.

    time freqtrade list-data --show-timerange --data-format-ohlcv <dataformat>\n
    Format Size timing feather 72Mb 3.5s json 149Mb 25.6s jsongz 39Mb 27s hdf5 145Mb 3.9s parquet 83Mb 3.8s

    Size has been taken from the BTC/USDT 1m spot combination for the timerange specified above.

    To have a best performance/size mix, we recommend using the default feather format, or parquet.

    "},{"location":"data-download/#pairs-file","title":"Pairs file","text":"

    In alternative to the whitelist from config.json, a pairs.json file can be used. If you are using Binance for example:

    • create a directory user_data/data/binance and copy or create the pairs.json file in that directory.
    • update the pairs.json file to contain the currency pairs you are interested in.
    mkdir -p user_data/data/binance\ntouch user_data/data/binance/pairs.json\n

    The format of the pairs.json file is a simple json list. Mixing different stake-currencies is allowed for this file, since it's only used for downloading.

    [\n    \"ETH/BTC\",\n    \"ETH/USDT\",\n    \"BTC/USDT\",\n    \"XRP/ETH\"\n]\n

    Note

    The pairs.json file is only used when no configuration is loaded (implicitly by naming, or via --config flag). You can force the usage of this file via --pairs-file pairs.json - however we recommend to use the pairlist from within the configuration, either via exchange.pair_whitelist or pairs setting in the configuration.

    "},{"location":"data-download/#sub-command-convert-data","title":"Sub-command convert data","text":"
    usage: freqtrade convert-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                              [-d PATH] [--userdir PATH]\n                              [-p PAIRS [PAIRS ...]] --format-from\n                              {json,jsongz,hdf5,feather,parquet} --format-to\n                              {json,jsongz,hdf5,feather,parquet} [--erase]\n                              [--exchange EXCHANGE]\n                              [-t TIMEFRAMES [TIMEFRAMES ...]]\n                              [--trading-mode {spot,margin,futures}]\n                              [--candle-types {spot,futures,mark,index,premiumIndex,funding_rate} [{spot,futures,mark,index,premiumIndex,funding_rate} ...]]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --format-from {json,jsongz,hdf5,feather,parquet}\n                        Source format for data conversion.\n  --format-to {json,jsongz,hdf5,feather,parquet}\n                        Destination format for data conversion.\n  --erase               Clean all existing data for the selected\n                        exchange/pairs/timeframes.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  -t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]\n                        Specify which tickers to download. Space-separated\n                        list. Default: `1m 5m`.\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n  --candle-types {spot,futures,mark,index,premiumIndex,funding_rate} [{spot,futures,mark,index,premiumIndex,funding_rate} ...]\n                        Select candle type to convert. Defaults to all\n                        available types.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-converting-data","title":"Example converting data","text":"

    The following command will convert all candle (OHLCV) data available in ~/.freqtrade/data/binance from json to jsongz, saving diskspace in the process. It'll also remove original json data files (--erase parameter).

    freqtrade convert-data --format-from json --format-to jsongz --datadir ~/.freqtrade/data/binance -t 5m 15m --erase\n
    "},{"location":"data-download/#sub-command-convert-trade-data","title":"Sub-command convert trade data","text":"
    usage: freqtrade convert-trade-data [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                    [-d PATH] [--userdir PATH]\n                                    [-p PAIRS [PAIRS ...]] --format-from\n                                    {json,jsongz,hdf5,feather,parquet}\n                                    --format-to\n                                    {json,jsongz,hdf5,feather,parquet}\n                                    [--erase] [--exchange EXCHANGE]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --format-from {json,jsongz,hdf5,feather,parquet}\n                        Source format for data conversion.\n  --format-to {json,jsongz,hdf5,feather,parquet}\n                        Destination format for data conversion.\n  --erase               Clean all existing data for the selected\n                        exchange/pairs/timeframes.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-converting-trades","title":"Example converting trades","text":"

    The following command will convert all available trade-data in ~/.freqtrade/data/kraken from jsongz to json. It'll also remove original jsongz data files (--erase parameter).

    freqtrade convert-trade-data --format-from jsongz --format-to json --datadir ~/.freqtrade/data/kraken --erase\n
    "},{"location":"data-download/#sub-command-trades-to-ohlcv","title":"Sub-command trades to ohlcv","text":"

    When you need to use --dl-trades (kraken only) to download data, conversion of trades data to ohlcv data is the last step. This command will allow you to repeat this last step for additional timeframes without re-downloading the data.

    usage: freqtrade trades-to-ohlcv [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                 [-d PATH] [--userdir PATH]\n                                 [-p PAIRS [PAIRS ...]]\n                                 [-t TIMEFRAMES [TIMEFRAMES ...]]\n                                 [--exchange EXCHANGE]\n                                 [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                                 [--data-format-trades {json,jsongz,hdf5,feather}]\n\noptions:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  -t TIMEFRAMES [TIMEFRAMES ...], --timeframes TIMEFRAMES [TIMEFRAMES ...]\n                        Specify which tickers to download. Space-separated\n                        list. Default: `1m 5m`.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --data-format-trades {json,jsongz,hdf5,feather}\n                        Storage format for downloaded trades data. (default:\n                        `feather`).\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-trade-to-ohlcv-conversion","title":"Example trade-to-ohlcv conversion","text":"
    freqtrade trades-to-ohlcv --exchange kraken -t 5m 1h 1d --pairs BTC/EUR ETH/EUR\n
    "},{"location":"data-download/#sub-command-list-data","title":"Sub-command list-data","text":"

    You can get a list of downloaded data using the list-data sub-command.

    usage: freqtrade list-data [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                           [--userdir PATH] [--exchange EXCHANGE]\n                           [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                           [--data-format-trades {json,jsongz,hdf5,feather,parquet}]\n                           [--trades] [-p PAIRS [PAIRS ...]]\n                           [--trading-mode {spot,margin,futures}]\n                           [--show-timerange]\n\noptions:\n  -h, --help            show this help message and exit\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  --data-format-trades {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded trades data. (default:\n                        `feather`).\n  --trades              Work on trades data instead of OHLCV data.\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n  --show-timerange      Show timerange available for available data. (May take\n                        a while to calculate).\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"data-download/#example-list-data","title":"Example list-data","text":"
    > freqtrade list-data --userdir ~/.freqtrade/user_data/\n\n              Found 33 pair / timeframe combinations.\n\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503          Pair \u2503                                 Timeframe \u2503 Type \u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502       ADA/BTC \u2502     5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d \u2502 spot \u2502\n\u2502       ADA/ETH \u2502     5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d \u2502 spot \u2502\n\u2502       ETH/BTC \u2502     5m, 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d \u2502 spot \u2502\n\u2502      ETH/USDT \u2502                  5m, 15m, 30m, 1h, 2h, 4h \u2502 spot \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n

    Show all trades data including from/to timerange

    > freqtrade list-data --show --trades\n                     Found trades data for 1 pair.                     \n\u250f\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2533\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2513\n\u2503    Pair \u2503 Type \u2503                From \u2503                  To \u2503 Trades \u2503\n\u2521\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2547\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2529\n\u2502 XRP/ETH \u2502 spot \u2502 2019-10-11 00:00:11 \u2502 2019-10-13 11:19:28 \u2502  12477 \u2502\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n
    "},{"location":"data-download/#trades-tick-data","title":"Trades (tick) data","text":"

    By default, download-data sub-command downloads Candles (OHLCV) data. Most exchanges also provide historic trade-data via their API. This data can be useful if you need many different timeframes, since it is only downloaded once, and then resampled locally to the desired timeframes.

    Since this data is large by default, the files use the feather file format by default. They are stored in your data-directory with the naming convention of <pair>-trades.feather (ETH_BTC-trades.feather). Incremental mode is also supported, as for historic OHLCV data, so downloading the data once per week with --days 8 will create an incremental data-repository.

    To use this mode, simply add --dl-trades to your call. This will swap the download method to download trades. If --convert is also provided, the resample step will happen automatically and overwrite eventually existing OHLCV data for the given pair/timeframe combinations.

    Do not use

    You should not use this unless you're a kraken user (Kraken does not provide historic OHLCV data). Most other exchanges provide OHLCV data with sufficient history, so downloading multiple timeframes through that method will still proof to be a lot faster than downloading trades data.

    Kraken user

    Kraken users should read this before starting to download data.

    Example call:

    freqtrade download-data --exchange kraken --pairs XRP/EUR ETH/EUR --days 20 --dl-trades\n

    Note

    While this method uses async calls, it will be slow, since it requires the result of the previous call to generate the next request to the exchange.

    "},{"location":"data-download/#next-step","title":"Next step","text":"

    Great, you now have some data downloaded, so you can now start backtesting your strategy.

    "},{"location":"deprecated/","title":"Deprecated features","text":"

    This page contains description of the command line arguments, configuration parameters and the bot features that were declared as DEPRECATED by the bot development team and are no longer supported. Please avoid their usage in your configuration.

    "},{"location":"deprecated/#removed-features","title":"Removed features","text":""},{"location":"deprecated/#the-refresh-pairs-cached-command-line-option","title":"the --refresh-pairs-cached command line option","text":"

    --refresh-pairs-cached in the context of backtesting, hyperopt and edge allows to refresh candle data for backtesting. Since this leads to much confusion, and slows down backtesting (while not being part of backtesting) this has been singled out as a separate freqtrade sub-command freqtrade download-data.

    This command line option was deprecated in 2019.7-dev (develop branch) and removed in 2019.9.

    "},{"location":"deprecated/#the-dynamic-whitelist-command-line-option","title":"The --dynamic-whitelist command line option","text":"

    This command line option was deprecated in 2018 and removed freqtrade 2019.6-dev (develop branch) and in freqtrade 2019.7. Please refer to pairlists instead.

    "},{"location":"deprecated/#the-live-command-line-option","title":"the --live command line option","text":"

    --live in the context of backtesting allowed to download the latest tick data for backtesting. Did only download the latest 500 candles, so was ineffective in getting good backtest data. Removed in 2019-7-dev (develop branch) and in freqtrade 2019.8.

    "},{"location":"deprecated/#ticker_interval-now-timeframe","title":"ticker_interval (now timeframe)","text":"

    Support for ticker_interval terminology was deprecated in 2020.6 in favor of timeframe - and compatibility code was removed in 2022.3.

    "},{"location":"deprecated/#allow-running-multiple-pairlists-in-sequence","title":"Allow running multiple pairlists in sequence","text":"

    The former \"pairlist\" section in the configuration has been removed, and is replaced by \"pairlists\" - being a list to specify a sequence of pairlists.

    The old section of configuration parameters (\"pairlist\") has been deprecated in 2019.11 and has been removed in 2020.4.

    "},{"location":"deprecated/#deprecation-of-bidvolume-and-askvolume-from-volume-pairlist","title":"deprecation of bidVolume and askVolume from volume-pairlist","text":"

    Since only quoteVolume can be compared between assets, the other options (bidVolume, askVolume) have been deprecated in 2020.4, and have been removed in 2020.9.

    "},{"location":"deprecated/#using-order-book-steps-for-exit-price","title":"Using order book steps for exit price","text":"

    Using order_book_min and order_book_max used to allow stepping the orderbook and trying to find the next ROI slot - trying to place sell-orders early. As this does however increase risk and provides no benefit, it's been removed for maintainability purposes in 2021.7.

    "},{"location":"deprecated/#legacy-hyperopt-mode","title":"Legacy Hyperopt mode","text":"

    Using separate hyperopt files was deprecated in 2021.4 and was removed in 2021.9. Please switch to the new Parametrized Strategies to benefit from the new hyperopt interface.

    "},{"location":"deprecated/#strategy-changes-between-v2-and-v3","title":"Strategy changes between V2 and V3","text":"

    Isolated Futures / short trading was introduced in 2022.4. This required major changes to configuration settings, strategy interfaces, ...

    We have put a great effort into keeping compatibility with existing strategies, so if you just want to continue using freqtrade in spot markets, there are no changes necessary. While we may drop support for the current interface sometime in the future, we will announce this separately and have an appropriate transition period.

    Please follow the Strategy migration guide to migrate your strategy to the new format to start using the new functionalities.

    "},{"location":"deprecated/#webhooks-changes-with-20224","title":"webhooks - changes with 2022.4","text":""},{"location":"deprecated/#buy_tag-has-been-renamed-to-enter_tag","title":"buy_tag has been renamed to enter_tag","text":"

    This should apply only to your strategy and potentially to webhooks. We will keep a compatibility layer for 1-2 versions (so both buy_tag and enter_tag will still work), but support for this in webhooks will disappear after that.

    "},{"location":"deprecated/#naming-changes","title":"Naming changes","text":"

    Webhook terminology changed from \"sell\" to \"exit\", and from \"buy\" to \"entry\", removing \"webhook\" in the process.

    • webhookbuy, webhookentry -> entry
    • webhookbuyfill, webhookentryfill -> entry_fill
    • webhookbuycancel, webhookentrycancel -> entry_cancel
    • webhooksell, webhookexit -> exit
    • webhooksellfill, webhookexitfill -> exit_fill
    • webhooksellcancel, webhookexitcancel -> exit_cancel
    "},{"location":"deprecated/#removal-of-populate_any_indicators","title":"Removal of populate_any_indicators","text":"

    version 2023.3 saw the removal of populate_any_indicators in favor of split methods for feature engineering and targets. Please read the migration document for full details.

    "},{"location":"developer/","title":"Development Help","text":"

    This page is intended for developers of Freqtrade, people who want to contribute to the Freqtrade codebase or documentation, or people who want to understand the source code of the application they're running.

    All contributions, bug reports, bug fixes, documentation improvements, enhancements and ideas are welcome. We track issues on GitHub and also have a dev channel on discord where you can ask questions.

    "},{"location":"developer/#documentation","title":"Documentation","text":"

    Documentation is available at https://freqtrade.io and needs to be provided with every new feature PR.

    Special fields for the documentation (like Note boxes, ...) can be found here.

    To test the documentation locally use the following commands.

    pip install -r docs/requirements-docs.txt\nmkdocs serve\n

    This will spin up a local server (usually on port 8000) so you can see if everything looks as you'd like it to.

    "},{"location":"developer/#developer-setup","title":"Developer setup","text":"

    To configure a development environment, you can either use the provided DevContainer, or use the setup.sh script and answer \"y\" when asked \"Do you want to install dependencies for dev [y/N]? \". Alternatively (e.g. if your system is not supported by the setup.sh script), follow the manual installation process and run pip3 install -r requirements-dev.txt - followed by pip3 install -e .[all].

    This will install all required tools for development, including pytest, ruff, mypy, and coveralls.

    Then install the git hook scripts by running pre-commit install, so your changes will be verified locally before committing. This avoids a lot of waiting for CI already, as some basic formatting checks are done locally on your machine.

    Before opening a pull request, please familiarize yourself with our Contributing Guidelines.

    "},{"location":"developer/#devcontainer-setup","title":"Devcontainer setup","text":"

    The fastest and easiest way to get started is to use VSCode with the Remote container extension. This gives developers the ability to start the bot with all required dependencies without needing to install any freqtrade specific dependencies on your local machine.

    "},{"location":"developer/#devcontainer-dependencies","title":"Devcontainer dependencies","text":"
    • VSCode
    • docker
    • Remote container extension documentation

    For more information about the Remote container extension, best consult the documentation.

    "},{"location":"developer/#tests","title":"Tests","text":"

    New code should be covered by basic unittests. Depending on the complexity of the feature, Reviewers may request more in-depth unittests. If necessary, the Freqtrade team can assist and give guidance with writing good tests (however please don't expect anyone to write the tests for you).

    "},{"location":"developer/#how-to-run-tests","title":"How to run tests","text":"

    Use pytest in root folder to run all available testcases and confirm your local environment is setup correctly

    feature branches

    Tests are expected to pass on the develop and stable branches. Other branches may be work in progress with tests not working yet.

    "},{"location":"developer/#checking-log-content-in-tests","title":"Checking log content in tests","text":"

    Freqtrade uses 2 main methods to check log content in tests, log_has() and log_has_re() (to check using regex, in case of dynamic log-messages). These are available from conftest.py and can be imported in any test module.

    A sample check looks as follows:

    from tests.conftest import log_has, log_has_re\n\ndef test_method_to_test(caplog):\n    method_to_test()\n\n    assert log_has(\"This event happened\", caplog)\n    # Check regex with trailing number ...\n    assert log_has_re(r\"This dynamic event happened and produced \\d+\", caplog)\n
    "},{"location":"developer/#debug-configuration","title":"Debug configuration","text":"

    To debug freqtrade, we recommend VSCode (with the Python extension) with the following launch configuration (located in .vscode/launch.json). Details will obviously vary between setups - but this should work to get you started.

    {\n    \"name\": \"freqtrade trade\",\n    \"type\": \"debugpy\",\n    \"request\": \"launch\",\n    \"module\": \"freqtrade\",\n    \"console\": \"integratedTerminal\",\n    \"args\": [\n        \"trade\",\n        // Optional:\n        // \"--userdir\", \"user_data\",\n        \"--strategy\", \n        \"MyAwesomeStrategy\",\n    ]\n},\n

    Command line arguments can be added in the \"args\" array. This method can also be used to debug a strategy, by setting the breakpoints within the strategy.

    A similar setup can also be taken for Pycharm - using freqtrade as module name, and setting the command line arguments as \"parameters\".

    Correct venv usage

    When using a virtual environment (which you should), make sure that your Editor is using the correct virtual environment to avoid problems or \"unknown import\" errors.

    Startup directory

    This assumes that you have the repository checked out, and the editor is started at the repository root level (so setup.py is at the top level of your repository).

    "},{"location":"developer/#vscode","title":"Vscode","text":"

    You can select the correct environment in VSCode with the command \"Python: Select Interpreter\" - which will show you environments the extension detected. If your environment has not been detected, you can also pick a path manually.

    "},{"location":"developer/#pycharm","title":"Pycharm","text":"

    In pycharm, you can select the appropriate Environment in the \"Run/Debug Configurations\" window.

    "},{"location":"developer/#errorhandling","title":"ErrorHandling","text":"

    Freqtrade Exceptions all inherit from FreqtradeException. This general class of error should however not be used directly. Instead, multiple specialized sub-Exceptions exist.

    Below is an outline of exception inheritance hierarchy:

    + FreqtradeException\n|\n+---+ OperationalException\n|   |\n|   +---+ ConfigurationError\n|\n+---+ DependencyException\n|   |\n|   +---+ PricingError\n|   |\n|   +---+ ExchangeError\n|       |\n|       +---+ TemporaryError\n|       |\n|       +---+ DDosProtection\n|       |\n|       +---+ InvalidOrderException\n|           |\n|           +---+ RetryableOrderError\n|           |\n|           +---+ InsufficientFundsError\n|\n+---+ StrategyError\n
    "},{"location":"developer/#plugins","title":"Plugins","text":""},{"location":"developer/#pairlists","title":"Pairlists","text":"

    You have a great idea for a new pair selection algorithm you would like to try out? Great. Hopefully you also want to contribute this back upstream.

    Whatever your motivations are - This should get you off the ground in trying to develop a new Pairlist Handler.

    First of all, have a look at the VolumePairList Handler, and best copy this file with a name of your new Pairlist Handler.

    This is a simple Handler, which however serves as a good example on how to start developing.

    Next, modify the class-name of the Handler (ideally align this with the module filename).

    The base-class provides an instance of the exchange (self._exchange) the pairlist manager (self._pairlistmanager), as well as the main configuration (self._config), the pairlist dedicated configuration (self._pairlistconfig) and the absolute position within the list of pairlists.

            self._exchange = exchange\n        self._pairlistmanager = pairlistmanager\n        self._config = config\n        self._pairlistconfig = pairlistconfig\n        self._pairlist_pos = pairlist_pos\n

    Tip

    Don't forget to register your pairlist in constants.py under the variable AVAILABLE_PAIRLISTS - otherwise it will not be selectable.

    Now, let's step through the methods which require actions:

    "},{"location":"developer/#pairlist-configuration","title":"Pairlist configuration","text":"

    Configuration for the chain of Pairlist Handlers is done in the bot configuration file in the element \"pairlists\", an array of configuration parameters for each Pairlist Handlers in the chain.

    By convention, \"number_assets\" is used to specify the maximum number of pairs to keep in the pairlist. Please follow this to ensure a consistent user experience.

    Additional parameters can be configured as needed. For instance, VolumePairList uses \"sort_key\" to specify the sorting value - however feel free to specify whatever is necessary for your great algorithm to be successful and dynamic.

    "},{"location":"developer/#short_desc","title":"short_desc","text":"

    Returns a description used for Telegram messages.

    This should contain the name of the Pairlist Handler, as well as a short description containing the number of assets. Please follow the format \"PairlistName - top/bottom X pairs\".

    "},{"location":"developer/#gen_pairlist","title":"gen_pairlist","text":"

    Override this method if the Pairlist Handler can be used as the leading Pairlist Handler in the chain, defining the initial pairlist which is then handled by all Pairlist Handlers in the chain. Examples are StaticPairList and VolumePairList.

    This is called with each iteration of the bot (only if the Pairlist Handler is at the first location) - so consider implementing caching for compute/network heavy calculations.

    It must return the resulting pairlist (which may then be passed into the chain of Pairlist Handlers).

    Validations are optional, the parent class exposes a _verify_blacklist(pairlist) and _whitelist_for_active_markets(pairlist) to do default filtering. Use this if you limit your result to a certain number of pairs - so the end-result is not shorter than expected.

    "},{"location":"developer/#filter_pairlist","title":"filter_pairlist","text":"

    This method is called for each Pairlist Handler in the chain by the pairlist manager.

    This is called with each iteration of the bot - so consider implementing caching for compute/network heavy calculations.

    It gets passed a pairlist (which can be the result of previous pairlists) as well as tickers, a pre-fetched version of get_tickers().

    The default implementation in the base class simply calls the _validate_pair() method for each pair in the pairlist, but you may override it. So you should either implement the _validate_pair() in your Pairlist Handler or override filter_pairlist() to do something else.

    If overridden, it must return the resulting pairlist (which may then be passed into the next Pairlist Handler in the chain).

    Validations are optional, the parent class exposes a _verify_blacklist(pairlist) and _whitelist_for_active_markets(pairlist) to do default filters. Use this if you limit your result to a certain number of pairs - so the end result is not shorter than expected.

    In VolumePairList, this implements different methods of sorting, does early validation so only the expected number of pairs is returned.

    "},{"location":"developer/#sample","title":"sample","text":"
        def filter_pairlist(self, pairlist: List[str], tickers: Dict) -> List[str]:\n        # Generate dynamic whitelist\n        pairs = self._calculate_pairlist(pairlist, tickers)\n        return pairs\n
    "},{"location":"developer/#protections","title":"Protections","text":"

    Best read the Protection documentation to understand protections. This Guide is directed towards Developers who want to develop a new protection.

    No protection should use datetime directly, but use the provided date_now variable for date calculations. This preserves the ability to backtest protections.

    Writing a new Protection

    Best copy one of the existing Protections to have a good example. Don't forget to register your protection in constants.py under the variable AVAILABLE_PROTECTIONS - otherwise it will not be selectable.

    "},{"location":"developer/#implementation-of-a-new-protection","title":"Implementation of a new protection","text":"

    All Protection implementations must have IProtection as parent class. For that reason, they must implement the following methods:

    • short_desc()
    • global_stop()
    • stop_per_pair().

    global_stop() and stop_per_pair() must return a ProtectionReturn object, which consists of:

    • lock pair - boolean
    • lock until - datetime - until when should the pair be locked (will be rounded up to the next new candle)
    • reason - string, used for logging and storage in the database
    • lock_side - long, short or '*'.

    The until portion should be calculated using the provided calculate_lock_end() method.

    All Protections should use \"stop_duration\" / \"stop_duration_candles\" to define how long a pair (or all pairs) should be locked. The content of this is made available as self._stop_duration to the each Protection.

    If your protection requires a look-back period, please use \"lookback_period\" / \"lockback_period_candles\" to keep all protections aligned.

    "},{"location":"developer/#global-vs-local-stops","title":"Global vs. local stops","text":"

    Protections can have 2 different ways to stop trading for a limited :

    • Per pair (local)
    • For all Pairs (globally)
    "},{"location":"developer/#protections-per-pair","title":"Protections - per pair","text":"

    Protections that implement the per pair approach must set has_local_stop=True. The method stop_per_pair() will be called whenever a trade closed (exit order completed).

    "},{"location":"developer/#protections-global-protection","title":"Protections - global protection","text":"

    These Protections should do their evaluation across all pairs, and consequently will also lock all pairs from trading (called a global PairLock). Global protection must set has_global_stop=True to be evaluated for global stops. The method global_stop() will be called whenever a trade closed (exit order completed).

    "},{"location":"developer/#protections-calculating-lock-end-time","title":"Protections - calculating lock end time","text":"

    Protections should calculate the lock end time based on the last trade it considers. This avoids re-locking should the lookback-period be longer than the actual lock period.

    The IProtection parent class provides a helper method for this in calculate_lock_end().

    "},{"location":"developer/#implement-a-new-exchange-wip","title":"Implement a new Exchange (WIP)","text":"

    Note

    This section is a Work in Progress and is not a complete guide on how to test a new exchange with Freqtrade.

    Note

    Make sure to use an up-to-date version of CCXT before running any of the below tests. You can get the latest version of ccxt by running pip install -U ccxt with activated virtual environment. Native docker is not supported for these tests, however the available dev-container will support all required actions and eventually necessary changes.

    Most exchanges supported by CCXT should work out of the box.

    To quickly test the public endpoints of an exchange, add a configuration for your exchange to tests/exchange_online/conftest.py and run these tests with pytest --longrun tests/exchange_online/test_ccxt_compat.py. Completing these tests successfully a good basis point (it's a requirement, actually), however these won't guarantee correct exchange functioning, as this only tests public endpoints, but no private endpoint (like generate order or similar).

    Also try to use freqtrade download-data for an extended timerange (multiple months) and verify that the data downloaded correctly (no holes, the specified timerange was actually downloaded).

    These are prerequisites to have an exchange listed as either Supported or Community tested (listed on the homepage). The below are \"extras\", which will make an exchange better (feature-complete) - but are not absolutely necessary for either of the 2 categories.

    Additional tests / steps to complete:

    • Verify data provided by fetch_ohlcv() - and eventually adjust ohlcv_candle_limit for this exchange
    • Check L2 orderbook limit range (API documentation) - and eventually set as necessary
    • Check if balance shows correctly (*)
    • Create market order (*)
    • Create limit order (*)
    • Cancel order (*)
    • Complete trade (enter + exit) (*)
      • Compare result calculation between exchange and bot
      • Ensure fees are applied correctly (check the database against the exchange)

    (*) Requires API keys and Balance on the exchange.

    "},{"location":"developer/#stoploss-on-exchange","title":"Stoploss On Exchange","text":"

    Check if the new exchange supports Stoploss on Exchange orders through their API.

    Since CCXT does not provide unification for Stoploss On Exchange yet, we'll need to implement the exchange-specific parameters ourselves. Best look at binance.py for an example implementation of this. You'll need to dig through the documentation of the Exchange's API on how exactly this can be done. CCXT Issues may also provide great help, since others may have implemented something similar for their projects.

    "},{"location":"developer/#incomplete-candles","title":"Incomplete candles","text":"

    While fetching candle (OHLCV) data, we may end up getting incomplete candles (depending on the exchange). To demonstrate this, we'll use daily candles (\"1d\") to keep things simple. We query the api (ct.fetch_ohlcv()) for the timeframe and look at the date of the last entry. If this entry changes or shows the date of a \"incomplete\" candle, then we should drop this since having incomplete candles is problematic because indicators assume that only complete candles are passed to them, and will generate a lot of false buy signals. By default, we're therefore removing the last candle assuming it's incomplete.

    To check how the new exchange behaves, you can use the following snippet:

    import ccxt\nfrom datetime import datetime, timezone\nfrom freqtrade.data.converter import ohlcv_to_dataframe\nct = ccxt.binance()  # Use the exchange you're testing\ntimeframe = \"1d\"\npair = \"BTC/USDT\"  # Make sure to use a pair that exists on that exchange!\nraw = ct.fetch_ohlcv(pair, timeframe=timeframe)\n\n# convert to dataframe\ndf1 = ohlcv_to_dataframe(raw, timeframe, pair=pair, drop_incomplete=False)\n\nprint(df1.tail(1))\nprint(datetime.now(timezone.utc))\n
                             date      open      high       low     close  volume  \n499 2019-06-08 00:00:00+00:00  0.000007  0.000007  0.000007  0.000007   26264344.0  \n2019-06-09 12:30:27.873327\n

    The output will show the last entry from the Exchange as well as the current UTC date. If the day shows the same day, then the last candle can be assumed as incomplete and should be dropped (leave the setting \"ohlcv_partial_candle\" from the exchange-class untouched / True). Otherwise, set \"ohlcv_partial_candle\" to False to not drop Candles (shown in the example above). Another way is to run this command multiple times in a row and observe if the volume is changing (while the date remains the same).

    "},{"location":"developer/#update-binance-cached-leverage-tiers","title":"Update binance cached leverage tiers","text":"

    Updating leveraged tiers should be done regularly - and requires an authenticated account with futures enabled.

    import ccxt\nimport json\nfrom pathlib import Path\n\nexchange = ccxt.binance({\n    'apiKey': '<apikey>',\n    'secret': '<secret>',\n    'options': {'defaultType': 'swap'}\n    })\n_ = exchange.load_markets()\n\nlev_tiers = exchange.fetch_leverage_tiers()\n\n# Assumes this is running in the root of the repository.\nfile = Path('freqtrade/exchange/binance_leverage_tiers.json')\njson.dump(dict(sorted(lev_tiers.items())), file.open('w'), indent=2)\n

    This file should then be contributed upstream, so others can benefit from this, too.

    "},{"location":"developer/#updating-example-notebooks","title":"Updating example notebooks","text":"

    To keep the jupyter notebooks aligned with the documentation, the following should be ran after updating a example notebook.

    jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace freqtrade/templates/strategy_analysis_example.ipynb\njupyter nbconvert --ClearOutputPreprocessor.enabled=True --to markdown freqtrade/templates/strategy_analysis_example.ipynb --stdout > docs/strategy_analysis_example.md\n
    "},{"location":"developer/#continuous-integration","title":"Continuous integration","text":"

    This documents some decisions taken for the CI Pipeline.

    • CI runs on all OS variants, Linux (ubuntu), macOS and Windows.
    • Docker images are build for the branches stable and develop, and are built as multiarch builds, supporting multiple platforms via the same tag.
    • Docker images containing Plot dependencies are also available as stable_plot and develop_plot.
    • Docker images contain a file, /freqtrade/freqtrade_commit containing the commit this image is based of.
    • Full docker image rebuilds are run once a week via schedule.
    • Deployments run on ubuntu.
    • ta-lib binaries are contained in the build_helpers directory to avoid fails related to external unavailability.
    • All tests must pass for a PR to be merged to stable or develop.
    "},{"location":"developer/#creating-a-release","title":"Creating a release","text":"

    This part of the documentation is aimed at maintainers, and shows how to create a release.

    "},{"location":"developer/#create-release-branch","title":"Create release branch","text":"

    Note

    Make sure that the stable branch is up-to-date!

    First, pick a commit that's about one week old (to not include latest additions to releases).

    # create new branch\ngit checkout -b new_release <commitid>\n

    Determine if crucial bugfixes have been made between this commit and the current state, and eventually cherry-pick these.

    • Merge the release branch (stable) into this branch.
    • Edit freqtrade/__init__.py and add the version matching the current date (for example 2019.7 for July 2019). Minor versions can be 2019.7.1 should we need to do a second release that month. Version numbers must follow allowed versions from PEP0440 to avoid failures pushing to pypi.
    • Commit this part.
    • Push that branch to the remote and create a PR against the stable branch.
    • Update develop version to next version following the pattern 2019.8-dev.
    "},{"location":"developer/#create-changelog-from-git-commits","title":"Create changelog from git commits","text":"
    # Needs to be done before merging / pulling that branch.\ngit log --oneline --no-decorate --no-merges stable..new_release\n

    To keep the release-log short, best wrap the full git changelog into a collapsible details section.

    <details>\n<summary>Expand full changelog</summary>\n\n... Full git changelog\n\n</details>\n
    "},{"location":"developer/#frequi-release","title":"FreqUI release","text":"

    If FreqUI has been updated substantially, make sure to create a release before merging the release branch. Make sure that freqUI CI on the release is finished and passed before merging the release.

    "},{"location":"developer/#create-github-release-tag","title":"Create github release / tag","text":"

    Once the PR against stable is merged (best right after merging):

    • Use the button \"Draft a new release\" in the Github UI (subsection releases).
    • Use the version-number specified as tag.
    • Use \"stable\" as reference (this step comes after the above PR is merged).
    • Use the above changelog as release comment (as codeblock).
    • Use the below snippet for the new release
    Release template
    ## Highlighted changes\n\n- ...\n\n### How to update\n\nAs always, you can update your bot using one of the following commands:\n\n#### docker-compose\n\n```bash\ndocker-compose pull\ndocker-compose up -d\n```\n\n#### Installation via setup script\n\n```\n# Deactivate venv and run \n./setup.sh --update\n```\n\n#### Plain native installation\n\n```\ngit pull\npip install -U -r requirements.txt\n```\n\n<details>\n<summary>Expand full changelog</summary>\n\n```\n<Paste your changelog here>\n```\n\n</details>\n
    "},{"location":"developer/#releases","title":"Releases","text":""},{"location":"developer/#pypi","title":"pypi","text":"

    Manual Releases

    This process is automated as part of Github Actions. Manual pypi pushes should not be necessary.

    Manual release

    To manually create a pypi release, please run the following commands:

    Additional requirement: wheel, twine (for uploading), account on pypi with proper permissions.

    pip install -U build\npython -m build --sdist --wheel\n\n# For pypi test (to check if some change to the installation did work)\ntwine upload --repository-url https://test.pypi.org/legacy/ dist/*\n\n# For production:\ntwine upload dist/*\n

    Please don't push non-releases to the productive / real pypi instance.

    "},{"location":"docker_quickstart/","title":"Using Freqtrade with Docker","text":"

    This page explains how to run the bot with Docker. It is not meant to work out of the box. You'll still need to read through the documentation and understand how to properly configure it.

    "},{"location":"docker_quickstart/#install-docker","title":"Install Docker","text":"

    Start by downloading and installing Docker / Docker Desktop for your platform:

    • Mac
    • Windows
    • Linux

    Docker compose install

    Freqtrade documentation assumes the use of Docker desktop (or the docker compose plugin). While the docker-compose standalone installation still works, it will require changing all docker compose commands from docker compose to docker-compose to work (e.g. docker compose up -d will become docker-compose up -d).

    Docker on windows

    If you just installed docker on a windows system, make sure to reboot your system, otherwise you might encounter unexplainable Problems related to network connectivity to docker containers.

    "},{"location":"docker_quickstart/#freqtrade-with-docker","title":"Freqtrade with docker","text":"

    Freqtrade provides an official Docker image on Dockerhub, as well as a docker compose file ready for usage.

    Note

    • The following section assumes that docker is installed and available to the logged in user.
    • All below commands use relative directories and will have to be executed from the directory containing the docker-compose.yml file.
    "},{"location":"docker_quickstart/#docker-quick-start","title":"Docker quick start","text":"

    Create a new directory and place the docker-compose file in this directory.

    mkdir ft_userdata\ncd ft_userdata/\n# Download the docker-compose file from the repository\ncurl https://raw.githubusercontent.com/freqtrade/freqtrade/stable/docker-compose.yml -o docker-compose.yml\n\n# Pull the freqtrade image\ndocker compose pull\n\n# Create user directory structure\ndocker compose run --rm freqtrade create-userdir --userdir user_data\n\n# Create configuration - Requires answering interactive questions\ndocker compose run --rm freqtrade new-config --config user_data/config.json\n

    The above snippet creates a new directory called ft_userdata, downloads the latest compose file and pulls the freqtrade image. The last 2 steps in the snippet create the directory with user_data, as well as (interactively) the default configuration based on your selections.

    How to edit the bot configuration?

    You can edit the configuration at any time, which is available as user_data/config.json (within the directory ft_userdata) when using the above configuration.

    You can also change the both Strategy and commands by editing the command section of your docker-compose.yml file.

    "},{"location":"docker_quickstart/#adding-a-custom-strategy","title":"Adding a custom strategy","text":"
    1. The configuration is now available as user_data/config.json
    2. Copy a custom strategy to the directory user_data/strategies/
    3. Add the Strategy' class name to the docker-compose.yml file

    The SampleStrategy is run by default.

    SampleStrategy is just a demo!

    The SampleStrategy is there for your reference and give you ideas for your own strategy. Please always backtest your strategy and use dry-run for some time before risking real money! You will find more information about Strategy development in the Strategy documentation.

    Once this is done, you're ready to launch the bot in trading mode (Dry-run or Live-trading, depending on your answer to the corresponding question you made above).

    docker compose up -d\n

    Default configuration

    While the configuration generated will be mostly functional, you will still need to verify that all options correspond to what you want (like Pricing, pairlist, ...) before starting the bot.

    "},{"location":"docker_quickstart/#accessing-the-ui","title":"Accessing the UI","text":"

    If you've selected to enable FreqUI in the new-config step, you will have freqUI available at port localhost:8080.

    You can now access the UI by typing localhost:8080 in your browser.

    UI Access on a remote server

    If you're running on a VPS, you should consider using either a ssh tunnel, or setup a VPN (openVPN, wireguard) to connect to your bot. This will ensure that freqUI is not directly exposed to the internet, which is not recommended for security reasons (freqUI does not support https out of the box). Setup of these tools is not part of this tutorial, however many good tutorials can be found on the internet. Please also read the API configuration with docker section to learn more about this configuration.

    "},{"location":"docker_quickstart/#monitoring-the-bot","title":"Monitoring the bot","text":"

    You can check for running instances with docker compose ps. This should list the service freqtrade as running. If that's not the case, best check the logs (see next point).

    "},{"location":"docker_quickstart/#docker-compose-logs","title":"Docker compose logs","text":"

    Logs will be written to: user_data/logs/freqtrade.log. You can also check the latest log with the command docker compose logs -f.

    "},{"location":"docker_quickstart/#database","title":"Database","text":"

    The database will be located at: user_data/tradesv3.sqlite

    "},{"location":"docker_quickstart/#updating-freqtrade-with-docker","title":"Updating freqtrade with docker","text":"

    Updating freqtrade when using docker is as simple as running the following 2 commands:

    # Download the latest image\ndocker compose pull\n# Restart the image\ndocker compose up -d\n

    This will first pull the latest image, and will then restart the container with the just pulled version.

    Check the Changelog

    You should always check the changelog for breaking changes / manual interventions required and make sure the bot starts correctly after the update.

    "},{"location":"docker_quickstart/#editing-the-docker-compose-file","title":"Editing the docker-compose file","text":"

    Advanced users may edit the docker-compose file further to include all possible options or arguments.

    All freqtrade arguments will be available by running docker compose run --rm freqtrade <command> <optional arguments>.

    docker compose for trade commands

    Trade commands (freqtrade trade <...>) should not be ran via docker compose run - but should use docker compose up -d instead. This makes sure that the container is properly started (including port forwardings) and will make sure that the container will restart after a system reboot. If you intend to use freqUI, please also ensure to adjust the configuration accordingly, otherwise the UI will not be available.

    docker compose run --rm

    Including --rm will remove the container after completion, and is highly recommended for all modes except trading mode (running with freqtrade trade command).

    Using docker without docker compose

    \"docker compose run --rm\" will require a compose file to be provided. Some freqtrade commands that don't require authentication such as list-pairs can be run with \"docker run --rm\" instead. For example docker run --rm freqtradeorg/freqtrade:stable list-pairs --exchange binance --quote BTC --print-json. This can be useful for fetching exchange information to add to your config.json without affecting your running containers.

    "},{"location":"docker_quickstart/#example-download-data-with-docker","title":"Example: Download data with docker","text":"

    Download backtesting data for 5 days for the pair ETH/BTC and 1h timeframe from Binance. The data will be stored in the directory user_data/data/ on the host.

    docker compose run --rm freqtrade download-data --pairs ETH/BTC --exchange binance --days 5 -t 1h\n

    Head over to the Data Downloading Documentation for more details on downloading data.

    "},{"location":"docker_quickstart/#example-backtest-with-docker","title":"Example: Backtest with docker","text":"

    Run backtesting in docker-containers for SampleStrategy and specified timerange of historical data, on 5m timeframe:

    docker compose run --rm freqtrade backtesting --config user_data/config.json --strategy SampleStrategy --timerange 20190801-20191001 -i 5m\n

    Head over to the Backtesting Documentation to learn more.

    "},{"location":"docker_quickstart/#additional-dependencies-with-docker","title":"Additional dependencies with docker","text":"

    If your strategy requires dependencies not included in the default image - it will be necessary to build the image on your host. For this, please create a Dockerfile containing installation steps for the additional dependencies (have a look at docker/Dockerfile.custom for an example).

    You'll then also need to modify the docker-compose.yml file and uncomment the build step, as well as rename the image to avoid naming collisions.

        image: freqtrade_custom\n    build:\n      context: .\n      dockerfile: \"./Dockerfile.<yourextension>\"\n

    You can then run docker compose build --pull to build the docker image, and run it using the commands described above.

    "},{"location":"docker_quickstart/#plotting-with-docker","title":"Plotting with docker","text":"

    Commands freqtrade plot-profit and freqtrade plot-dataframe (Documentation) are available by changing the image to *_plot in your docker-compose.yml file. You can then use these commands as follows:

    docker compose run --rm freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805\n

    The output will be stored in the user_data/plot directory, and can be opened with any modern browser.

    "},{"location":"docker_quickstart/#data-analysis-using-docker-compose","title":"Data analysis using docker compose","text":"

    Freqtrade provides a docker-compose file which starts up a jupyter lab server. You can run this server using the following command:

    docker compose -f docker/docker-compose-jupyter.yml up\n

    This will create a docker-container running jupyter lab, which will be accessible using https://127.0.0.1:8888/lab. Please use the link that's printed in the console after startup for simplified login.

    Since part of this image is built on your machine, it is recommended to rebuild the image from time to time to keep freqtrade (and dependencies) up-to-date.

    docker compose -f docker/docker-compose-jupyter.yml build --no-cache\n
    "},{"location":"docker_quickstart/#troubleshooting","title":"Troubleshooting","text":""},{"location":"docker_quickstart/#docker-on-windows","title":"Docker on Windows","text":"
    • Error: \"Timestamp for this request is outside of the recvWindow.\" The market api requests require a synchronized clock but the time in the docker container shifts a bit over time into the past. To fix this issue temporarily you need to run wsl --shutdown and restart docker again (a popup on windows 10 will ask you to do so). A permanent solution is either to host the docker container on a linux host or restart the wsl from time to time with the scheduler.

      taskkill /IM \"Docker Desktop.exe\" /F\nwsl --shutdown\nstart \"\" \"C:\\Program Files\\Docker\\Docker\\Docker Desktop.exe\"\n
    • Cannot connect to the API (Windows) If you're on windows and just installed Docker (desktop), make sure to reboot your System. Docker can have problems with network connectivity without a restart. You should obviously also make sure to have your settings accordingly.

    Warning

    Due to the above, we do not recommend the usage of docker on windows for production setups, but only for experimentation, datadownload and backtesting. Best use a linux-VPS for running freqtrade reliably.

    "},{"location":"edge/","title":"Edge positioning","text":"

    The Edge Positioning module uses probability to calculate your win rate and risk reward ratio. It will use these statistics to control your strategy trade entry points, position size and, stoploss.

    Deprecated functionality

    Edge positioning (or short Edge) is currently in maintenance mode only (we keep existing functionality alive) and should be considered as deprecated. It will currently not receive new features until either someone stepped forward to take up ownership of that module - or we'll decide to remove edge from freqtrade.

    Warning

    When using Edge positioning with a dynamic whitelist (VolumePairList), make sure to also use AgeFilter and set it to at least calculate_since_number_of_days to avoid problems with missing data.

    Note

    Edge Positioning only considers its own buy/sell/stoploss signals. It ignores the stoploss, trailing stoploss, and ROI settings in the strategy configuration file. Edge Positioning improves the performance of some trading strategies and decreases the performance of others.

    "},{"location":"edge/#introduction","title":"Introduction","text":"

    Trading strategies are not perfect. They are frameworks that are susceptible to the market and its indicators. Because the market is not at all predictable, sometimes a strategy will win and sometimes the same strategy will lose.

    To obtain an edge in the market, a strategy has to make more money than it loses. Making money in trading is not only about how often the strategy makes or loses money.

    It doesn't matter how often, but how much!

    A bad strategy might make 1 penny in ten transactions but lose 1 dollar in one transaction. If one only checks the number of winning trades, it would be misleading to think that the strategy is actually making a profit.

    The Edge Positioning module seeks to improve a strategy's winning probability and the money that the strategy will make on the long run.

    We raise the following question1:

    Which trade is a better option?

    a) A trade with 80% of chance of losing 100$ and 20% chance of winning 200$ b) A trade with 100% of chance of losing 30$

    Answer

    The expected value of a) is smaller than the expected value of b). Hence, b) represents a smaller loss in the long run. However, the answer is: it depends

    Another way to look at it is to ask a similar question:

    Which trade is a better option?

    a) A trade with 80% of chance of winning 100$ and 20% chance of losing 200$ b) A trade with 100% of chance of winning 30$

    Edge positioning tries to answer the hard questions about risk/reward and position size automatically, seeking to minimizes the chances of losing of a given strategy.

    "},{"location":"edge/#trading-winning-and-losing","title":"Trading, winning and losing","text":"

    Let's call \\(o\\) the return of a single transaction \\(o\\) where \\(o \\in \\mathbb{R}\\). The collection \\(O = \\{o_1, o_2, ..., o_N\\}\\) is the set of all returns of transactions made during a trading session. We say that \\(N\\) is the cardinality of \\(O\\), or, in lay terms, it is the number of transactions made in a trading session.

    Example

    In a session where a strategy made three transactions we can say that \\(O = \\{3.5, -1, 15\\}\\). That means that \\(N = 3\\) and \\(o_1 = 3.5\\), \\(o_2 = -1\\), \\(o_3 = 15\\).

    A winning trade is a trade where a strategy made money. Making money means that the strategy closed the position in a value that returned a profit, after all deducted fees. Formally, a winning trade will have a return \\(o_i > 0\\). Similarly, a losing trade will have a return \\(o_j \\leq 0\\). With that, we can discover the set of all winning trades, \\(T_{win}\\), as follows:

    \\[ T_{win} = \\{ o \\in O | o > 0 \\} \\]

    Similarly, we can discover the set of losing trades \\(T_{lose}\\) as follows:

    \\[ T_{lose} = \\{o \\in O | o \\leq 0\\} \\]

    Example

    In a section where a strategy made four transactions \\(O = \\{3.5, -1, 15, 0\\}\\): \\(T_{win} = \\{3.5, 15\\}\\) \\(T_{lose} = \\{-1, 0\\}\\)

    "},{"location":"edge/#win-rate-and-lose-rate","title":"Win Rate and Lose Rate","text":"

    The win rate \\(W\\) is the proportion of winning trades with respect to all the trades made by a strategy. We use the following function to compute the win rate:

    \\[W = \\frac{|T_{win}|}{N}\\]

    Where \\(W\\) is the win rate, \\(N\\) is the number of trades and, \\(T_{win}\\) is the set of all trades where the strategy made money.

    Similarly, we can compute the rate of losing trades:

    \\[ L = \\frac{|T_{lose}|}{N} \\]

    Where \\(L\\) is the lose rate, \\(N\\) is the amount of trades made and, \\(T_{lose}\\) is the set of all trades where the strategy lost money. Note that the above formula is the same as calculating \\(L = 1 \u2013 W\\) or \\(W = 1 \u2013 L\\)

    "},{"location":"edge/#risk-reward-ratio","title":"Risk Reward Ratio","text":"

    Risk Reward Ratio (\\(R\\)) is a formula used to measure the expected gains of a given investment against the risk of loss. It is basically what you potentially win divided by what you potentially lose. Formally:

    \\[ R = \\frac{\\text{potential_profit}}{\\text{potential_loss}} \\] Worked example of \\(R\\) calculation

    Let's say that you think that the price of stonecoin today is 10.0$. You believe that, because they will start mining stonecoin, it will go up to 15.0$ tomorrow. There is the risk that the stone is too hard, and the GPUs can't mine it, so the price might go to 0$ tomorrow. You are planning to invest 100$, which will give you 10 shares (100 / 10).

    Your potential profit is calculated as:

    \\(\\begin{aligned} \\text{potential_profit} &= (\\text{potential_price} - \\text{entry_price}) * \\frac{\\text{investment}}{\\text{entry_price}} \\\\ &= (15 - 10) * (100 / 10) \\\\ &= 50 \\end{aligned}\\)

    Since the price might go to 0$, the 100$ dollars invested could turn into 0.

    We do however use a stoploss of 15% - so in the worst case, we'll sell 15% below entry price (or at 8.5$).

    \\(\\begin{aligned} \\text{potential_loss} &= (\\text{entry_price} - \\text{stoploss}) * \\frac{\\text{investment}}{\\text{entry_price}} \\\\ &= (10 - 8.5) * (100 / 10)\\\\ &= 15 \\end{aligned}\\)

    We can compute the Risk Reward Ratio as follows:

    \\(\\begin{aligned} R &= \\frac{\\text{potential_profit}}{\\text{potential_loss}}\\\\ &= \\frac{50}{15}\\\\ &= 3.33 \\end{aligned}\\) What it effectively means is that the strategy have the potential to make 3.33$ for each 1$ invested.

    On a long horizon, that is, on many trades, we can calculate the risk reward by dividing the strategy' average profit on winning trades by the strategy' average loss on losing trades. We can calculate the average profit, \\(\\mu_{win}\\), as follows:

    \\[ \\text{average_profit} = \\mu_{win} = \\frac{\\text{sum_of_profits}}{\\text{count_winning_trades}} = \\frac{\\sum^{o \\in T_{win}} o}{|T_{win}|} \\]

    Similarly, we can calculate the average loss, \\(\\mu_{lose}\\), as follows:

    \\[ \\text{average_loss} = \\mu_{lose} = \\frac{\\text{sum_of_losses}}{\\text{count_losing_trades}} = \\frac{\\sum^{o \\in T_{lose}} o}{|T_{lose}|} \\]

    Finally, we can calculate the Risk Reward ratio, \\(R\\), as follows:

    \\[ R = \\frac{\\text{average_profit}}{\\text{average_loss}} = \\frac{\\mu_{win}}{\\mu_{lose}}\\\\ \\] Worked example of \\(R\\) calculation using mean profit/loss

    Let's say the strategy that we are using makes an average win \\(\\mu_{win} = 2.06\\) and an average loss \\(\\mu_{loss} = 4.11\\). We calculate the risk reward ratio as follows: \\(R = \\frac{\\mu_{win}}{\\mu_{loss}} = \\frac{2.06}{4.11} = 0.5012...\\)

    "},{"location":"edge/#expectancy","title":"Expectancy","text":"

    By combining the Win Rate \\(W\\) and the Risk Reward ratio \\(R\\) to create an expectancy ratio \\(E\\). A expectance ratio is the expected return of the investment made in a trade. We can compute the value of \\(E\\) as follows:

    \\[E = R * W - L\\]

    Calculating \\(E\\)

    Let's say that a strategy has a win rate \\(W = 0.28\\) and a risk reward ratio \\(R = 5\\). What this means is that the strategy is expected to make 5 times the investment around on 28% of the trades it makes. Working out the example: \\(E = R * W - L = 5 * 0.28 - 0.72 = 0.68\\)

    The expectancy worked out in the example above means that, on average, this strategy' trades will return 1.68 times the size of its losses. Said another way, the strategy makes 1.68$ for every 1$ it loses, on average.

    This is important for two reasons: First, it may seem obvious, but you know right away that you have a positive return. Second, you now have a number you can compare to other candidate systems to make decisions about which ones you employ.

    It is important to remember that any system with an expectancy greater than 0 is profitable using past data. The key is finding one that will be profitable in the future.

    You can also use this value to evaluate the effectiveness of modifications to this system.

    Note

    It's important to keep in mind that Edge is testing your expectancy using historical data, there's no guarantee that you will have a similar edge in the future. It's still vital to do this testing in order to build confidence in your methodology but be wary of \"curve-fitting\" your approach to the historical data as things are unlikely to play out the exact same way for future trades.

    "},{"location":"edge/#how-does-it-work","title":"How does it work?","text":"

    Edge combines dynamic stoploss, dynamic positions, and whitelist generation into one isolated module which is then applied to the trading strategy. If enabled in config, Edge will go through historical data with a range of stoplosses in order to find buy and sell/stoploss signals. It then calculates win rate and expectancy over N trades for each stoploss. Here is an example:

    Pair Stoploss Win Rate Risk Reward Ratio Expectancy XZC/ETH -0.01 0.50 1.176384 0.088 XZC/ETH -0.02 0.51 1.115941 0.079 XZC/ETH -0.03 0.52 1.359670 0.228 XZC/ETH -0.04 0.51 1.234539 0.117

    The goal here is to find the best stoploss for the strategy in order to have the maximum expectancy. In the above example stoploss at \\(3%\\) leads to the maximum expectancy according to historical data.

    Edge module then forces stoploss value it evaluated to your strategy dynamically.

    "},{"location":"edge/#position-size","title":"Position size","text":"

    Edge dictates the amount at stake for each trade to the bot according to the following factors:

    • Allowed capital at risk
    • Stoploss

    Allowed capital at risk is calculated as follows:

    Allowed capital at risk = (Capital available_percentage) X (Allowed risk per trade)\n

    Stoploss is calculated as described above with respect to historical data.

    The position size is calculated as follows:

    Position size = (Allowed capital at risk) / Stoploss\n

    Example:

    Let's say the stake currency is ETH and there is \\(10\\) ETH on the wallet. The capital available percentage is \\(50%\\) and the allowed risk per trade is \\(1\\%\\). Thus, the available capital for trading is \\(10 * 0.5 = 5\\) ETH and the allowed capital at risk would be \\(5 * 0.01 = 0.05\\) ETH.

    • Trade 1: The strategy detects a new buy signal in the XLM/ETH market. Edge Positioning calculates a stoploss of \\(2\\%\\) and a position of \\(0.05 / 0.02 = 2.5\\) ETH. The bot takes a position of \\(2.5\\) ETH in the XLM/ETH market.
    • Trade 2: The strategy detects a buy signal on the BTC/ETH market while Trade 1 is still open. Edge Positioning calculates the stoploss of \\(4\\%\\) on this market. Thus, Trade 2 position size is \\(0.05 / 0.04 = 1.25\\) ETH.

    Available Capital \\(\\neq\\) Available in wallet

    The available capital for trading didn't change in Trade 2 even with Trade 1 still open. The available capital is not the free amount in the wallet.

    • Trade 3: The strategy detects a buy signal in the ADA/ETH market. Edge Positioning calculates a stoploss of \\(1\\%\\) and a position of \\(0.05 / 0.01 = 5\\) ETH. Since Trade 1 has \\(2.5\\) ETH blocked and Trade 2 has \\(1.25\\) ETH blocked, there is only \\(5 - 1.25 - 2.5 = 1.25\\) ETH available. Hence, the position size of Trade 3 is \\(1.25\\) ETH.

    Available Capital Updates

    The available capital does not change before a position is sold. After a trade is closed the Available Capital goes up if the trade was profitable or goes down if the trade was a loss.

    • The strategy detects a sell signal in the XLM/ETH market. The bot exits Trade 1 for a profit of \\(1\\) ETH. The total capital in the wallet becomes \\(11\\) ETH and the available capital for trading becomes \\(5.5\\) ETH.
    • Trade 4 The strategy detects a new buy signal int the XLM/ETH market. Edge Positioning calculates the stoploss of \\(2\\%\\), and the position size of \\(0.055 / 0.02 = 2.75\\) ETH.
    "},{"location":"edge/#edge-command-reference","title":"Edge command reference","text":"
    usage: freqtrade edge [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                      [--userdir PATH] [-s NAME] [--strategy-path PATH]\n                      [-i TIMEFRAME] [--timerange TIMERANGE]\n                      [--data-format-ohlcv {json,jsongz,hdf5}]\n                      [--max-open-trades INT] [--stake-amount STAKE_AMOUNT]\n                      [--fee FLOAT] [-p PAIRS [PAIRS ...]]\n                      [--stoplosses STOPLOSS_RANGE]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --data-format-ohlcv {json,jsongz,hdf5}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `None`).\n  --max-open-trades INT\n                        Override the value of the `max_open_trades`\n                        configuration setting.\n  --stake-amount STAKE_AMOUNT\n                        Override the value of the `stake_amount` configuration\n                        setting.\n  --fee FLOAT           Specify fee ratio. Will be applied twice (on trade\n                        entry and exit).\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --stoplosses STOPLOSS_RANGE\n                        Defines a range of stoploss values against which edge\n                        will assess the strategy. The format is \"min,max,step\"\n                        (without any space). Example:\n                        `--stoplosses=-0.01,-0.1,-0.001`\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n
    "},{"location":"edge/#configurations","title":"Configurations","text":"

    Edge module has following configuration options:

    Parameter Description enabled If true, then Edge will run periodically. Defaults to false. Datatype: Boolean process_throttle_secs How often should Edge run in seconds. Defaults to 3600 (once per hour). Datatype: Integer calculate_since_number_of_days Number of days of data against which Edge calculates Win Rate, Risk Reward and Expectancy. Note that it downloads historical data so increasing this number would lead to slowing down the bot. Defaults to 7. Datatype: Integer allowed_risk Ratio of allowed risk per trade. Defaults to 0.01 (1%)). Datatype: Float stoploss_range_min Minimum stoploss. Defaults to -0.01. Datatype: Float stoploss_range_max Maximum stoploss. Defaults to -0.10. Datatype: Float stoploss_range_step As an example if this is set to -0.01 then Edge will test the strategy for [-0.01, -0,02, -0,03 ..., -0.09, -0.10] ranges. Note than having a smaller step means having a bigger range which could lead to slow calculation. If you set this parameter to -0.001, you then slow down the Edge calculation by a factor of 10. Defaults to -0.001. Datatype: Float minimum_winrate It filters out pairs which don't have at least minimum_winrate. This comes handy if you want to be conservative and don't comprise win rate in favour of risk reward ratio. Defaults to 0.60. Datatype: Float minimum_expectancy It filters out pairs which have the expectancy lower than this number. Having an expectancy of 0.20 means if you put 10$ on a trade you expect a 12$ return. Defaults to 0.20. Datatype: Float min_trade_number When calculating W, R and E (expectancy) against historical data, you always want to have a minimum number of trades. The more this number is the more Edge is reliable. Having a win rate of 100% on a single trade doesn't mean anything at all. But having a win rate of 70% over past 100 trades means clearly something. Defaults to 10 (it is highly recommended not to decrease this number). Datatype: Integer max_trade_duration_minute Edge will filter out trades with long duration. If a trade is profitable after 1 month, it is hard to evaluate the strategy based on it. But if most of trades are profitable and they have maximum duration of 30 minutes, then it is clearly a good sign.NOTICE: While configuring this value, you should take into consideration your timeframe. As an example filtering out trades having duration less than one day for a strategy which has 4h interval does not make sense. Default value is set assuming your strategy interval is relatively small (1m or 5m, etc.).Defaults to 1440 (one day). Datatype: Integer remove_pumps Edge will remove sudden pumps in a given market while going through historical data. However, given that pumps happen very often in crypto markets, we recommend you keep this off.Defaults to false. Datatype: Boolean"},{"location":"edge/#running-edge-independently","title":"Running Edge independently","text":"

    You can run Edge independently in order to see in details the result. Here is an example:

    freqtrade edge\n

    An example of its output:

    pair stoploss win rate risk reward ratio required risk reward expectancy total number of trades average duration (min) AGI/BTC -0.02 0.64 5.86 0.56 3.41 14 54 NXS/BTC -0.03 0.64 2.99 0.57 1.54 11 26 LEND/BTC -0.02 0.82 2.05 0.22 1.50 11 36 VIA/BTC -0.01 0.55 3.01 0.83 1.19 11 48 MTH/BTC -0.09 0.56 2.82 0.80 1.12 18 52 ARDR/BTC -0.04 0.42 3.14 1.40 0.73 12 42 BCPT/BTC -0.01 0.71 1.34 0.40 0.67 14 30 WINGS/BTC -0.02 0.56 1.97 0.80 0.65 27 42 VIBE/BTC -0.02 0.83 0.91 0.20 0.59 12 35 MCO/BTC -0.02 0.79 0.97 0.27 0.55 14 31 GNT/BTC -0.02 0.50 2.06 1.00 0.53 18 24 HOT/BTC -0.01 0.17 7.72 4.81 0.50 209 7 SNM/BTC -0.03 0.71 1.06 0.42 0.45 17 38 APPC/BTC -0.02 0.44 2.28 1.27 0.44 25 43 NEBL/BTC -0.03 0.63 1.29 0.58 0.44 19 59

    Edge produced the above table by comparing calculate_since_number_of_days to minimum_expectancy to find min_trade_number historical information based on the config file. The timerange Edge uses for its comparisons can be further limited by using the --timerange switch.

    In live and dry-run modes, after the process_throttle_secs has passed, Edge will again process calculate_since_number_of_days against minimum_expectancy to find min_trade_number. If no min_trade_number is found, the bot will return \"whitelist empty\". Depending on the trade strategy being deployed, \"whitelist empty\" may be return much of the time - or all of the time. The use of Edge may also cause trading to occur in bursts, though this is rare.

    If you encounter \"whitelist empty\" a lot, condsider tuning calculate_since_number_of_days, minimum_expectancy and min_trade_number to align to the trading frequency of your strategy.

    "},{"location":"edge/#update-cached-pairs-with-the-latest-data","title":"Update cached pairs with the latest data","text":"

    Edge requires historic data the same way as backtesting does. Please refer to the Data Downloading section of the documentation for details.

    "},{"location":"edge/#precising-stoploss-range","title":"Precising stoploss range","text":"
    freqtrade edge --stoplosses=-0.01,-0.1,-0.001 #min,max,step\n
    "},{"location":"edge/#advanced-use-of-timerange","title":"Advanced use of timerange","text":"
    freqtrade edge --timerange=20181110-20181113\n

    Doing --timerange=-20190901 will get all available data until September 1st (excluding September 1st 2019).

    The full timerange specification:

    • Use tickframes till 2018/01/31: --timerange=-20180131
    • Use tickframes since 2018/01/31: --timerange=20180131-
    • Use tickframes since 2018/01/31 till 2018/03/01 : --timerange=20180131-20180301
    • Use tickframes between POSIX timestamps 1527595200 1527618600: --timerange=1527595200-1527618600
    1. Question extracted from MIT Opencourseware S096 - Mathematics with applications in Finance: https://ocw.mit.edu/courses/mathematics/18-s096-topics-in-mathematics-with-applications-in-finance-fall-2013/ \u21a9

    "},{"location":"exchanges/","title":"Exchange-specific Notes","text":"

    This page combines common gotchas and Information which are exchange-specific and most likely don't apply to other exchanges.

    "},{"location":"exchanges/#exchange-configuration","title":"Exchange configuration","text":"

    Freqtrade is based on CCXT library that supports over 100 cryptocurrency exchange markets and trading APIs. The complete up-to-date list can be found in the CCXT repo homepage. However, the bot was tested by the development team with only a few exchanges. A current list of these can be found in the \"Home\" section of this documentation.

    Feel free to test other exchanges and submit your feedback or PR to improve the bot or confirm exchanges that work flawlessly..

    Some exchanges require special configuration, which can be found below.

    "},{"location":"exchanges/#sample-exchange-configuration","title":"Sample exchange configuration","text":"

    A exchange configuration for \"binance\" would look as follows:

    \"exchange\": {\n    \"name\": \"binance\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"ccxt_config\": {},\n    \"ccxt_async_config\": {},\n    // ... \n
    "},{"location":"exchanges/#setting-rate-limits","title":"Setting rate limits","text":"

    Usually, rate limits set by CCXT are reliable and work well. In case of problems related to rate-limits (usually DDOS Exceptions in your logs), it's easy to change rateLimit settings to other values.

    \"exchange\": {\n    \"name\": \"kraken\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"ccxt_config\": {\"enableRateLimit\": true},\n    \"ccxt_async_config\": {\n        \"enableRateLimit\": true,\n        \"rateLimit\": 3100\n    },\n

    This configuration enables kraken, as well as rate-limiting to avoid bans from the exchange. \"rateLimit\": 3100 defines a wait-event of 3.1s between each call. This can also be completely disabled by setting \"enableRateLimit\" to false.

    Note

    Optimal settings for rate-limiting depend on the exchange and the size of the whitelist, so an ideal parameter will vary on many other settings. We try to provide sensible defaults per exchange where possible, if you encounter bans please make sure that \"enableRateLimit\" is enabled and increase the \"rateLimit\" parameter step by step.

    "},{"location":"exchanges/#binance","title":"Binance","text":"

    Server location and geo-ip restrictions

    Please be aware that Binance restricts API access regarding the server country. The current and non-exhaustive countries blocked are Canada, Malaysia, Netherlands and United States. Please go to binance terms > b. Eligibility to find up to date list.

    Binance supports time_in_force.

    Stoploss on Exchange

    Binance supports stoploss_on_exchange and uses stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange. On futures, Binance supports both stop-limit as well as stop-market orders. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type to use.

    "},{"location":"exchanges/#binance-blacklist-recommendation","title":"Binance Blacklist recommendation","text":"

    For Binance, it is suggested to add \"BNB/<STAKE>\" to your blacklist to avoid issues, unless you are willing to maintain enough extra BNB on the account or unless you're willing to disable using BNB for fees. Binance accounts may use BNB for fees, and if a trade happens to be on BNB, further trades may consume this position and make the initial BNB trade unsellable as the expected amount is not there anymore.

    If not enough BNB is available to cover transaction fees, then fees will not be covered by BNB and no fee reduction will occur. Freqtrade will never buy BNB to cover for fees. BNB needs to be bought and monitored manually to this end.

    "},{"location":"exchanges/#binance-sites","title":"Binance sites","text":"

    Binance has been split into 2, and users must use the correct ccxt exchange ID for their exchange, otherwise API keys are not recognized.

    • binance.com - International users. Use exchange id: binance.
    • binance.us - US based users. Use exchange id: binanceus.
    "},{"location":"exchanges/#binance-rsa-keys","title":"Binance RSA keys","text":"

    Freqtrade supports binance RSA API keys.

    We recommend to use them as environment variable.

    export FREQTRADE__EXCHANGE__SECRET=\"$(cat ./rsa_binance.private)\"\n

    They can however also be configured via configuration file. Since json doesn't support multi-line strings, you'll have to replace all newlines with \\n to have a valid json file.

    // ...\n \"key\": \"<someapikey>\",\n \"secret\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvQIBABACAFQA<...>s8KX8=\\n-----END PRIVATE KEY-----\"\n// ...\n
    "},{"location":"exchanges/#binance-futures","title":"Binance Futures","text":"

    Binance has specific (unfortunately complex) Futures Trading Quantitative Rules which need to be followed, and which prohibit a too low stake-amount (among others) for too many orders. Violating these rules will result in a trading restriction.

    When trading on Binance Futures market, orderbook must be used because there is no price ticker data for futures.

      \"entry_pricing\": {\n      \"use_order_book\": true,\n      \"order_book_top\": 1,\n      \"check_depth_of_market\": {\n          \"enabled\": false,\n          \"bids_to_ask_delta\": 1\n      }\n  },\n  \"exit_pricing\": {\n      \"use_order_book\": true,\n      \"order_book_top\": 1\n  },\n
    "},{"location":"exchanges/#binance-futures-settings","title":"Binance futures settings","text":"

    Users will also have to have the futures-setting \"Position Mode\" set to \"One-way Mode\", and \"Asset Mode\" set to \"Single-Asset Mode\". These settings will be checked on startup, and freqtrade will show an error if this setting is wrong.

    Freqtrade will not attempt to change these settings.

    "},{"location":"exchanges/#bingx","title":"Bingx","text":"

    BingX supports time_in_force with settings \"GTC\" (good till cancelled), \"IOC\" (immediate-or-cancel) and \"PO\" (Post only) settings.

    Stoploss on Exchange

    Bingx supports stoploss_on_exchange and can use both stop-limit and stop-market orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange.

    "},{"location":"exchanges/#kraken","title":"Kraken","text":"

    Kraken supports time_in_force with settings \"GTC\" (good till cancelled), \"IOC\" (immediate-or-cancel) and \"PO\" (Post only) settings.

    Stoploss on Exchange

    Kraken supports stoploss_on_exchange and can use both stop-loss-market and stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type to use.

    "},{"location":"exchanges/#historic-kraken-data","title":"Historic Kraken data","text":"

    The Kraken API does only provide 720 historic candles, which is sufficient for Freqtrade dry-run and live trade modes, but is a problem for backtesting. To download data for the Kraken exchange, using --dl-trades is mandatory, otherwise the bot will download the same 720 candles over and over, and you'll not have enough backtest data.

    To speed up downloading, you can download the trades zip files kraken provides. These are usually updated once per quarter. Freqtrade expects these files to be placed in user_data/data/kraken/trades_csv.

    A structure as follows can make sense if using incremental files, with the \"full\" history in one directory, and incremental files in different directories. The assumption for this mode is that the data is downloaded and unzipped keeping filenames as they are. Duplicate content will be ignored (based on timestamp) - though the assumption is that there is no gap in the data.

    This means, if your \"full\" history ends in Q4 2022 - then both incremental updates Q1 2023 and Q2 2023 are available. Not having this will lead to incomplete data, and therefore invalid results while using the data.

    \u2514\u2500\u2500 trades_csv\n\u00a0 \u00a0 \u251c\u2500\u2500 Kraken_full_history\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 BCHEUR.csv\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 XBTEUR.csv\n \u00a0\u00a0 \u251c\u2500\u2500 Kraken_Trading_History_Q1_2023\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u251c\u2500\u2500 BCHEUR.csv\n \u00a0\u00a0 \u2502\u00a0\u00a0 \u2514\u2500\u2500 XBTEUR.csv\n \u00a0\u00a0 \u2514\u2500\u2500 Kraken_Trading_History_Q2_2023\n \u00a0\u00a0  \u00a0\u00a0 \u251c\u2500\u2500 BCHEUR.csv\n \u00a0\u00a0  \u00a0\u00a0 \u2514\u2500\u2500 XBTEUR.csv\n

    You can convert these files into freqtrade files:

    freqtrade convert-trade-data --exchange kraken --format-from kraken_csv --format-to feather\n# Convert trade data to different ohlcv timeframes\nfreqtrade trades-to-ohlcv -p BTC/EUR BCH/EUR --exchange kraken -t 1m 5m 15m 1h\n

    The converted data also makes downloading data possible, and will start the download after the latest loaded trade.

    freqtrade download-data --exchange kraken --dl-trades -p BTC/EUR BCH/EUR \n

    Downloading data from kraken

    Downloading kraken data will require significantly more memory (RAM) than any other exchange, as the trades-data needs to be converted into candles on your machine. It will also take a long time, as freqtrade will need to download every single trade that happened on the exchange for the pair / timerange combination, therefore please be patient.

    rateLimit tuning

    Please pay attention that rateLimit configuration entry holds delay in milliseconds between requests, NOT requests\\sec rate. So, in order to mitigate Kraken API \"Rate limit exceeded\" exception, this configuration should be increased, NOT decreased.

    "},{"location":"exchanges/#kucoin","title":"Kucoin","text":"

    Kucoin requires a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows:

    \"exchange\": {\n    \"name\": \"kucoin\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"password\": \"your_exchange_api_key_password\",\n    // ...\n}\n

    Kucoin supports time_in_force.

    Stoploss on Exchange

    Kucoin supports stoploss_on_exchange and can use both stop-loss-market and stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type of stoploss shall be used.

    "},{"location":"exchanges/#kucoin-blacklists","title":"Kucoin Blacklists","text":"

    For Kucoin, it is suggested to add \"KCS/<STAKE>\" to your blacklist to avoid issues, unless you are willing to maintain enough extra KCS on the account or unless you're willing to disable using KCS for fees. Kucoin accounts may use KCS for fees, and if a trade happens to be on KCS, further trades may consume this position and make the initial KCS trade unsellable as the expected amount is not there anymore.

    "},{"location":"exchanges/#htx-formerly-huobi","title":"HTX (formerly Huobi)","text":"

    Stoploss on Exchange

    HTX supports stoploss_on_exchange and uses stop-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange.

    "},{"location":"exchanges/#okx-former-okex","title":"OKX (former OKEX)","text":"

    OKX requires a passphrase for each api key, you will therefore need to add this key into the configuration so your exchange section looks as follows:

    \"exchange\": {\n    \"name\": \"okx\",\n    \"key\": \"your_exchange_key\",\n    \"secret\": \"your_exchange_secret\",\n    \"password\": \"your_exchange_api_key_password\",\n    // ...\n}\n

    Warning

    OKX only provides 100 candles per api call. Therefore, the strategy will only have a pretty low amount of data available in backtesting mode.

    Futures

    OKX Futures has the concept of \"position mode\" - which can be \"Buy/Sell\" or long/short (hedge mode). Freqtrade supports both modes (we recommend to use Buy/Sell mode) - but changing the mode mid-trading is not supported and will lead to exceptions and failures to place trades. OKX also only provides MARK candles for the past ~3 months. Backtesting futures prior to that date will therefore lead to slight deviations, as funding-fees cannot be calculated correctly without this data.

    "},{"location":"exchanges/#gateio","title":"Gate.io","text":"

    Stoploss on Exchange

    Gate.io supports stoploss_on_exchange and uses stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange..

    Gate.io allows the use of POINT to pay for fees. As this is not a tradable currency (no regular market available), automatic fee calculations will fail (and default to a fee of 0). The configuration parameter exchange.unknown_fee_rate can be used to specify the exchange rate between Point and the stake currency. Obviously, changing the stake-currency will also require changes to this value.

    "},{"location":"exchanges/#bybit","title":"Bybit","text":"

    Futures trading on bybit is currently supported for USDT markets, and will use isolated futures mode.

    On startup, freqtrade will set the position mode to \"One-way Mode\" for the whole (sub)account. This avoids making this call over and over again (slowing down bot operations), but means that changes to this setting may result in exceptions and errors.

    As bybit doesn't provide funding rate history, the dry-run calculation is used for live trades as well.

    API Keys for live futures trading must have the following permissions: * Read-write * Contract - Orders * Contract - Positions

    We do strongly recommend to limit all API keys to the IP you're going to use it from.

    Unified accounts

    Freqtrade assumes accounts to be dedicated to the bot. We therefore recommend the usage of one subaccount per bot. This is especially important when using unified accounts. Other configurations (multiple bots on one account, manual non-bot trades on the bot account) are not supported and may lead to unexpected behavior.

    Stoploss on Exchange

    Bybit (futures only) supports stoploss_on_exchange and uses stop-loss-limit orders. It provides great advantages, so we recommend to benefit from it by enabling stoploss on exchange. On futures, Bybit supports both stop-limit as well as stop-market orders. You can use either \"limit\" or \"market\" in the order_types.stoploss configuration setting to decide which type to use.

    "},{"location":"exchanges/#bitmart","title":"Bitmart","text":"

    Bitmart requires the API key Memo (the name you give the API key) to go along with the exchange key and secret. It's therefore required to pass the UID as well.

    \"exchange\": {\n    \"name\": \"bitmart\",\n    \"uid\": \"your_bitmart_api_key_memo\",\n    \"secret\": \"your_exchange_secret\",\n    \"password\": \"your_exchange_api_key_password\",\n    // ...\n}\n

    Necessary Verification

    Bitmart requires Verification Lvl2 to successfully trade on the spot market through the API - even though trading via UI works just fine with just Lvl1 verification.

    "},{"location":"exchanges/#all-exchanges","title":"All exchanges","text":"

    Should you experience constant errors with Nonce (like InvalidNonce), it is best to regenerate the API keys. Resetting Nonce is difficult and it's usually easier to regenerate the API keys.

    "},{"location":"exchanges/#random-notes-for-other-exchanges","title":"Random notes for other exchanges","text":"
    • The Ocean (exchange id: theocean) exchange uses Web3 functionality and requires web3 python package to be installed:
    $ pip3 install web3\n
    "},{"location":"exchanges/#getting-latest-price-incomplete-candles","title":"Getting latest price / Incomplete candles","text":"

    Most exchanges return current incomplete candle via their OHLCV/klines API interface. By default, Freqtrade assumes that incomplete candle is fetched from the exchange and removes the last candle assuming it's the incomplete candle.

    Whether your exchange returns incomplete candles or not can be checked using the helper script from the Contributor documentation.

    Due to the danger of repainting, Freqtrade does not allow you to use this incomplete candle.

    However, if it is based on the need for the latest price for your strategy - then this requirement can be acquired using the data provider from within the strategy.

    "},{"location":"exchanges/#advanced-freqtrade-exchange-configuration","title":"Advanced Freqtrade Exchange configuration","text":"

    Advanced options can be configured using the _ft_has_params setting, which will override Defaults and exchange-specific behavior.

    Available options are listed in the exchange-class as _ft_has_default.

    For example, to test the order type FOK with Kraken, and modify candle limit to 200 (so you only get 200 candles per API call):

    \"exchange\": {\n    \"name\": \"kraken\",\n    \"_ft_has_params\": {\n        \"order_time_in_force\": [\"GTC\", \"FOK\"],\n        \"ohlcv_candle_limit\": 200\n        }\n    //...\n}\n

    Warning

    Please make sure to fully understand the impacts of these settings before modifying them.

    "},{"location":"faq/","title":"Freqtrade FAQ","text":""},{"location":"faq/#supported-markets","title":"Supported Markets","text":"

    Freqtrade supports spot trading, as well as (isolated) futures trading for some selected exchanges. Please refer to the documentation start page for an up-to-date list of supported exchanges.

    "},{"location":"faq/#can-my-bot-open-short-positions","title":"Can my bot open short positions?","text":"

    Freqtrade can open short positions in futures markets. This requires the strategy to be made for this - and \"trading_mode\": \"futures\" in the configuration. Please make sure to read the relevant documentation page first.

    In spot markets, you can in some cases use leveraged spot tokens, which reflect an inverted pair (eg. BTCUP/USD, BTCDOWN/USD, ETHBULL/USD, ETHBEAR/USD,...) which can be traded with Freqtrade.

    "},{"location":"faq/#can-my-bot-trade-options-or-futures","title":"Can my bot trade options or futures?","text":"

    Futures trading is supported for selected exchanges. Please refer to the documentation start page for an up-to-date list of supported exchanges.

    "},{"location":"faq/#beginner-tips-tricks","title":"Beginner Tips & Tricks","text":"
    • When you work with your strategy & hyperopt file you should use a proper code editor like VSCode or PyCharm. A good code editor will provide syntax highlighting as well as line numbers, making it easy to find syntax errors (most likely pointed out by Freqtrade during startup).
    "},{"location":"faq/#freqtrade-common-questions","title":"Freqtrade common questions","text":""},{"location":"faq/#can-freqtrade-open-multiple-positions-on-the-same-pair-in-parallel","title":"Can freqtrade open multiple positions on the same pair in parallel?","text":"

    No. Freqtrade will only open one position per pair at a time. You can however use the adjust_trade_position() callback to adjust an open position.

    Backtesting provides an option for this in --eps - however this is only there to highlight \"hidden\" signals, and will not work in live.

    "},{"location":"faq/#the-bot-does-not-start","title":"The bot does not start","text":"

    Running the bot with freqtrade trade --config config.json shows the output freqtrade: command not found.

    This could be caused by the following reasons:

    • The virtual environment is not active.
      • Run source .venv/bin/activate to activate the virtual environment.
    • The installation did not complete successfully.
      • Please check the Installation documentation.
    "},{"location":"faq/#i-have-waited-5-minutes-why-hasnt-the-bot-made-any-trades-yet","title":"I have waited 5 minutes, why hasn't the bot made any trades yet?","text":"
    • Depending on the buy strategy, the amount of whitelisted coins, the situation of the market etc, it can take up to hours to find a good entry position for a trade. Be patient!
    • It may be because of a configuration error. It's best to check the logs, they usually tell you if the bot is simply not getting buy signals (only heartbeat messages), or if there is something wrong (errors / exceptions in the log).
    "},{"location":"faq/#i-have-made-12-trades-already-why-is-my-total-profit-negative","title":"I have made 12 trades already, why is my total profit negative?","text":"

    I understand your disappointment but unfortunately 12 trades is just not enough to say anything. If you run backtesting, you can see that the current algorithm does leave you on the plus side, but that is after thousands of trades and even there, you will be left with losses on specific coins that you have traded tens if not hundreds of times. We of course constantly aim to improve the bot but it will always be a gamble, which should leave you with modest wins on monthly basis but you can't say much from few trades.

    "},{"location":"faq/#id-like-to-make-changes-to-the-config-can-i-do-that-without-having-to-kill-the-bot","title":"I\u2019d like to make changes to the config. Can I do that without having to kill the bot?","text":"

    Yes. You can edit your config and use the /reload_config command to reload the configuration. The bot will stop, reload the configuration and strategy and will restart with the new configuration and strategy.

    "},{"location":"faq/#why-does-my-bot-not-sell-everything-it-bought","title":"Why does my bot not sell everything it bought?","text":"

    This is called \"coin dust\" and can happen on all exchanges. It happens because many exchanges subtract fees from the \"receiving currency\" - so you buy 100 COIN - but you only get 99.9 COIN. As COIN is trading in full lot sizes (1COIN steps), you cannot sell 0.9 COIN (or 99.9 COIN) - but you need to round down to 99 COIN.

    This is not a bot-problem, but will also happen while manual trading.

    While freqtrade can handle this (it'll sell 99 COIN), fees are often below the minimum tradable lot-size (you can only trade full COIN, not 0.9 COIN). Leaving the dust (0.9 COIN) on the exchange makes usually sense, as the next time freqtrade buys COIN, it'll eat into the remaining small balance, this time selling everything it bought, and therefore slowly declining the dust balance (although it most likely will never reach exactly 0).

    Where possible (e.g. on binance), the use of the exchange's dedicated fee currency will fix this. On binance, it's sufficient to have BNB in your account, and have \"Pay fees in BNB\" enabled in your profile. Your BNB balance will slowly decline (as it's used to pay fees) - but you'll no longer encounter dust (Freqtrade will include the fees in the profit calculations). Other exchanges don't offer such possibilities, where it's simply something you'll have to accept or move to a different exchange.

    "},{"location":"faq/#i-deposited-more-funds-to-the-exchange-but-my-bot-doesnt-recognize-this","title":"I deposited more funds to the exchange, but my bot doesn't recognize this","text":"

    Freqtrade will update the exchange balance when necessary (Before placing an order). RPC calls (Telegram's /balance, API calls to /balance) can trigger an update at max. once per hour.

    If adjust_trade_position is enabled (and the bot has open trades eligible for position adjustments) - then the wallets will be refreshed once per hour. To force an immediate update, you can use /reload_config - which will restart the bot.

    "},{"location":"faq/#i-want-to-use-incomplete-candles","title":"I want to use incomplete candles","text":"

    Freqtrade will not provide incomplete candles to strategies. Using incomplete candles will lead to repainting and consequently to strategies with \"ghost\" buys, which are impossible to both backtest, and verify after they happened.

    You can use \"current\" market data by using the dataprovider's orderbook or ticker methods - which however cannot be used during backtesting.

    "},{"location":"faq/#is-there-a-setting-to-only-exit-the-trades-being-held-and-not-perform-any-new-entries","title":"Is there a setting to only Exit the trades being held and not perform any new Entries?","text":"

    You can use the /stopentry command in Telegram to prevent future trade entry, followed by /forceexit all (sell all open trades).

    "},{"location":"faq/#i-want-to-run-multiple-bots-on-the-same-machine","title":"I want to run multiple bots on the same machine","text":"

    Please look at the advanced setup documentation Page.

    "},{"location":"faq/#im-getting-missing-data-fillup-messages-in-the-log","title":"I'm getting \"Missing data fillup\" messages in the log","text":"

    This message is just a warning that the latest candles had missing candles in them. Depending on the exchange, this can indicate that the pair didn't have a trade for the timeframe you are using - and the exchange does only return candles with volume. On low volume pairs, this is a rather common occurrence.

    If this happens for all pairs in the pairlist, this might indicate a recent exchange downtime. Please check your exchange's public channels for details.

    Irrespectively of the reason, Freqtrade will fill up these candles with \"empty\" candles, where open, high, low and close are set to the previous candle close - and volume is empty. In a chart, this will look like a _ - and is aligned with how exchanges usually represent 0 volume candles.

    "},{"location":"faq/#im-getting-price-jump-between-2-candles-detected","title":"I'm getting \"Price jump between 2 candles detected\"","text":"

    This message is a warning that the candles had a price jump of > 30%. This might be a sign that the pair stopped trading, and some token exchange took place (e.g. COCOS in 2021 - where price jumped from 0.0000154 to 0.01621). This message is often accompanied by \"Missing data fillup\" - as trading on such pairs is often stopped for some time.

    "},{"location":"faq/#im-getting-outdated-history-for-pair-xxx-in-the-log","title":"I'm getting \"Outdated history for pair xxx\" in the log","text":"

    The bot is trying to tell you that it got an outdated last candle (not the last complete candle). As a consequence, Freqtrade will not enter a trade for this pair - as trading on old information is usually not what is desired.

    This warning can point to one of the below problems:

    • Exchange downtime -> Check your exchange status page / blog / twitter feed for details.
    • Wrong system time -> Ensure your system-time is correct.
    • Barely traded pair -> Check the pair on the exchange webpage, look at the timeframe your strategy uses. If the pair does not have any volume in some candles (usually visualized with a \"volume 0\" bar, and a \"_\" as candle), this pair did not have any trades in this timeframe. These pairs should ideally be avoided, as they can cause problems with order-filling.
    • API problem -> API returns wrong data (this only here for completeness, and should not happen with supported exchanges).
    "},{"location":"faq/#im-getting-the-exchange-xxx-does-not-support-market-orders-message-and-cannot-run-my-strategy","title":"I'm getting the \"Exchange XXX does not support market orders.\" message and cannot run my strategy","text":"

    As the message says, your exchange does not support market orders and you have one of the order types set to \"market\". Your strategy was probably written with other exchanges in mind and sets \"market\" orders for \"stoploss\" orders, which is correct and preferable for most of the exchanges supporting market orders (but not for Gate.io).

    To fix this, redefine order types in the strategy to use \"limit\" instead of \"market\":

        order_types = {\n        ...\n        \"stoploss\": \"limit\",\n        ...\n    }\n

    The same fix should be applied in the configuration file, if order types are defined in your custom config rather than in the strategy.

    "},{"location":"faq/#im-trying-to-start-the-bot-live-but-get-an-api-permission-error","title":"I'm trying to start the bot live, but get an API permission error","text":"

    Errors like Invalid API-key, IP, or permissions for action mean exactly what they actually say. Your API key is either invalid (copy/paste error? check for leading/trailing spaces in the config), expired, or the IP you're running the bot from is not enabled in the Exchange's API console. Usually, the permission \"Spot Trading\" (or the equivalent in the exchange you use) will be necessary. Futures will usually have to be enabled specifically.

    "},{"location":"faq/#how-do-i-search-the-bot-logs-for-something","title":"How do I search the bot logs for something?","text":"

    By default, the bot writes its log into stderr stream. This is implemented this way so that you can easily separate the bot's diagnostics messages from Backtesting, Edge and Hyperopt results, output from other various Freqtrade utility sub-commands, as well as from the output of your custom print()'s you may have inserted into your strategy. So if you need to search the log messages with the grep utility, you need to redirect stderr to stdout and disregard stdout.

    • In unix shells, this normally can be done as simple as:
      $ freqtrade --some-options 2>&1 >/dev/null | grep 'something'\n
      (note, 2>&1 and >/dev/null should be written in this order)
    • Bash interpreter also supports so called process substitution syntax, you can grep the log for a string with it as:
      $ freqtrade --some-options 2> >(grep 'something') >/dev/null\n
      or
      $ freqtrade --some-options 2> >(grep -v 'something' 1>&2)\n
    • You can also write the copy of Freqtrade log messages to a file with the --logfile option:
      $ freqtrade --logfile /path/to/mylogfile.log --some-options\n
      and then grep it as:
      $ cat /path/to/mylogfile.log | grep 'something'\n
      or even on the fly, as the bot works and the log file grows:
      $ tail -f /path/to/mylogfile.log | grep 'something'\n
      from a separate terminal window.

    On Windows, the --logfile option is also supported by Freqtrade and you can use the findstr command to search the log for the string of interest:

    > type \\path\\to\\mylogfile.log | findstr \"something\"\n

    "},{"location":"faq/#hyperopt-module","title":"Hyperopt module","text":""},{"location":"faq/#why-does-freqtrade-not-have-gpu-support","title":"Why does freqtrade not have GPU support?","text":"

    First of all, most indicator libraries don't have GPU support - as such, there would be little benefit for indicator calculations. The GPU improvements would only apply to pandas-native calculations - or ones written by yourself.

    For hyperopt, freqtrade is using scikit-optimize, which is built on top of scikit-learn. Their statement about GPU support is pretty clear.

    GPU's also are only good at crunching numbers (floating point operations). For hyperopt, we need both number-crunching (find next parameters) and running python code (running backtesting). As such, GPU's are not too well suited for most parts of hyperopt.

    The benefit of using GPU would therefore be pretty slim - and will not justify the complexity introduced by trying to add GPU support.

    There is however nothing preventing you from using GPU-enabled indicators within your strategy if you think you must have this - you will however probably be disappointed by the slim gain that will give you (compared to the complexity).

    "},{"location":"faq/#how-many-epochs-do-i-need-to-get-a-good-hyperopt-result","title":"How many epochs do I need to get a good Hyperopt result?","text":"

    Per default Hyperopt called without the -e/--epochs command line option will only run 100 epochs, means 100 evaluations of your triggers, guards, ... Too few to find a great result (unless if you are very lucky), so you probably have to run it for 10000 or more. But it will take an eternity to compute.

    Since hyperopt uses Bayesian search, running for too many epochs may not produce greater results.

    It's therefore recommended to run between 500-1000 epochs over and over until you hit at least 10000 epochs in total (or are satisfied with the result). You can best judge by looking at the results - if the bot keeps discovering better strategies, it's best to keep on going.

    freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy SampleStrategy -e 1000\n
    "},{"location":"faq/#why-does-it-take-a-long-time-to-run-hyperopt","title":"Why does it take a long time to run hyperopt?","text":"
    • Discovering a great strategy with Hyperopt takes time. Study www.freqtrade.io, the Freqtrade Documentation page, join the Freqtrade discord community. While you patiently wait for the most advanced, free crypto bot in the world, to hand you a possible golden strategy specially designed just for you.
    • If you wonder why it can take from 20 minutes to days to do 1000 epochs here are some answers:

    This answer was written during the release 0.15.1, when we had:

    • 8 triggers
    • 9 guards: let's say we evaluate even 10 values from each
    • 1 stoploss calculation: let's say we want 10 values from that too to be evaluated

    The following calculation is still very rough and not very precise but it will give the idea. With only these triggers and guards there is already 8*10^9*10 evaluations. A roughly total of 80 billion evaluations. Did you run 100 000 evaluations? Congrats, you've done roughly 1 / 100 000 th of the search space, assuming that the bot never tests the same parameters more than once.

    • The time it takes to run 1000 hyperopt epochs depends on things like: The available cpu, hard-disk, ram, timeframe, timerange, indicator settings, indicator count, amount of coins that hyperopt test strategies on and the resulting trade count - which can be 650 trades in a year or 100000 trades depending if the strategy aims for big profits by trading rarely or for many low profit trades.

    Example: 4% profit 650 times vs 0,3% profit a trade 10000 times in a year. If we assume you set the --timerange to 365 days.

    Example: freqtrade --config config.json --strategy SampleStrategy --hyperopt SampleHyperopt -e 1000 --timerange 20190601-20200601

    "},{"location":"faq/#edge-module","title":"Edge module","text":""},{"location":"faq/#edge-implements-interesting-approach-for-controlling-position-size-is-there-any-theory-behind-it","title":"Edge implements interesting approach for controlling position size, is there any theory behind it?","text":"

    The Edge module is mostly a result of brainstorming of @mishaker and @creslinux freqtrade team members.

    You can find further info on expectancy, win rate, risk management and position size in the following sources:

    • https://www.tradeciety.com/ultimate-math-guide-for-traders/
    • https://samuraitradingacademy.com/trading-expectancy/
    • https://www.learningmarkets.com/determining-expectancy-in-your-trading/
    • https://www.lonestocktrader.com/make-money-trading-positive-expectancy/
    • https://www.babypips.com/trading/trade-expectancy-matter
    "},{"location":"faq/#official-channels","title":"Official channels","text":"

    Freqtrade is using exclusively the following official channels:

    • Freqtrade discord server
    • Freqtrade documentation (https://freqtrade.io)
    • Freqtrade github organization

    Nobody affiliated with the freqtrade project will ask you about your exchange keys or anything else exposing your funds to exploitation. Should you be asked to expose your exchange keys or send funds to some random wallet, then please don't follow these instructions.

    Failing to follow these guidelines will not be responsibility of freqtrade.

    "},{"location":"faq/#freqtrade-token","title":"\"Freqtrade token\"","text":"

    Freqtrade does not have a Crypto token offering.

    Token offerings you find on the internet referring Freqtrade, FreqAI or freqUI must be considered to be a scam, trying to exploit freqtrade's popularity for their own, nefarious gains.

    "},{"location":"freq-ui/","title":"FreqUI","text":"

    Freqtrade provides a builtin webserver, which can serve FreqUI, the freqtrade frontend.

    By default, the UI is automatically installed as part of the installation (script, docker). freqUI can also be manually installed by using the freqtrade install-ui command. This same command can also be used to update freqUI to new new releases.

    Once the bot is started in trade / dry-run mode (with freqtrade trade) - the UI will be available under the configured API port (by default http://127.0.0.1:8080).

    Looking to contribute to freqUI?

    Developers should not use this method, but instead clone the corresponding use the method described in the freqUI repository to get the source-code of freqUI. A working installation of node will be required to build the frontend.

    freqUI is not required to run freqtrade

    freqUI is an optional component of freqtrade, and is not required to run the bot. It is a frontend that can be used to monitor the bot and to interact with it - but freqtrade itself will work perfectly fine without it.

    "},{"location":"freq-ui/#configuration","title":"Configuration","text":"

    FreqUI does not have it's own configuration file - but assumes a working setup for the rest-api is available. Please refer to the corresponding documentation page to get setup with freqUI

    "},{"location":"freq-ui/#ui","title":"UI","text":"

    FreqUI is a modern, responsive web application that can be used to monitor and interact with your bot.

    FreqUI provides a light, as well as a dark theme. Themes can be easily switched via a prominent button at the top of the page. The theme of the screenshots on this page will adapt to the selected documentation Theme, so to see the dark (or light) version, please switch the theme of the Documentation.

    "},{"location":"freq-ui/#login","title":"Login","text":"

    The below screenshot shows the login screen of freqUI.

    CORS

    The Cors error shown in this screenshot is due to the fact that the UI is running on a different port than the API, and CORS has not been setup correctly yet.

    "},{"location":"freq-ui/#trade-view","title":"Trade view","text":"

    The trade view allows you to visualize the trades that the bot is making and to interact with the bot. On this page, you can also interact with the bot by starting and stopping it and - if configured - force trade entries and exits.

    "},{"location":"freq-ui/#plot-configurator","title":"Plot Configurator","text":"

    FreqUI Plots can be configured either via a plot_config configuration object in the strategy (which can be loaded via \"from strategy\" button) or via the UI. Multiple plot configurations can be created and switched at will - allowing for flexible, different views into your charts.

    The plot configuration can be accessed via the \"Plot Configurator\" (Cog icon) button in the top right corner of the trade view.

    "},{"location":"freq-ui/#settings","title":"Settings","text":"

    Several UI related settings can be changed by accessing the settings page.

    Things you can change (among others):

    • Timezone of the UI
    • Visualization of open trades as part of the favicon (browser tab)
    • Candle colors (up/down -> red/green)
    • Enable / disable in-app notification types

    "},{"location":"freq-ui/#backtesting","title":"Backtesting","text":"

    When freqtrade is started in webserver mode (freqtrade started with freqtrade webserver), the backtesting view becomes available. This view allows you to backtest strategies and visualize the results.

    You can also load and visualize previous backtest results, as well as compare the results with each other.

    "},{"location":"freq-ui/#cors","title":"CORS","text":"

    This whole section is only necessary in cross-origin cases (where you multiple bot API's running on localhost:8081, localhost:8082, ...), and want to combine them into one FreqUI instance.

    Technical explanation

    All web-based front-ends are subject to CORS - Cross-Origin Resource Sharing. Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems. Also, the standard disallows * CORS policies for requests with credentials, so this setting must be set appropriately.

    Users can allow access from different origin URL's to the bot API via the CORS_origins configuration setting. It consists of a list of allowed URL's that are allowed to consume resources from the bot's API.

    Assuming your application is deployed as https://frequi.freqtrade.io/home/ - this would mean that the following configuration becomes necessary:

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"https://frequi.freqtrade.io\"],\n    //...\n}\n

    In the following (pretty common) case, FreqUI is accessible on http://localhost:8080/trade (this is what you see in your navbar when navigating to freqUI).

    The correct configuration for this case is http://localhost:8080 - the main part of the URL including the port.

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"http://localhost:8080\"],\n    //...\n}\n

    trailing Slash

    The trailing slash is not allowed in the CORS_origins configuration (e.g. \"http://localhots:8080/\"). Such a configuration will not take effect, and the cors errors will remain.

    Note

    We strongly recommend to also set jwt_secret_key to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"freqai-configuration/","title":"Configuration","text":"

    FreqAI is configured through the typical Freqtrade config file and the standard Freqtrade strategy. Examples of FreqAI config and strategy files can be found in config_examples/config_freqai.example.json and freqtrade/templates/FreqaiExampleStrategy.py, respectively.

    "},{"location":"freqai-configuration/#setting-up-the-configuration-file","title":"Setting up the configuration file","text":"

    Although there are plenty of additional parameters to choose from, as highlighted in the parameter table, a FreqAI config must at minimum include the following parameters (the parameter values are only examples):

        \"freqai\": {\n        \"enabled\": true,\n        \"purge_old_models\": 2,\n        \"train_period_days\": 30,\n        \"backtest_period_days\": 7,\n        \"identifier\" : \"unique-id\",\n        \"feature_parameters\" : {\n            \"include_timeframes\": [\"5m\",\"15m\",\"4h\"],\n            \"include_corr_pairlist\": [\n                \"ETH/USD\",\n                \"LINK/USD\",\n                \"BNB/USD\"\n            ],\n            \"label_period_candles\": 24,\n            \"include_shifted_candles\": 2,\n            \"indicator_periods_candles\": [10, 20]\n        },\n        \"data_split_parameters\" : {\n            \"test_size\": 0.25\n        }\n    }\n

    A full example config is available in config_examples/config_freqai.example.json.

    Note

    The identifier is commonly overlooked by newcomers, however, this value plays an important role in your configuration. This value is a unique ID that you choose to describe one of your runs. Keeping it the same allows you to maintain crash resilience as well as faster backtesting. As soon as you want to try a new run (new features, new model, etc.), you should change this value (or delete the user_data/models/unique-id folder. More details available in the parameter table.

    "},{"location":"freqai-configuration/#building-a-freqai-strategy","title":"Building a FreqAI strategy","text":"

    The FreqAI strategy requires including the following lines of code in the standard Freqtrade strategy:

        # user should define the maximum startup candle count (the largest number of candles\n    # passed to any single indicator)\n    startup_candle_count: int = 20\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n\n        # the model will return all labels created by user in `set_freqai_targets()`\n        # (& appended targets), an indication of whether or not the prediction should be accepted,\n        # the target mean/std values for each of the labels created by user in\n        # `set_freqai_targets()` for each training period.\n\n        dataframe = self.freqai.start(dataframe, metadata, self)\n\n        return dataframe\n\n    def feature_engineering_expand_all(self, dataframe: DataFrame, period, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and\n        `include_corr_pairs`. In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *\n        `include_corr_pairs` numbers of features added to the model.\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        :param period: period of the indicator - usage example:\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n        \"\"\"\n\n        dataframe[\"%-rsi-period\"] = ta.RSI(dataframe, timeperiod=period)\n        dataframe[\"%-mfi-period\"] = ta.MFI(dataframe, timeperiod=period)\n        dataframe[\"%-adx-period\"] = ta.ADX(dataframe, timeperiod=period)\n        dataframe[\"%-sma-period\"] = ta.SMA(dataframe, timeperiod=period)\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n\n        return dataframe\n\n    def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.\n        In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `include_timeframes` * `include_shifted_candles` * `include_corr_pairs`\n        numbers of features added to the model.\n\n        Features defined here will *not* be automatically duplicated on user defined\n        `indicator_periods_candles`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-ema-200\"] = ta.EMA(dataframe, timeperiod=200)\n        \"\"\"\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-raw_volume\"] = dataframe[\"volume\"]\n        dataframe[\"%-raw_price\"] = dataframe[\"close\"]\n        return dataframe\n\n    def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This optional function will be called once with the dataframe of the base timeframe.\n        This is the final function to be called, which means that the dataframe entering this\n        function will contain all the features and columns created by all other\n        freqai_feature_engineering_* functions.\n\n        This function is a good place to do custom exotic feature extractions (e.g. tsfresh).\n        This function is a good place for any feature that should not be auto-expanded upon\n        (e.g. day of the week).\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        usage example: dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        \"\"\"\n        dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        dataframe[\"%-hour_of_day\"] = (dataframe[\"date\"].dt.hour + 1) / 25\n        return dataframe\n\n    def set_freqai_targets(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        :param df: strategy dataframe which will receive the targets\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        dataframe[\"&-s_close\"] = (\n            dataframe[\"close\"]\n            .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .mean()\n            / dataframe[\"close\"]\n            - 1\n            )\n        return dataframe\n

    Notice how the feature_engineering_*() is where features are added. Meanwhile set_freqai_targets() adds the labels/targets. A full example strategy is available in templates/FreqaiExampleStrategy.py.

    Note

    The self.freqai.start() function cannot be called outside the populate_indicators().

    Note

    Features must be defined in feature_engineering_*(). Defining FreqAI features in populate_indicators() will cause the algorithm to fail in live/dry mode. In order to add generalized features that are not associated with a specific pair or timeframe, you should use feature_engineering_standard() (as exemplified in freqtrade/templates/FreqaiExampleStrategy.py).

    "},{"location":"freqai-configuration/#important-dataframe-key-patterns","title":"Important dataframe key patterns","text":"

    Below are the values you can expect to include/use inside a typical strategy dataframe (df[]):

    DataFrame Key Description df['&*'] Any dataframe column prepended with & in set_freqai_targets() is treated as a training target (label) inside FreqAI (typically following the naming convention &-s*). For example, to predict the close price 40 candles into the future, you would set df['&-s_close'] = df['close'].shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"]) with \"label_period_candles\": 40 in the config. FreqAI makes the predictions and gives them back under the same key (df['&-s_close']) to be used in populate_entry/exit_trend(). Datatype: Depends on the output of the model. df['&*_std/mean'] Standard deviation and mean values of the defined labels during training (or live tracking with fit_live_predictions_candles). Commonly used to understand the rarity of a prediction (use the z-score as shown in templates/FreqaiExampleStrategy.py and explained here to evaluate how often a particular prediction was observed during training or historically with fit_live_predictions_candles). Datatype: Float. df['do_predict'] Indication of an outlier data point. The return value is integer between -2 and 2, which lets you know if the prediction is trustworthy or not. do_predict==1 means that the prediction is trustworthy. If the Dissimilarity Index (DI, see details here) of the input data point is above the threshold defined in the config, FreqAI will subtract 1 from do_predict, resulting in do_predict==0. If use_SVM_to_remove_outliers is active, the Support Vector Machine (SVM, see details here) may also detect outliers in training and prediction data. In this case, the SVM will also subtract 1 from do_predict. If the input data point was considered an outlier by the SVM but not by the DI, or vice versa, the result will be do_predict==0. If both the DI and the SVM considers the input data point to be an outlier, the result will be do_predict==-1. As with the SVM, if use_DBSCAN_to_remove_outliers is active, DBSCAN (see details here) may also detect outliers and subtract 1 from do_predict. Hence, if both the SVM and DBSCAN are active and identify a datapoint that was above the DI threshold as an outlier, the result will be do_predict==-2. A particular case is when do_predict == 2, which means that the model has expired due to exceeding expired_hours. Datatype: Integer between -2 and 2. df['DI_values'] Dissimilarity Index (DI) values are proxies for the level of confidence FreqAI has in the prediction. A lower DI means the prediction is close to the training data, i.e., higher prediction confidence. See details about the DI here. Datatype: Float. df['%*'] Any dataframe column prepended with % in feature_engineering_*() is treated as a training feature. For example, you can include the RSI in the training feature set (similar to in templates/FreqaiExampleStrategy.py) by setting df['%-rsi']. See more details on how this is done here. Note: Since the number of features prepended with % can multiply very quickly (10s of thousands of features are easily engineered using the multiplictative functionality of, e.g., include_shifted_candles and include_timeframes as described in the parameter table), these features are removed from the dataframe that is returned from FreqAI to the strategy. To keep a particular type of feature for plotting purposes, you would prepend it with %% (see details below). Datatype: Depends on the feature created by the user. df['%%*'] Any dataframe column prepended with %% in feature_engineering_*() is treated as a training feature, just the same as the above % prepend. However, in this case, the features are returned back to the strategy for FreqUI/plot-dataframe plotting and monitoring in Dry/Live/Backtesting Datatype: Depends on the feature created by the user. Please note that features created in feature_engineering_expand() will have automatic FreqAI naming schemas depending on the expansions that you configured (i.e. include_timeframes, include_corr_pairlist, indicators_periods_candles, include_shifted_candles). So if you want to plot %%-rsi from feature_engineering_expand_all(), the final naming scheme for your plotting config would be: %%-rsi-period_10_ETH/USDT:USDT_1h for the rsi feature with period=10, timeframe=1h, and pair=ETH/USDT:USDT (the :USDT is added if you are using futures pairs). It is useful to simply add print(dataframe.columns) in your populate_indicators() after self.freqai.start() to see the full list of available features that are returned to the strategy for plotting purposes."},{"location":"freqai-configuration/#setting-the-startup_candle_count","title":"Setting the startup_candle_count","text":"

    The startup_candle_count in the FreqAI strategy needs to be set up in the same way as in the standard Freqtrade strategy (see details here). This value is used by Freqtrade to ensure that a sufficient amount of data is provided when calling the dataprovider, to avoid any NaNs at the beginning of the first training. You can easily set this value by identifying the longest period (in candle units) which is passed to the indicator creation functions (e.g., TA-Lib functions). In the presented example, startup_candle_count is 20 since this is the maximum value in indicators_periods_candles.

    Note

    There are instances where the TA-Lib functions actually require more data than just the passed period or else the feature dataset gets populated with NaNs. Anecdotally, multiplying the startup_candle_count by 2 always leads to a fully NaN free training dataset. Hence, it is typically safest to multiply the expected startup_candle_count by 2. Look out for this log message to confirm that the data is clean:

    2022-08-31 15:14:04 - freqtrade.freqai.data_kitchen - INFO - dropped 0 training points due to NaNs in populated dataset 4319.\n
    "},{"location":"freqai-configuration/#creating-a-dynamic-target-threshold","title":"Creating a dynamic target threshold","text":"

    Deciding when to enter or exit a trade can be done in a dynamic way to reflect current market conditions. FreqAI allows you to return additional information from the training of a model (more info here). For example, the &*_std/mean return values describe the statistical distribution of the target/label during the most recent training. Comparing a given prediction to these values allows you to know the rarity of the prediction. In templates/FreqaiExampleStrategy.py, the target_roi and sell_roi are defined to be 1.25 z-scores away from the mean which causes predictions that are closer to the mean to be filtered out.

    dataframe[\"target_roi\"] = dataframe[\"&-s_close_mean\"] + dataframe[\"&-s_close_std\"] * 1.25\ndataframe[\"sell_roi\"] = dataframe[\"&-s_close_mean\"] - dataframe[\"&-s_close_std\"] * 1.25\n

    To consider the population of historical predictions for creating the dynamic target instead of information from the training as discussed above, you would set fit_live_predictions_candles in the config to the number of historical prediction candles you wish to use to generate target statistics.

        \"freqai\": {\n        \"fit_live_predictions_candles\": 300,\n    }\n

    If this value is set, FreqAI will initially use the predictions from the training data and subsequently begin introducing real prediction data as it is generated. FreqAI will save this historical data to be reloaded if you stop and restart a model with the same identifier.

    "},{"location":"freqai-configuration/#using-different-prediction-models","title":"Using different prediction models","text":"

    FreqAI has multiple example prediction model libraries that are ready to be used as is via the flag --freqaimodel. These libraries include CatBoost, LightGBM, and XGBoost regression, classification, and multi-target models, and can be found in freqai/prediction_models/.

    Regression and classification models differ in what targets they predict - a regression model will predict a target of continuous values, for example what price BTC will be at tomorrow, whilst a classifier will predict a target of discrete values, for example if the price of BTC will go up tomorrow or not. This means that you have to specify your targets differently depending on which model type you are using (see details below).

    All of the aforementioned model libraries implement gradient boosted decision tree algorithms. They all work on the principle of ensemble learning, where predictions from multiple simple learners are combined to get a final prediction that is more stable and generalized. The simple learners in this case are decision trees. Gradient boosting refers to the method of learning, where each simple learner is built in sequence - the subsequent learner is used to improve on the error from the previous learner. If you want to learn more about the different model libraries you can find the information in their respective docs:

    • CatBoost: https://catboost.ai/en/docs/
    • LightGBM: https://lightgbm.readthedocs.io/en/v3.3.2/#
    • XGBoost: https://xgboost.readthedocs.io/en/stable/#

    There are also numerous online articles describing and comparing the algorithms. Some relatively lightweight examples would be CatBoost vs. LightGBM vs. XGBoost \u2014 Which is the best algorithm? and XGBoost, LightGBM or CatBoost \u2014 which boosting algorithm should I use?. Keep in mind that the performance of each model is highly dependent on the application and so any reported metrics might not be true for your particular use of the model.

    Apart from the models already available in FreqAI, it is also possible to customize and create your own prediction models using the IFreqaiModel class. You are encouraged to inherit fit(), train(), and predict() to customize various aspects of the training procedures. You can place custom FreqAI models in user_data/freqaimodels - and freqtrade will pick them up from there based on the provided --freqaimodel name - which has to correspond to the class name of your custom model. Make sure to use unique names to avoid overriding built-in models.

    "},{"location":"freqai-configuration/#setting-model-targets","title":"Setting model targets","text":""},{"location":"freqai-configuration/#regressors","title":"Regressors","text":"

    If you are using a regressor, you need to specify a target that has continuous values. FreqAI includes a variety of regressors, such as the CatboostRegressorvia the flag --freqaimodel CatboostRegressor. An example of how you could set a regression target for predicting the price 100 candles into the future would be

    df['&s-close_price'] = df['close'].shift(-100)\n

    If you want to predict multiple targets, you need to define multiple labels using the same syntax as shown above.

    "},{"location":"freqai-configuration/#classifiers","title":"Classifiers","text":"

    If you are using a classifier, you need to specify a target that has discrete values. FreqAI includes a variety of classifiers, such as the CatboostClassifier via the flag --freqaimodel CatboostClassifier. If you elects to use a classifier, the classes need to be set using strings. For example, if you want to predict if the price 100 candles into the future goes up or down you would set

    df['&s-up_or_down'] = np.where( df[\"close\"].shift(-100) > df[\"close\"], 'up', 'down')\n

    If you want to predict multiple targets you must specify all labels in the same label column. You could, for example, add the label same to define where the price was unchanged by setting

    df['&s-up_or_down'] = np.where( df[\"close\"].shift(-100) > df[\"close\"], 'up', 'down')\ndf['&s-up_or_down'] = np.where( df[\"close\"].shift(-100) == df[\"close\"], 'same', df['&s-up_or_down'])\n
    "},{"location":"freqai-configuration/#pytorch-module","title":"PyTorch Module","text":""},{"location":"freqai-configuration/#quick-start","title":"Quick start","text":"

    The easiest way to quickly run a pytorch model is with the following command (for regression task):

    freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel PyTorchMLPRegressor --strategy-path freqtrade/templates \n

    Installation/docker

    The PyTorch module requires large packages such as torch, which should be explicitly requested during ./setup.sh -i by answering \"y\" to the question \"Do you also want dependencies for freqai-rl or PyTorch (~700mb additional space required) [y/N]?\". Users who prefer docker should ensure they use the docker image appended with _freqaitorch. We do provide an explicit docker-compose file for this in docker/docker-compose-freqai.yml - which can be used via docker compose -f docker/docker-compose-freqai.yml run ... - or can be copied to replace the original docker file. This docker-compose file also contains a (disabled) section to enable GPU resources within docker containers. This obviously assumes the system has GPU resources available.

    "},{"location":"freqai-configuration/#structure","title":"Structure","text":""},{"location":"freqai-configuration/#model","title":"Model","text":"

    You can construct your own Neural Network architecture in PyTorch by simply defining your nn.Module class inside your custom IFreqaiModel file and then using that class in your def train() function. Here is an example of logistic regression model implementation using PyTorch (should be used with nn.BCELoss criterion) for classification tasks.

    class LogisticRegression(nn.Module):\n    def __init__(self, input_size: int):\n        super().__init__()\n        # Define your layers\n        self.linear = nn.Linear(input_size, 1)\n        self.activation = nn.Sigmoid()\n\n    def forward(self, x: torch.Tensor) -> torch.Tensor:\n        # Define the forward pass\n        out = self.linear(x)\n        out = self.activation(out)\n        return out\n\nclass MyCoolPyTorchClassifier(BasePyTorchClassifier):\n    \"\"\"\n    This is a custom IFreqaiModel showing how a user might setup their own \n    custom Neural Network architecture for their training.\n    \"\"\"\n\n    @property\n    def data_convertor(self) -> PyTorchDataConvertor:\n        return DefaultPyTorchDataConvertor(target_tensor_type=torch.float)\n\n    def __init__(self, **kwargs) -> None:\n        super().__init__(**kwargs)\n        config = self.freqai_info.get(\"model_training_parameters\", {})\n        self.learning_rate: float = config.get(\"learning_rate\",  3e-4)\n        self.model_kwargs: Dict[str, Any] = config.get(\"model_kwargs\",  {})\n        self.trainer_kwargs: Dict[str, Any] = config.get(\"trainer_kwargs\",  {})\n\n    def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:\n        \"\"\"\n        User sets up the training and test data to fit their desired model here\n        :param data_dictionary: the dictionary holding all data for train, test,\n            labels, weights\n        :param dk: The datakitchen object for the current coin/model\n        \"\"\"\n\n        class_names = self.get_class_names()\n        self.convert_label_column_to_int(data_dictionary, dk, class_names)\n        n_features = data_dictionary[\"train_features\"].shape[-1]\n        model = LogisticRegression(\n            input_dim=n_features\n        )\n        model.to(self.device)\n        optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate)\n        criterion = torch.nn.CrossEntropyLoss()\n        init_model = self.get_init_model(dk.pair)\n        trainer = PyTorchModelTrainer(\n            model=model,\n            optimizer=optimizer,\n            criterion=criterion,\n            model_meta_data={\"class_names\": class_names},\n            device=self.device,\n            init_model=init_model,\n            data_convertor=self.data_convertor,\n            **self.trainer_kwargs,\n        )\n        trainer.fit(data_dictionary, self.splits)\n        return trainer\n
    "},{"location":"freqai-configuration/#trainer","title":"Trainer","text":"

    The PyTorchModelTrainer performs the idiomatic PyTorch train loop: Define our model, loss function, and optimizer, and then move them to the appropriate device (GPU or CPU). Inside the loop, we iterate through the batches in the dataloader, move the data to the device, compute the prediction and loss, backpropagate, and update the model parameters using the optimizer.

    In addition, the trainer is responsible for the following: - saving and loading the model - converting the data from pandas.DataFrame to torch.Tensor.

    "},{"location":"freqai-configuration/#integration-with-freqai-module","title":"Integration with Freqai module","text":"

    Like all freqai models, PyTorch models inherit IFreqaiModel. IFreqaiModel declares three abstract methods: train, fit, and predict. we implement these methods in three levels of hierarchy. From top to bottom:

    1. BasePyTorchModel - Implements the train method. all BasePyTorch* inherit it. responsible for general data preparation (e.g., data normalization) and calling the fit method. Sets device attribute used by children classes. Sets model_type attribute used by the parent class.
    2. BasePyTorch* - Implements the predict method. Here, the * represents a group of algorithms, such as classifiers or regressors. responsible for data preprocessing, predicting, and postprocessing if needed.
    3. PyTorch*Classifier / PyTorch*Regressor - implements the fit method. responsible for the main train flaw, where we initialize the trainer and model objects.

    "},{"location":"freqai-configuration/#full-example","title":"Full example","text":"

    Building a PyTorch regressor using MLP (multilayer perceptron) model, MSELoss criterion, and AdamW optimizer.

    class PyTorchMLPRegressor(BasePyTorchRegressor):\n    def __init__(self, **kwargs) -> None:\n        super().__init__(**kwargs)\n        config = self.freqai_info.get(\"model_training_parameters\", {})\n        self.learning_rate: float = config.get(\"learning_rate\",  3e-4)\n        self.model_kwargs: Dict[str, Any] = config.get(\"model_kwargs\",  {})\n        self.trainer_kwargs: Dict[str, Any] = config.get(\"trainer_kwargs\",  {})\n\n    def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:\n        n_features = data_dictionary[\"train_features\"].shape[-1]\n        model = PyTorchMLPModel(\n            input_dim=n_features,\n            output_dim=1,\n            **self.model_kwargs\n        )\n        model.to(self.device)\n        optimizer = torch.optim.AdamW(model.parameters(), lr=self.learning_rate)\n        criterion = torch.nn.MSELoss()\n        init_model = self.get_init_model(dk.pair)\n        trainer = PyTorchModelTrainer(\n            model=model,\n            optimizer=optimizer,\n            criterion=criterion,\n            device=self.device,\n            init_model=init_model,\n            target_tensor_type=torch.float,\n            **self.trainer_kwargs,\n        )\n        trainer.fit(data_dictionary)\n        return trainer\n

    Here we create a PyTorchMLPRegressor class that implements the fit method. The fit method specifies the training building blocks: model, optimizer, criterion, and trainer. We inherit both BasePyTorchRegressor and BasePyTorchModel, where the former implements the predict method that is suitable for our regression task, and the latter implements the train method.

    Setting Class Names for Classifiers

    When using classifiers, the user must declare the class names (or targets) by overriding the IFreqaiModel.class_names attribute. This is achieved by setting self.freqai.class_names in the FreqAI strategy inside the set_freqai_targets method.

    For example, if you are using a binary classifier to predict price movements as up or down, you can set the class names as follows:

    def set_freqai_targets(self, dataframe: DataFrame, metadata: Dict, **kwargs) -> DataFrame:\n    self.freqai.class_names = [\"down\", \"up\"]\n    dataframe['&s-up_or_down'] = np.where(dataframe[\"close\"].shift(-100) >\n                                              dataframe[\"close\"], 'up', 'down')\n\n    return dataframe\n
    To see a full example, you can refer to the classifier test strategy class.

    "},{"location":"freqai-configuration/#improving-performance-with-torchcompile","title":"Improving performance with torch.compile()","text":"

    Torch provides a torch.compile() method that can be used to improve performance for specific GPU hardware. More details can be found here. In brief, you simply wrap your model in torch.compile():

            model = PyTorchMLPModel(\n            input_dim=n_features,\n            output_dim=1,\n            **self.model_kwargs\n        )\n        model.to(self.device)\n        model = torch.compile(model)\n

    Then proceed to use the model as normal. Keep in mind that doing this will remove eager execution, which means errors and tracebacks will not be informative.

    "},{"location":"freqai-developers/","title":"Development","text":""},{"location":"freqai-developers/#project-architecture","title":"Project architecture","text":"

    The architecture and functions of FreqAI are generalized to encourages development of unique features, functions, models, etc.

    The class structure and a detailed algorithmic overview is depicted in the following diagram:

    As shown, there are three distinct objects comprising FreqAI:

    • IFreqaiModel - A singular persistent object containing all the necessary logic to collect, store, and process data, engineer features, run training, and inference models.
    • FreqaiDataKitchen - A non-persistent object which is created uniquely for each unique asset/model. Beyond metadata, it also contains a variety of data processing tools.
    • FreqaiDataDrawer - A singular persistent object containing all the historical predictions, models, and save/load methods.

    There are a variety of built-in prediction models which inherit directly from IFreqaiModel. Each of these models have full access to all methods in IFreqaiModel and can therefore override any of those functions at will. However, advanced users will likely stick to overriding fit(), train(), predict(), and data_cleaning_train/predict().

    "},{"location":"freqai-developers/#data-handling","title":"Data handling","text":"

    FreqAI aims to organize model files, prediction data, and meta data in a way that simplifies post-processing and enhances crash resilience by automatic data reloading. The data is saved in a file structure,user_data_dir/models/, which contains all the data associated with the trainings and backtests. The FreqaiDataKitchen() relies heavily on the file structure for proper training and inferencing and should therefore not be manually modified.

    "},{"location":"freqai-developers/#file-structure","title":"File structure","text":"

    The file structure is automatically generated based on the model identifier set in the config. The following structure shows where the data is stored for post processing:

    Structure Description config_*.json A copy of the model specific configuration file. historic_predictions.pkl A file containing all historic predictions generated during the lifetime of the identifier model during live deployment. historic_predictions.pkl is used to reload the model after a crash or a config change. A backup file is always held in case of corruption on the main file. FreqAI automatically detects corruption and replaces the corrupted file with the backup. pair_dictionary.json A file containing the training queue as well as the on disk location of the most recently trained model. sub-train-*_TIMESTAMP A folder containing all the files associated with a single model, such as: *_metadata.json - Metadata for the model, such as normalization max/min, expected training feature list, etc. *_model.* - The model file saved to disk for reloading from a crash. Can be joblib (typical boosting libs), zip (stable_baselines), hd5 (keras type), etc. *_pca_object.pkl - The Principal component analysis (PCA) transform (if principal_component_analysis: True is set in the config) which will be used to transform unseen prediction features. *_svm_model.pkl - The Support Vector Machine (SVM) model (if use_SVM_to_remove_outliers: True is set in the config) which is used to detect outliers in unseen prediction features. *_trained_df.pkl - The dataframe containing all the training features used to train the identifier model. This is used for computing the Dissimilarity Index (DI) and can also be used for post-processing. *_trained_dates.df.pkl - The dates associated with the trained_df.pkl, which is useful for post-processing.

    The example file structure would look like this:

    \u251c\u2500\u2500 models\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 unique-id\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 config_freqai.example.json\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 historic_predictions.backup.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 historic_predictions.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 pair_dictionary.json\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 sub-train-1INCH_1662821319\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_metadata.json\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_pca_object.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_svm_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821319_trained_dates_df.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u2514\u2500\u2500 cb_1inch_1662821319_trained_df.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 sub-train-1INCH_1662821371\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_metadata.json\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_pca_object.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_svm_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_1inch_1662821371_trained_dates_df.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u2514\u2500\u2500 cb_1inch_1662821371_trained_df.pkl\n\u2502\u00a0\u00a0     \u251c\u2500\u2500 sub-train-ADA_1662821344\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_metadata.json\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_pca_object.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_svm_model.joblib\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u251c\u2500\u2500 cb_ada_1662821344_trained_dates_df.pkl\n\u2502\u00a0\u00a0     \u2502\u00a0\u00a0 \u2514\u2500\u2500 cb_ada_1662821344_trained_df.pkl\n\u2502\u00a0\u00a0     \u2514\u2500\u2500 sub-train-ADA_1662821399\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_metadata.json\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_model.joblib\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_pca_object.pkl\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_svm_model.joblib\n\u2502\u00a0\u00a0         \u251c\u2500\u2500 cb_ada_1662821399_trained_dates_df.pkl\n\u2502\u00a0\u00a0         \u2514\u2500\u2500 cb_ada_1662821399_trained_df.pkl\n
    "},{"location":"freqai-feature-engineering/","title":"Feature engineering","text":""},{"location":"freqai-feature-engineering/#defining-the-features","title":"Defining the features","text":"

    Low level feature engineering is performed in the user strategy within a set of functions called feature_engineering_*. These function set the base features such as, RSI, MFI, EMA, SMA, time of day, volume, etc. The base features can be custom indicators or they can be imported from any technical-analysis library that you can find. FreqAI is equipped with a set of functions to simplify rapid large-scale feature engineering:

    Function Description feature_engineering_expand_all() This optional function will automatically expand the defined features on the config defined indicator_periods_candles, include_timeframes, include_shifted_candles, and include_corr_pairs. feature_engineering_expand_basic() This optional function will automatically expand the defined features on the config defined include_timeframes, include_shifted_candles, and include_corr_pairs. Note: this function does not expand across indicator_periods_candles. feature_engineering_standard() This optional function will be called once with the dataframe of the base timeframe. This is the final function to be called, which means that the dataframe entering this function will contain all the features and columns from the base asset created by the other feature_engineering_expand functions. This function is a good place to do custom exotic feature extractions (e.g. tsfresh). This function is also a good place for any feature that should not be auto-expanded upon (e.g., day of the week). set_freqai_targets() Required function to set the targets for the model. All targets must be prepended with & to be recognized by the FreqAI internals.

    Meanwhile, high level feature engineering is handled within \"feature_parameters\":{} in the FreqAI config. Within this file, it is possible to decide large scale feature expansions on top of the base_features such as \"including correlated pairs\" or \"including informative timeframes\" or even \"including recent candles.\"

    It is advisable to start from the template feature_engineering_* functions in the source provided example strategy (found in templates/FreqaiExampleStrategy.py) to ensure that the feature definitions are following the correct conventions. Here is an example of how to set the indicators and labels in the strategy:

        def feature_engineering_expand_all(self, dataframe: DataFrame, period, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and\n        `include_corr_pairs`. In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *\n        `include_corr_pairs` numbers of features added to the model.\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        Access metadata such as the current pair/timeframe/period with:\n\n        `metadata[\"pair\"]` `metadata[\"tf\"]`  `metadata[\"period\"]`\n\n        :param df: strategy dataframe which will receive the features\n        :param period: period of the indicator - usage example:\n        :param metadata: metadata of current pair\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n        \"\"\"\n\n        dataframe[\"%-rsi-period\"] = ta.RSI(dataframe, timeperiod=period)\n        dataframe[\"%-mfi-period\"] = ta.MFI(dataframe, timeperiod=period)\n        dataframe[\"%-adx-period\"] = ta.ADX(dataframe, timeperiod=period)\n        dataframe[\"%-sma-period\"] = ta.SMA(dataframe, timeperiod=period)\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n\n        bollinger = qtpylib.bollinger_bands(\n            qtpylib.typical_price(dataframe), window=period, stds=2.2\n        )\n        dataframe[\"bb_lowerband-period\"] = bollinger[\"lower\"]\n        dataframe[\"bb_middleband-period\"] = bollinger[\"mid\"]\n        dataframe[\"bb_upperband-period\"] = bollinger[\"upper\"]\n\n        dataframe[\"%-bb_width-period\"] = (\n            dataframe[\"bb_upperband-period\"]\n            - dataframe[\"bb_lowerband-period\"]\n        ) / dataframe[\"bb_middleband-period\"]\n        dataframe[\"%-close-bb_lower-period\"] = (\n            dataframe[\"close\"] / dataframe[\"bb_lowerband-period\"]\n        )\n\n        dataframe[\"%-roc-period\"] = ta.ROC(dataframe, timeperiod=period)\n\n        dataframe[\"%-relative_volume-period\"] = (\n            dataframe[\"volume\"] / dataframe[\"volume\"].rolling(period).mean()\n        )\n\n        return dataframe\n\n    def feature_engineering_expand_basic(self, dataframe: DataFrame, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.\n        In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `include_timeframes` * `include_shifted_candles` * `include_corr_pairs`\n        numbers of features added to the model.\n\n        Features defined here will *not* be automatically duplicated on user defined\n        `indicator_periods_candles`\n\n        Access metadata such as the current pair/timeframe with:\n\n        `metadata[\"pair\"]` `metadata[\"tf\"]`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        :param metadata: metadata of current pair\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-ema-200\"] = ta.EMA(dataframe, timeperiod=200)\n        \"\"\"\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-raw_volume\"] = dataframe[\"volume\"]\n        dataframe[\"%-raw_price\"] = dataframe[\"close\"]\n        return dataframe\n\n    def feature_engineering_standard(self, dataframe: DataFrame, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This optional function will be called once with the dataframe of the base timeframe.\n        This is the final function to be called, which means that the dataframe entering this\n        function will contain all the features and columns created by all other\n        freqai_feature_engineering_* functions.\n\n        This function is a good place to do custom exotic feature extractions (e.g. tsfresh).\n        This function is a good place for any feature that should not be auto-expanded upon\n        (e.g. day of the week).\n\n        Access metadata such as the current pair with:\n\n        `metadata[\"pair\"]`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        :param df: strategy dataframe which will receive the features\n        :param metadata: metadata of current pair\n        usage example: dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        \"\"\"\n        dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        dataframe[\"%-hour_of_day\"] = (dataframe[\"date\"].dt.hour + 1) / 25\n        return dataframe\n\n    def set_freqai_targets(self, dataframe: DataFrame, metadata, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        Access metadata such as the current pair with:\n\n        `metadata[\"pair\"]`\n\n        :param df: strategy dataframe which will receive the targets\n        :param metadata: metadata of current pair\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        dataframe[\"&-s_close\"] = (\n            dataframe[\"close\"]\n            .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .mean()\n            / dataframe[\"close\"]\n            - 1\n            )\n\n        return dataframe\n

    In the presented example, the user does not wish to pass the bb_lowerband as a feature to the model, and has therefore not prepended it with %. The user does, however, wish to pass bb_width to the model for training/prediction and has therefore prepended it with %.

    After having defined the base features, the next step is to expand upon them using the powerful feature_parameters in the configuration file:

        \"freqai\": {\n        //...\n        \"feature_parameters\" : {\n            \"include_timeframes\": [\"5m\",\"15m\",\"4h\"],\n            \"include_corr_pairlist\": [\n                \"ETH/USD\",\n                \"LINK/USD\",\n                \"BNB/USD\"\n            ],\n            \"label_period_candles\": 24,\n            \"include_shifted_candles\": 2,\n            \"indicator_periods_candles\": [10, 20]\n        },\n        //...\n    }\n

    The include_timeframes in the config above are the timeframes (tf) of each call to feature_engineering_expand_*() in the strategy. In the presented case, the user is asking for the 5m, 15m, and 4h timeframes of the rsi, mfi, roc, and bb_width to be included in the feature set.

    You can ask for each of the defined features to be included also for informative pairs using the include_corr_pairlist. This means that the feature set will include all the features from feature_engineering_expand_*() on all the include_timeframes for each of the correlated pairs defined in the config (ETH/USD, LINK/USD, and BNB/USD in the presented example).

    include_shifted_candles indicates the number of previous candles to include in the feature set. For example, include_shifted_candles: 2 tells FreqAI to include the past 2 candles for each of the features in the feature set.

    In total, the number of features the user of the presented example strategy has created is: length of include_timeframes * no. features in feature_engineering_expand_*() * length of include_corr_pairlist * no. include_shifted_candles * length of indicator_periods_candles \\(= 3 * 3 * 3 * 2 * 2 = 108\\).

    !!! note \"Learn more about creative feature engineering\" Check out our medium article geared toward helping users learn how to creatively engineer features.

    "},{"location":"freqai-feature-engineering/#gain-finer-control-over-feature_engineering_-functions-with-metadata","title":"Gain finer control over feature_engineering_* functions with metadata","text":"

    All feature_engineering_* and set_freqai_targets() functions are passed a metadata dictionary which contains information about the pair, tf (timeframe), and period that FreqAI is automating for feature building. As such, a user can use metadata inside feature_engineering_* functions as criteria for blocking/reserving features for certain timeframes, periods, pairs etc.

    def feature_engineering_expand_all(self, dataframe: DataFrame, period, metadata, **kwargs) -> DataFrame:\n    if metadata[\"tf\"] == \"1h\":\n        dataframe[\"%-roc-period\"] = ta.ROC(dataframe, timeperiod=period)\n

    This will block ta.ROC() from being added to any timeframes other than \"1h\".

    "},{"location":"freqai-feature-engineering/#returning-additional-info-from-training","title":"Returning additional info from training","text":"

    Important metrics can be returned to the strategy at the end of each model training by assigning them to dk.data['extra_returns_per_train']['my_new_value'] = XYZ inside the custom prediction model class.

    FreqAI takes the my_new_value assigned in this dictionary and expands it to fit the dataframe that is returned to the strategy. You can then use the returned metrics in your strategy through dataframe['my_new_value']. An example of how return values can be used in FreqAI are the &*_mean and &*_std values that are used to created a dynamic target threshold.

    Another example, where the user wants to use live metrics from the trade database, is shown below:

        \"freqai\": {\n        \"extra_returns_per_train\": {\"total_profit\": 4}\n    }\n

    You need to set the standard dictionary in the config so that FreqAI can return proper dataframe shapes. These values will likely be overridden by the prediction model, but in the case where the model has yet to set them, or needs a default initial value, the pre-set values are what will be returned.

    "},{"location":"freqai-feature-engineering/#weighting-features-for-temporal-importance","title":"Weighting features for temporal importance","text":"

    FreqAI allows you to set a weight_factor to weight recent data more strongly than past data via an exponential function:

    \\[ W_i = \\exp(\\frac{-i}{\\alpha*n}) \\]

    where \\(W_i\\) is the weight of data point \\(i\\) in a total set of \\(n\\) data points. Below is a figure showing the effect of different weight factors on the data points in a feature set.

    "},{"location":"freqai-feature-engineering/#building-the-data-pipeline","title":"Building the data pipeline","text":"

    By default, FreqAI builds a dynamic pipeline based on user configuration settings. The default settings are robust and designed to work with a variety of methods. These two steps are a MinMaxScaler(-1,1) and a VarianceThreshold which removes any column that has 0 variance. Users can activate other steps with more configuration parameters. For example if users add use_SVM_to_remove_outliers: true to the freqai config, then FreqAI will automatically add the SVMOutlierExtractor to the pipeline. Likewise, users can add principal_component_analysis: true to the freqai config to activate PCA. The DissimilarityIndex is activated with DI_threshold: 1. Finally, noise can also be added to the data with noise_standard_deviation: 0.1. Finally, users can add DBSCAN outlier removal with use_DBSCAN_to_remove_outliers: true.

    More information available

    Please review the parameter table for more information on these parameters.

    "},{"location":"freqai-feature-engineering/#customizing-the-pipeline","title":"Customizing the pipeline","text":"

    Users are encouraged to customize the data pipeline to their needs by building their own data pipeline. This can be done by simply setting dk.feature_pipeline to their desired Pipeline object inside their IFreqaiModel train() function, or if they prefer not to touch the train() function, they can override define_data_pipeline/define_label_pipeline functions in their IFreqaiModel:

    More information available

    FreqAI uses the DataSieve pipeline, which follows the SKlearn pipeline API, but adds, among other features, coherence between the X, y, and sample_weight vector point removals, feature removal, feature name following.

    from datasieve.transforms import SKLearnWrapper, DissimilarityIndex\nfrom datasieve.pipeline import Pipeline\nfrom sklearn.preprocessing import QuantileTransformer, StandardScaler\nfrom freqai.base_models import BaseRegressionModel\n\n\nclass MyFreqaiModel(BaseRegressionModel):\n    \"\"\"\n    Some cool custom model\n    \"\"\"\n    def fit(self, data_dictionary: Dict, dk: FreqaiDataKitchen, **kwargs) -> Any:\n        \"\"\"\n        My custom fit function\n        \"\"\"\n        model = cool_model.fit()\n        return model\n\n    def define_data_pipeline(self) -> Pipeline:\n        \"\"\"\n        User defines their custom feature pipeline here (if they wish)\n        \"\"\"\n        feature_pipeline = Pipeline([\n            ('qt', SKLearnWrapper(QuantileTransformer(output_distribution='normal'))),\n            ('di', ds.DissimilarityIndex(di_threshold=1))\n        ])\n\n        return feature_pipeline\n\n    def define_label_pipeline(self) -> Pipeline:\n        \"\"\"\n        User defines their custom label pipeline here (if they wish)\n        \"\"\"\n        label_pipeline = Pipeline([\n            ('qt', SKLearnWrapper(StandardScaler())),\n        ])\n\n        return label_pipeline\n

    Here, you are defining the exact pipeline that will be used for your feature set during training and prediction. You can use most SKLearn transformation steps by wrapping them in the SKLearnWrapper class as shown above. In addition, you can use any of the transformations available in the DataSieve library.

    You can easily add your own transformation by creating a class that inherits from the datasieve BaseTransform and implementing your fit(), transform() and inverse_transform() methods:

    from datasieve.transforms.base_transform import BaseTransform\n# import whatever else you need\n\nclass MyCoolTransform(BaseTransform):\n    def __init__(self, **kwargs):\n        self.param1 = kwargs.get('param1', 1)\n\n    def fit(self, X, y=None, sample_weight=None, feature_list=None, **kwargs):\n        # do something with X, y, sample_weight, or/and feature_list\n        return X, y, sample_weight, feature_list\n\n    def transform(self, X, y=None, sample_weight=None,\n                  feature_list=None, outlier_check=False, **kwargs):\n        # do something with X, y, sample_weight, or/and feature_list\n        return X, y, sample_weight, feature_list\n\n    def inverse_transform(self, X, y=None, sample_weight=None, feature_list=None, **kwargs):\n        # do/dont do something with X, y, sample_weight, or/and feature_list\n        return X, y, sample_weight, feature_list\n

    Hint

    You can define this custom class in the same file as your IFreqaiModel.

    "},{"location":"freqai-feature-engineering/#migrating-a-custom-ifreqaimodel-to-the-new-pipeline","title":"Migrating a custom IFreqaiModel to the new Pipeline","text":"

    If you have created your own custom IFreqaiModel with a custom train()/predict() function, and you still rely on data_cleaning_train/predict(), then you will need to migrate to the new pipeline. If your model does not rely on data_cleaning_train/predict(), then you do not need to worry about this migration.

    More details about the migration can be found here.

    "},{"location":"freqai-feature-engineering/#outlier-detection","title":"Outlier detection","text":"

    Equity and crypto markets suffer from a high level of non-patterned noise in the form of outlier data points. FreqAI implements a variety of methods to identify such outliers and hence mitigate risk.

    "},{"location":"freqai-feature-engineering/#identifying-outliers-with-the-dissimilarity-index-di","title":"Identifying outliers with the Dissimilarity Index (DI)","text":"

    The Dissimilarity Index (DI) aims to quantify the uncertainty associated with each prediction made by the model.

    You can tell FreqAI to remove outlier data points from the training/test data sets using the DI by including the following statement in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"DI_threshold\": 1\n        }\n    }\n

    Which will add DissimilarityIndex step to your feature_pipeline and set the threshold to 1. The DI allows predictions which are outliers (not existent in the model feature space) to be thrown out due to low levels of certainty. To do so, FreqAI measures the distance between each training data point (feature vector), \\(X_{a}\\), and all other training data points:

    \\[ d_{ab} = \\sqrt{\\sum_{j=1}^p(X_{a,j}-X_{b,j})^2} \\]

    where \\(d_{ab}\\) is the distance between the normalized points \\(a\\) and \\(b\\), and \\(p\\) is the number of features, i.e., the length of the vector \\(X\\). The characteristic distance, \\(\\overline{d}\\), for a set of training data points is simply the mean of the average distances:

    \\[ \\overline{d} = \\sum_{a=1}^n(\\sum_{b=1}^n(d_{ab}/n)/n) \\]

    \\(\\overline{d}\\) quantifies the spread of the training data, which is compared to the distance between a new prediction feature vectors, \\(X_k\\) and all the training data:

    \\[ d_k = \\arg \\min d_{k,i} \\]

    This enables the estimation of the Dissimilarity Index as:

    \\[ DI_k = d_k/\\overline{d} \\]

    You can tweak the DI through the DI_threshold to increase or decrease the extrapolation of the trained model. A higher DI_threshold means that the DI is more lenient and allows predictions further away from the training data to be used whilst a lower DI_threshold has the opposite effect and hence discards more predictions.

    Below is a figure that describes the DI for a 3D data set.

    "},{"location":"freqai-feature-engineering/#identifying-outliers-using-a-support-vector-machine-svm","title":"Identifying outliers using a Support Vector Machine (SVM)","text":"

    You can tell FreqAI to remove outlier data points from the training/test data sets using a Support Vector Machine (SVM) by including the following statement in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"use_SVM_to_remove_outliers\": true\n        }\n    }\n

    Which will add SVMOutlierExtractor step to your feature_pipeline. The SVM will be trained on the training data and any data point that the SVM deems to be beyond the feature space will be removed.

    You can elect to provide additional parameters for the SVM, such as shuffle, and nu via the feature_parameters.svm_params dictionary in the config.

    The parameter shuffle is by default set to False to ensure consistent results. If it is set to True, running the SVM multiple times on the same data set might result in different outcomes due to max_iter being to low for the algorithm to reach the demanded tol. Increasing max_iter solves this issue but causes the procedure to take longer time.

    The parameter nu, very broadly, is the amount of data points that should be considered outliers and should be between 0 and 1.

    "},{"location":"freqai-feature-engineering/#identifying-outliers-with-dbscan","title":"Identifying outliers with DBSCAN","text":"

    You can configure FreqAI to use DBSCAN to cluster and remove outliers from the training/test data set or incoming outliers from predictions, by activating use_DBSCAN_to_remove_outliers in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"use_DBSCAN_to_remove_outliers\": true\n        }\n    }\n

    Which will add the DataSieveDBSCAN step to your feature_pipeline. This is an unsupervised machine learning algorithm that clusters data without needing to know how many clusters there should be.

    Given a number of data points \\(N\\), and a distance \\(\\varepsilon\\), DBSCAN clusters the data set by setting all data points that have \\(N-1\\) other data points within a distance of \\(\\varepsilon\\) as core points. A data point that is within a distance of \\(\\varepsilon\\) from a core point but that does not have \\(N-1\\) other data points within a distance of \\(\\varepsilon\\) from itself is considered an edge point. A cluster is then the collection of core points and edge points. Data points that have no other data points at a distance \\(<\\varepsilon\\) are considered outliers. The figure below shows a cluster with \\(N = 3\\).

    FreqAI uses sklearn.cluster.DBSCAN (details are available on scikit-learn's webpage here (external website)) with min_samples (\\(N\\)) taken as \u00bc of the no. of time points (candles) in the feature set. eps (\\(\\varepsilon\\)) is computed automatically as the elbow point in the k-distance graph computed from the nearest neighbors in the pairwise distances of all data points in the feature set.

    "},{"location":"freqai-feature-engineering/#data-dimensionality-reduction-with-principal-component-analysis","title":"Data dimensionality reduction with Principal Component Analysis","text":"

    You can reduce the dimensionality of your features by activating the principal_component_analysis in the config:

        \"freqai\": {\n        \"feature_parameters\" : {\n            \"principal_component_analysis\": true\n        }\n    }\n

    This will perform PCA on the features and reduce their dimensionality so that the explained variance of the data set is >= 0.999. Reducing data dimensionality makes training the model faster and hence allows for more up-to-date models.

    "},{"location":"freqai-parameter-table/","title":"Parameter table","text":"

    The table below will list all configuration parameters available for FreqAI. Some of the parameters are exemplified in config_examples/config_freqai.example.json.

    Mandatory parameters are marked as Required and have to be set in one of the suggested ways.

    "},{"location":"freqai-parameter-table/#general-configuration-parameters","title":"General configuration parameters","text":"Parameter Description General configuration parameters within the config.freqai tree freqai Required. The parent dictionary containing all the parameters for controlling FreqAI. Datatype: Dictionary. train_period_days Required. Number of days to use for the training data (width of the sliding window). Datatype: Positive integer. backtest_period_days Required. Number of days to inference from the trained model before sliding the train_period_days window defined above, and retraining the model during backtesting (more info here). This can be fractional days, but beware that the provided timerange will be divided by this number to yield the number of trainings necessary to complete the backtest. Datatype: Float. identifier Required. A unique ID for the current model. If models are saved to disk, the identifier allows for reloading specific pre-trained models/data. Datatype: String. live_retrain_hours Frequency of retraining during dry/live runs. Datatype: Float > 0. Default: 0 (models retrain as often as possible). expiration_hours Avoid making predictions if a model is more than expiration_hours old. Datatype: Positive integer. Default: 0 (models never expire). purge_old_models Number of models to keep on disk (not relevant to backtesting). Default is 2, which means that dry/live runs will keep the latest 2 models on disk. Setting to 0 keeps all models. This parameter also accepts a boolean to maintain backwards compatibility. Datatype: Integer. Default: 2. save_backtest_models Save models to disk when running backtesting. Backtesting operates most efficiently by saving the prediction data and reusing them directly for subsequent runs (when you wish to tune entry/exit parameters). Saving backtesting models to disk also allows to use the same model files for starting a dry/live instance with the same model identifier. Datatype: Boolean. Default: False (no models are saved). fit_live_predictions_candles Number of historical candles to use for computing target (label) statistics from prediction data, instead of from the training dataset (more information can be found here). Datatype: Positive integer. continual_learning Use the final state of the most recently trained model as starting point for the new model, allowing for incremental learning (more information can be found here). Beware that this is currently a naive approach to incremental learning, and it has a high probability of overfitting/getting stuck in local minima while the market moves away from your model. We have the connections here primarily for experimental purposes and so that it is ready for more mature approaches to continual learning in chaotic systems like the crypto market. Datatype: Boolean. Default: False. write_metrics_to_disk Collect train timings, inference timings and cpu usage in json file. Datatype: Boolean. Default: False data_kitchen_thread_count Designate the number of threads you want to use for data processing (outlier methods, normalization, etc.). This has no impact on the number of threads used for training. If user does not set it (default), FreqAI will use max number of threads - 2 (leaving 1 physical core available for Freqtrade bot and FreqUI) Datatype: Positive integer. activate_tensorboard Indicate whether or not to activate tensorboard for the tensorboard enabled modules (currently Reinforcment Learning, XGBoost, Catboost, and PyTorch). Tensorboard needs Torch installed, which means you will need the torch/RL docker image or you need to answer \"yes\" to the install question about whether or not you wish to install Torch. Datatype: Boolean. Default: True."},{"location":"freqai-parameter-table/#feature-parameters","title":"Feature parameters","text":"Parameter Description Feature parameters within the freqai.feature_parameters sub dictionary feature_parameters A dictionary containing the parameters used to engineer the feature set. Details and examples are shown here. Datatype: Dictionary. include_timeframes A list of timeframes that all indicators in feature_engineering_expand_*() will be created for. The list is added as features to the base indicators dataset. Datatype: List of timeframes (strings). include_corr_pairlist A list of correlated coins that FreqAI will add as additional features to all pair_whitelist coins. All indicators set in feature_engineering_expand_*() during feature engineering (see details here) will be created for each correlated coin. The correlated coins features are added to the base indicators dataset. Datatype: List of assets (strings). label_period_candles Number of candles into the future that the labels are created for. This can be used in set_freqai_targets() (see templates/FreqaiExampleStrategy.py for detailed usage). This parameter is not necessarily required, you can create custom labels and choose whether to make use of this parameter or not. Please see templates/FreqaiExampleStrategy.py to see the example usage. Datatype: Positive integer. include_shifted_candles Add features from previous candles to subsequent candles with the intent of adding historical information. If used, FreqAI will duplicate and shift all features from the include_shifted_candles previous candles so that the information is available for the subsequent candle. Datatype: Positive integer. weight_factor Weight training data points according to their recency (see details here). Datatype: Positive float (typically < 1). indicator_max_period_candles No longer used (#7325). Replaced by startup_candle_count which is set in the strategy. startup_candle_count is timeframe independent and defines the maximum period used in feature_engineering_*() for indicator creation. FreqAI uses this parameter together with the maximum timeframe in include_time_frames to calculate how many data points to download such that the first data point does not include a NaN. Datatype: Positive integer. indicator_periods_candles Time periods to calculate indicators for. The indicators are added to the base indicator dataset. Datatype: List of positive integers. principal_component_analysis Automatically reduce the dimensionality of the data set using Principal Component Analysis. See details about how it works here Datatype: Boolean. Default: False. plot_feature_importances Create a feature importance plot for each model for the top/bottom plot_feature_importances number of features. Plot is stored in user_data/models/<identifier>/sub-train-<COIN>_<timestamp>.html. Datatype: Integer. Default: 0. DI_threshold Activates the use of the Dissimilarity Index for outlier detection when set to > 0. See details about how it works here. Datatype: Positive float (typically < 1). use_SVM_to_remove_outliers Train a support vector machine to detect and remove outliers from the training dataset, as well as from incoming data points. See details about how it works here. Datatype: Boolean. svm_params All parameters available in Sklearn's SGDOneClassSVM(). See details about some select parameters here. Datatype: Dictionary. use_DBSCAN_to_remove_outliers Cluster data using the DBSCAN algorithm to identify and remove outliers from training and prediction data. See details about how it works here. Datatype: Boolean. noise_standard_deviation If set, FreqAI adds noise to the training features with the aim of preventing overfitting. FreqAI generates random deviates from a gaussian distribution with a standard deviation of noise_standard_deviation and adds them to all data points. noise_standard_deviation should be kept relative to the normalized space, i.e., between -1 and 1. In other words, since data in FreqAI is always normalized to be between -1 and 1, noise_standard_deviation: 0.05 would result in 32% of the data being randomly increased/decreased by more than 2.5% (i.e., the percent of data falling within the first standard deviation). Datatype: Integer. Default: 0. outlier_protection_percentage Enable to prevent outlier detection methods from discarding too much data. If more than outlier_protection_percentage % of points are detected as outliers by the SVM or DBSCAN, FreqAI will log a warning message and ignore outlier detection, i.e., the original dataset will be kept intact. If the outlier protection is triggered, no predictions will be made based on the training dataset. Datatype: Float. Default: 30. reverse_train_test_order Split the feature dataset (see below) and use the latest data split for training and test on historical split of the data. This allows the model to be trained up to the most recent data point, while avoiding overfitting. However, you should be careful to understand the unorthodox nature of this parameter before employing it. Datatype: Boolean. Default: False (no reversal). shuffle_after_split Split the data into train and test sets, and then shuffle both sets individually. Datatype: Boolean. Default: False. buffer_train_data_candles Cut buffer_train_data_candles off the beginning and end of the training data after the indicators were populated. The main example use is when predicting maxima and minima, the argrelextrema function cannot know the maxima/minima at the edges of the timerange. To improve model accuracy, it is best to compute argrelextrema on the full timerange and then use this function to cut off the edges (buffer) by the kernel. In another case, if the targets are set to a shifted price movement, this buffer is unnecessary because the shifted candles at the end of the timerange will be NaN and FreqAI will automatically cut those off of the training dataset. Datatype: Integer. Default: 0."},{"location":"freqai-parameter-table/#data-split-parameters","title":"Data split parameters","text":"Parameter Description Data split parameters within the freqai.data_split_parameters sub dictionary data_split_parameters Include any additional parameters available from scikit-learn test_train_split(), which are shown here (external website). Datatype: Dictionary. test_size The fraction of data that should be used for testing instead of training. Datatype: Positive float < 1. shuffle Shuffle the training data points during training. Typically, to not remove the chronological order of data in time-series forecasting, this is set to False. Datatype: Boolean. Default: False."},{"location":"freqai-parameter-table/#model-training-parameters","title":"Model training parameters","text":"Parameter Description Model training parameters within the freqai.model_training_parameters sub dictionary model_training_parameters A flexible dictionary that includes all parameters available by the selected model library. For example, if you use LightGBMRegressor, this dictionary can contain any parameter available by the LightGBMRegressor here (external website). If you select a different model, this dictionary can contain any parameter from that model. A list of the currently available models can be found here. Datatype: Dictionary. n_estimators The number of boosted trees to fit in the training of the model. Datatype: Integer. learning_rate Boosting learning rate during training of the model. Datatype: Float. n_jobs, thread_count, task_type Set the number of threads for parallel processing and the task_type (gpu or cpu). Different model libraries use different parameter names. Datatype: Float."},{"location":"freqai-parameter-table/#reinforcement-learning-parameters","title":"Reinforcement Learning parameters","text":"Parameter Description Reinforcement Learning Parameters within the freqai.rl_config sub dictionary rl_config A dictionary containing the control parameters for a Reinforcement Learning model. Datatype: Dictionary. train_cycles Training time steps will be set based on the `train_cycles * number of training data points. Datatype: Integer. max_trade_duration_candles Guides the agent training to keep trades below desired length. Example usage shown in prediction_models/ReinforcementLearner.py within the customizable calculate_reward() function. Datatype: int. model_type Model string from stable_baselines3 or SBcontrib. Available strings include: 'TRPO', 'ARS', 'RecurrentPPO', 'MaskablePPO', 'PPO', 'A2C', 'DQN'. User should ensure that model_training_parameters match those available to the corresponding stable_baselines3 model by visiting their documentation. PPO doc (external website) Datatype: string. policy_type One of the available policy types from stable_baselines3 Datatype: string. max_training_drawdown_pct The maximum drawdown that the agent is allowed to experience during training. Datatype: float. Default: 0.8 cpu_count Number of threads/cpus to dedicate to the Reinforcement Learning training process (depending on if ReinforcementLearning_multiproc is selected or not). Recommended to leave this untouched, by default, this value is set to the total number of physical cores minus 1. Datatype: int. model_reward_parameters Parameters used inside the customizable calculate_reward() function in ReinforcementLearner.py Datatype: int. add_state_info Tell FreqAI to include state information in the feature set for training and inferencing. The current state variables include trade duration, current profit, trade position. This is only available in dry/live runs, and is automatically switched to false for backtesting. Datatype: bool. Default: False. net_arch Network architecture which is well described in stable_baselines3 doc. In summary: [<shared layers>, dict(vf=[<non-shared value network layers>], pi=[<non-shared policy network layers>])]. By default this is set to [128, 128], which defines 2 shared hidden layers with 128 units each. randomize_starting_position Randomize the starting point of each episode to avoid overfitting. Datatype: bool. Default: False. drop_ohlc_from_features Do not include the normalized ohlc data in the feature set passed to the agent during training (ohlc will still be used for driving the environment in all cases) Datatype: Boolean. Default: False progress_bar Display a progress bar with the current progress, elapsed time and estimated remaining time. Datatype: Boolean. Default: False."},{"location":"freqai-parameter-table/#pytorch-parameters","title":"PyTorch parameters","text":""},{"location":"freqai-parameter-table/#general","title":"general","text":"Parameter Description Model training parameters within the freqai.model_training_parameters sub dictionary learning_rate Learning rate to be passed to the optimizer. Datatype: float. Default: 3e-4. model_kwargs Parameters to be passed to the model class. Datatype: dict. Default: {}. trainer_kwargs Parameters to be passed to the trainer class. Datatype: dict. Default: {}."},{"location":"freqai-parameter-table/#trainer_kwargs","title":"trainer_kwargs","text":"Parameter Description Model training parameters within the freqai.model_training_parameters.model_kwargs sub dictionary n_epochs The n_epochs parameter is a crucial setting in the PyTorch training loop that determines the number of times the entire training dataset will be used to update the model's parameters. An epoch represents one full pass through the entire training dataset. Overrides n_steps. Either n_epochs or n_steps must be set. Datatype: int. optional. Default: 10. n_steps An alternative way of setting n_epochs - the number of training iterations to run. Iteration here refer to the number of times we call optimizer.step(). Ignored if n_epochs is set. A simplified version of the function: n_epochs = n_steps / (n_obs / batch_size) The motivation here is that n_steps is easier to optimize and keep stable across different n_obs - the number of data points. Datatype: int. optional. Default: None. batch_size The size of the batches to use during training. Datatype: int. Default: 64."},{"location":"freqai-parameter-table/#additional-parameters","title":"Additional parameters","text":"Parameter Description Extraneous parameters freqai.keras If the selected model makes use of Keras (typical for TensorFlow-based prediction models), this flag needs to be activated so that the model save/loading follows Keras standards. Datatype: Boolean. Default: False. freqai.conv_width The width of a neural network input tensor. This replaces the need for shifting candles (include_shifted_candles) by feeding in historical data points as the second dimension of the tensor. Technically, this parameter can also be used for regressors, but it only adds computational overhead and does not change the model training/prediction. Datatype: Integer. Default: 2. freqai.reduce_df_footprint Recast all numeric columns to float32/int32, with the objective of reducing ram/disk usage and decreasing train/inference timing. This parameter is set in the main level of the Freqtrade configuration file (not inside FreqAI). Datatype: Boolean. Default: False."},{"location":"freqai-reinforcement-learning/","title":"Reinforcement Learning","text":"

    Installation size

    Reinforcement learning dependencies include large packages such as torch, which should be explicitly requested during ./setup.sh -i by answering \"y\" to the question \"Do you also want dependencies for freqai-rl (~700mb additional space required) [y/N]?\". Users who prefer docker should ensure they use the docker image appended with _freqairl.

    "},{"location":"freqai-reinforcement-learning/#background-and-terminology","title":"Background and terminology","text":""},{"location":"freqai-reinforcement-learning/#what-is-rl-and-why-does-freqai-need-it","title":"What is RL and why does FreqAI need it?","text":"

    Reinforcement learning involves two important components, the agent and the training environment. During agent training, the agent moves through historical data candle by candle, always making 1 of a set of actions: Long entry, long exit, short entry, short exit, neutral). During this training process, the environment tracks the performance of these actions and rewards the agent according to a custom user made calculate_reward() (here we offer a default reward for users to build on if they wish details here). The reward is used to train weights in a neural network.

    A second important component of the FreqAI RL implementation is the use of state information. State information is fed into the network at each step, including current profit, current position, and current trade duration. These are used to train the agent in the training environment, and to reinforce the agent in dry/live (this functionality is not available in backtesting). FreqAI + Freqtrade is a perfect match for this reinforcing mechanism since this information is readily available in live deployments.

    Reinforcement learning is a natural progression for FreqAI, since it adds a new layer of adaptivity and market reactivity that Classifiers and Regressors cannot match. However, Classifiers and Regressors have strengths that RL does not have such as robust predictions. Improperly trained RL agents may find \"cheats\" and \"tricks\" to maximize reward without actually winning any trades. For this reason, RL is more complex and demands a higher level of understanding than typical Classifiers and Regressors.

    "},{"location":"freqai-reinforcement-learning/#the-rl-interface","title":"The RL interface","text":"

    With the current framework, we aim to expose the training environment via the common \"prediction model\" file, which is a user inherited BaseReinforcementLearner object (e.g. freqai/prediction_models/ReinforcementLearner). Inside this user class, the RL environment is available and customized via MyRLEnv as shown below.

    We envision the majority of users focusing their effort on creative design of the calculate_reward() function details here, while leaving the rest of the environment untouched. Other users may not touch the environment at all, and they will only play with the configuration settings and the powerful feature engineering that already exists in FreqAI. Meanwhile, we enable advanced users to create their own model classes entirely.

    The framework is built on stable_baselines3 (torch) and OpenAI gym for the base environment class. But generally speaking, the model class is well isolated. Thus, the addition of competing libraries can be easily integrated into the existing framework. For the environment, it is inheriting from gym.Env which means that it is necessary to write an entirely new environment in order to switch to a different library.

    "},{"location":"freqai-reinforcement-learning/#important-considerations","title":"Important considerations","text":"

    As explained above, the agent is \"trained\" in an artificial trading \"environment\". In our case, that environment may seem quite similar to a real Freqtrade backtesting environment, but it is NOT. In fact, the RL training environment is much more simplified. It does not incorporate any of the complicated strategy logic, such as callbacks like custom_exit, custom_stoploss, leverage controls, etc. The RL environment is instead a very \"raw\" representation of the true market, where the agent has free will to learn the policy (read: stoploss, take profit, etc.) which is enforced by the calculate_reward(). Thus, it is important to consider that the agent training environment is not identical to the real world.

    "},{"location":"freqai-reinforcement-learning/#running-reinforcement-learning","title":"Running Reinforcement Learning","text":"

    Setting up and running a Reinforcement Learning model is the same as running a Regressor or Classifier. The same two flags, --freqaimodel and --strategy, must be defined on the command line:

    freqtrade trade --freqaimodel ReinforcementLearner --strategy MyRLStrategy --config config.json\n

    where ReinforcementLearner will use the templated ReinforcementLearner from freqai/prediction_models/ReinforcementLearner (or a custom user defined one located in user_data/freqaimodels). The strategy, on the other hand, follows the same base feature engineering with feature_engineering_* as a typical Regressor. The difference lies in the creation of the targets, Reinforcement Learning doesn't require them. However, FreqAI requires a default (neutral) value to be set in the action column:

        def set_freqai_targets(self, dataframe, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        More details about feature engineering available:\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering\n\n        :param df: strategy dataframe which will receive the targets\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        # For RL, there are no direct targets to set. This is filler (neutral)\n        # until the agent sends an action.\n        dataframe[\"&-action\"] = 0\n        return dataframe\n

    Most of the function remains the same as for typical Regressors, however, the function below shows how the strategy must pass the raw price data to the agent so that it has access to raw OHLCV in the training environment:

        def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        # The following features are necessary for RL models\n        dataframe[f\"%-raw_close\"] = dataframe[\"close\"]\n        dataframe[f\"%-raw_open\"] = dataframe[\"open\"]\n        dataframe[f\"%-raw_high\"] = dataframe[\"high\"]\n        dataframe[f\"%-raw_low\"] = dataframe[\"low\"]\n    return dataframe\n

    Finally, there is no explicit \"label\" to make - instead it is necessary to assign the &-action column which will contain the agent's actions when accessed in populate_entry/exit_trends(). In the present example, the neutral action to 0. This value should align with the environment used. FreqAI provides two environments, both use 0 as the neutral action.

    After users realize there are no labels to set, they will soon understand that the agent is making its \"own\" entry and exit decisions. This makes strategy construction rather simple. The entry and exit signals come from the agent in the form of an integer - which are used directly to decide entries and exits in the strategy:

        def populate_entry_trend(self, df: DataFrame, metadata: dict) -> DataFrame:\n\n        enter_long_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 1]\n\n        if enter_long_conditions:\n            df.loc[\n                reduce(lambda x, y: x & y, enter_long_conditions), [\"enter_long\", \"enter_tag\"]\n            ] = (1, \"long\")\n\n        enter_short_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 3]\n\n        if enter_short_conditions:\n            df.loc[\n                reduce(lambda x, y: x & y, enter_short_conditions), [\"enter_short\", \"enter_tag\"]\n            ] = (1, \"short\")\n\n        return df\n\n    def populate_exit_trend(self, df: DataFrame, metadata: dict) -> DataFrame:\n        exit_long_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 2]\n        if exit_long_conditions:\n            df.loc[reduce(lambda x, y: x & y, exit_long_conditions), \"exit_long\"] = 1\n\n        exit_short_conditions = [df[\"do_predict\"] == 1, df[\"&-action\"] == 4]\n        if exit_short_conditions:\n            df.loc[reduce(lambda x, y: x & y, exit_short_conditions), \"exit_short\"] = 1\n\n        return df\n

    It is important to consider that &-action depends on which environment they choose to use. The example above shows 5 actions, where 0 is neutral, 1 is enter long, 2 is exit long, 3 is enter short and 4 is exit short.

    "},{"location":"freqai-reinforcement-learning/#configuring-the-reinforcement-learner","title":"Configuring the Reinforcement Learner","text":"

    In order to configure the Reinforcement Learner the following dictionary must exist in the freqai config:

            \"rl_config\": {\n            \"train_cycles\": 25,\n            \"add_state_info\": true,\n            \"max_trade_duration_candles\": 300,\n            \"max_training_drawdown_pct\": 0.02,\n            \"cpu_count\": 8,\n            \"model_type\": \"PPO\",\n            \"policy_type\": \"MlpPolicy\",\n            \"model_reward_parameters\": {\n                \"rr\": 1,\n                \"profit_aim\": 0.025\n            }\n        }\n

    Parameter details can be found here, but in general the train_cycles decides how many times the agent should cycle through the candle data in its artificial environment to train weights in the model. model_type is a string which selects one of the available models in stable_baselines(external link).

    Note

    If you would like to experiment with continual_learning, then you should set that value to true in the main freqai configuration dictionary. This will tell the Reinforcement Learning library to continue training new models from the final state of previous models, instead of retraining new models from scratch each time a retrain is initiated.

    Note

    Remember that the general model_training_parameters dictionary should contain all the model hyperparameter customizations for the particular model_type. For example, PPO parameters can be found here.

    "},{"location":"freqai-reinforcement-learning/#creating-a-custom-reward-function","title":"Creating a custom reward function","text":"

    Not for production

    Warning! The reward function provided with the Freqtrade source code is a showcase of functionality designed to show/test as many possible environment control features as possible. It is also designed to run quickly on small computers. This is a benchmark, it is not for live production. Please beware that you will need to create your own custom_reward() function or use a template built by other users outside of the Freqtrade source code.

    As you begin to modify the strategy and the prediction model, you will quickly realize some important differences between the Reinforcement Learner and the Regressors/Classifiers. Firstly, the strategy does not set a target value (no labels!). Instead, you set the calculate_reward() function inside the MyRLEnv class (see below). A default calculate_reward() is provided inside prediction_models/ReinforcementLearner.py to demonstrate the necessary building blocks for creating rewards, but this is not designed for production. Users must create their own custom reinforcement learning model class or use a pre-built one from outside the Freqtrade source code and save it to user_data/freqaimodels. It is inside the calculate_reward() where creative theories about the market can be expressed. For example, you can reward your agent when it makes a winning trade, and penalize the agent when it makes a losing trade. Or perhaps, you wish to reward the agent for entering trades, and penalize the agent for sitting in trades too long. Below we show examples of how these rewards are all calculated:

    Hint

    The best reward functions are ones that are continuously differentiable, and well scaled. In other words, adding a single large negative penalty to a rare event is not a good idea, and the neural net will not be able to learn that function. Instead, it is better to add a small negative penalty to a common event. This will help the agent learn faster. Not only this, but you can help improve the continuity of your rewards/penalties by having them scale with severity according to some linear/exponential functions. In other words, you'd slowly scale the penalty as the duration of the trade increases. This is better than a single large penalty occurring at a single point in time.

    from freqtrade.freqai.prediction_models.ReinforcementLearner import ReinforcementLearner\nfrom freqtrade.freqai.RL.Base5ActionRLEnv import Actions, Base5ActionRLEnv, Positions\n\n\nclass MyCoolRLModel(ReinforcementLearner):\n    \"\"\"\n    User created RL prediction model.\n\n    Save this file to `freqtrade/user_data/freqaimodels`\n\n    then use it with:\n\n    freqtrade trade --freqaimodel MyCoolRLModel --config config.json --strategy SomeCoolStrat\n\n    Here the users can override any of the functions\n    available in the `IFreqaiModel` inheritance tree. Most importantly for RL, this\n    is where the user overrides `MyRLEnv` (see below), to define custom\n    `calculate_reward()` function, or to override any other parts of the environment.\n\n    This class also allows users to override any other part of the IFreqaiModel tree.\n    For example, the user can override `def fit()` or `def train()` or `def predict()`\n    to take fine-tuned control over these processes.\n\n    Another common override may be `def data_cleaning_predict()` where the user can\n    take fine-tuned control over the data handling pipeline.\n    \"\"\"\n    class MyRLEnv(Base5ActionRLEnv):\n        \"\"\"\n        User made custom environment. This class inherits from BaseEnvironment and gym.Env.\n        Users can override any functions from those parent classes. Here is an example\n        of a user customized `calculate_reward()` function.\n\n        Warning!\n        This is function is a showcase of functionality designed to show as many possible\n        environment control features as possible. It is also designed to run quickly\n        on small computers. This is a benchmark, it is *not* for live production.\n        \"\"\"\n        def calculate_reward(self, action: int) -> float:\n            # first, penalize if the action is not valid\n            if not self._is_valid(action):\n                return -2\n            pnl = self.get_unrealized_profit()\n\n            factor = 100\n\n            pair = self.pair.replace(':', '')\n\n            # you can use feature values from dataframe\n            # Assumes the shifted RSI indicator has been generated in the strategy.\n            rsi_now = self.raw_features[f\"%-rsi-period_10_shift-1_{pair}_\"\n                            f\"{self.config['timeframe']}\"].iloc[self._current_tick]\n\n            # reward agent for entering trades\n            if (action in (Actions.Long_enter.value, Actions.Short_enter.value)\n                    and self._position == Positions.Neutral):\n                if rsi_now < 40:\n                    factor = 40 / rsi_now\n                else:\n                    factor = 1\n                return 25 * factor\n\n            # discourage agent from not entering trades\n            if action == Actions.Neutral.value and self._position == Positions.Neutral:\n                return -1\n            max_trade_duration = self.rl_config.get('max_trade_duration_candles', 300)\n            trade_duration = self._current_tick - self._last_trade_tick\n            if trade_duration <= max_trade_duration:\n                factor *= 1.5\n            elif trade_duration > max_trade_duration:\n                factor *= 0.5\n            # discourage sitting in position\n            if self._position in (Positions.Short, Positions.Long) and \\\n            action == Actions.Neutral.value:\n                return -1 * trade_duration / max_trade_duration\n            # close long\n            if action == Actions.Long_exit.value and self._position == Positions.Long:\n                if pnl > self.profit_aim * self.rr:\n                    factor *= self.rl_config['model_reward_parameters'].get('win_reward_factor', 2)\n                return float(pnl * factor)\n            # close short\n            if action == Actions.Short_exit.value and self._position == Positions.Short:\n                if pnl > self.profit_aim * self.rr:\n                    factor *= self.rl_config['model_reward_parameters'].get('win_reward_factor', 2)\n                return float(pnl * factor)\n            return 0.\n
    "},{"location":"freqai-reinforcement-learning/#using-tensorboard","title":"Using Tensorboard","text":"

    Reinforcement Learning models benefit from tracking training metrics. FreqAI has integrated Tensorboard to allow users to track training and evaluation performance across all coins and across all retrainings. Tensorboard is activated via the following command:

    tensorboard --logdir user_data/models/unique-id\n

    where unique-id is the identifier set in the freqai configuration file. This command must be run in a separate shell to view the output in the browser at 127.0.0.1:6006 (6006 is the default port used by Tensorboard).

    "},{"location":"freqai-reinforcement-learning/#custom-logging","title":"Custom logging","text":"

    FreqAI also provides a built in episodic summary logger called self.tensorboard_log for adding custom information to the Tensorboard log. By default, this function is already called once per step inside the environment to record the agent actions. All values accumulated for all steps in a single episode are reported at the conclusion of each episode, followed by a full reset of all metrics to 0 in preparation for the subsequent episode.

    self.tensorboard_log can also be used anywhere inside the environment, for example, it can be added to the calculate_reward function to collect more detailed information about how often various parts of the reward were called:

        class MyRLEnv(Base5ActionRLEnv):\n        \"\"\"\n        User made custom environment. This class inherits from BaseEnvironment and gym.Env.\n        Users can override any functions from those parent classes. Here is an example\n        of a user customized `calculate_reward()` function.\n        \"\"\"\n        def calculate_reward(self, action: int) -> float:\n            if not self._is_valid(action):\n                self.tensorboard_log(\"invalid\")\n                return -2\n

    Note

    The self.tensorboard_log() function is designed for tracking incremented objects only i.e. events, actions inside the training environment. If the event of interest is a float, the float can be passed as the second argument e.g. self.tensorboard_log(\"float_metric1\", 0.23). In this case the metric values are not incremented.

    "},{"location":"freqai-reinforcement-learning/#choosing-a-base-environment","title":"Choosing a base environment","text":"

    FreqAI provides three base environments, Base3ActionRLEnvironment, Base4ActionEnvironment and Base5ActionEnvironment. As the names imply, the environments are customized for agents that can select from 3, 4 or 5 actions. The Base3ActionEnvironment is the simplest, the agent can select from hold, long, or short. This environment can also be used for long-only bots (it automatically follows the can_short flag from the strategy), where long is the enter condition and short is the exit condition. Meanwhile, in the Base4ActionEnvironment, the agent can enter long, enter short, hold neutral, or exit position. Finally, in the Base5ActionEnvironment, the agent has the same actions as Base4, but instead of a single exit action, it separates exit long and exit short. The main changes stemming from the environment selection include:

    • the actions available in the calculate_reward
    • the actions consumed by the user strategy

    All of the FreqAI provided environments inherit from an action/position agnostic environment object called the BaseEnvironment, which contains all shared logic. The architecture is designed to be easily customized. The simplest customization is the calculate_reward() (see details here). However, the customizations can be further extended into any of the functions inside the environment. You can do this by simply overriding those functions inside your MyRLEnv in the prediction model file. Or for more advanced customizations, it is encouraged to create an entirely new environment inherited from BaseEnvironment.

    Note

    Only the Base3ActionRLEnv can do long-only training/trading (set the user strategy attribute can_short = False).

    "},{"location":"freqai-running/","title":"Running FreqAI","text":"

    There are two ways to train and deploy an adaptive machine learning model - live deployment and historical backtesting. In both cases, FreqAI runs/simulates periodic retraining of models as shown in the following figure:

    "},{"location":"freqai-running/#live-deployments","title":"Live deployments","text":"

    FreqAI can be run dry/live using the following command:

    freqtrade trade --strategy FreqaiExampleStrategy --config config_freqai.example.json --freqaimodel LightGBMRegressor\n

    When launched, FreqAI will start training a new model, with a new identifier, based on the config settings. Following training, the model will be used to make predictions on incoming candles until a new model is available. New models are typically generated as often as possible, with FreqAI managing an internal queue of the coin pairs to try to keep all models equally up to date. FreqAI will always use the most recently trained model to make predictions on incoming live data. If you do not want FreqAI to retrain new models as often as possible, you can set live_retrain_hours to tell FreqAI to wait at least that number of hours before training a new model. Additionally, you can set expired_hours to tell FreqAI to avoid making predictions on models that are older than that number of hours.

    Trained models are by default saved to disk to allow for reuse during backtesting or after a crash. You can opt to purge old models to save disk space by setting \"purge_old_models\": true in the config.

    To start a dry/live run from a saved backtest model (or from a previously crashed dry/live session), you only need to specify the identifier of the specific model:

        \"freqai\": {\n        \"identifier\": \"example\",\n        \"live_retrain_hours\": 0.5\n    }\n

    In this case, although FreqAI will initiate with a pre-trained model, it will still check to see how much time has elapsed since the model was trained. If a full live_retrain_hours has elapsed since the end of the loaded model, FreqAI will start training a new model.

    "},{"location":"freqai-running/#automatic-data-download","title":"Automatic data download","text":"

    FreqAI automatically downloads the proper amount of data needed to ensure training of a model through the defined train_period_days and startup_candle_count (see the parameter table for detailed descriptions of these parameters).

    "},{"location":"freqai-running/#saving-prediction-data","title":"Saving prediction data","text":"

    All predictions made during the lifetime of a specific identifier model are stored in historic_predictions.pkl to allow for reloading after a crash or changes made to the config.

    "},{"location":"freqai-running/#purging-old-model-data","title":"Purging old model data","text":"

    FreqAI stores new model files after each successful training. These files become obsolete as new models are generated to adapt to new market conditions. If you are planning to leave FreqAI running for extended periods of time with high frequency retraining, you should enable purge_old_models in the config:

        \"freqai\": {\n        \"purge_old_models\": 4,\n    }\n

    This will automatically purge all models older than the four most recently trained ones to save disk space. Inputing \"0\" will never purge any models.

    "},{"location":"freqai-running/#backtesting","title":"Backtesting","text":"

    The FreqAI backtesting module can be executed with the following command:

    freqtrade backtesting --strategy FreqaiExampleStrategy --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --freqaimodel LightGBMRegressor --timerange 20210501-20210701\n

    If this command has never been executed with the existing config file, FreqAI will train a new model for each pair, for each backtesting window within the expanded --timerange.

    Backtesting mode requires downloading the necessary data before deployment (unlike in dry/live mode where FreqAI handles the data downloading automatically). You should be careful to consider that the time range of the downloaded data is more than the backtesting time range. This is because FreqAI needs data prior to the desired backtesting time range in order to train a model to be ready to make predictions on the first candle of the set backtesting time range. More details on how to calculate the data to download can be found here.

    Model reuse

    Once the training is completed, you can execute the backtesting again with the same config file and FreqAI will find the trained models and load them instead of spending time training. This is useful if you want to tweak (or even hyperopt) buy and sell criteria inside the strategy. If you want to retrain a new model with the same config file, you should simply change the identifier. This way, you can return to using any model you wish by simply specifying the identifier.

    Note

    Backtesting calls set_freqai_targets() one time for each backtest window (where the number of windows is the full backtest timerange divided by the backtest_period_days parameter). Doing this means that the targets simulate dry/live behavior without look ahead bias. However, the definition of the features in feature_engineering_*() is performed once on the entire training timerange. This means that you should be sure that features do not look-ahead into the future. More details about look-ahead bias can be found in Common Mistakes.

    "},{"location":"freqai-running/#saving-backtesting-prediction-data","title":"Saving backtesting prediction data","text":"

    To allow for tweaking your strategy (not the features!), FreqAI will automatically save the predictions during backtesting so that they can be reused for future backtests and live runs using the same identifier model. This provides a performance enhancement geared towards enabling high-level hyperopting of entry/exit criteria.

    An additional directory called backtesting_predictions, which contains all the predictions stored in feather format, will be created in the unique-id folder.

    To change your features, you must set a new identifier in the config to signal to FreqAI to train new models.

    To save the models generated during a particular backtest so that you can start a live deployment from one of them instead of training a new model, you must set save_backtest_models to True in the config.

    Note

    To ensure that the model can be reused, freqAI will call your strategy with a dataframe of length 1. If your strategy requires more data than this to generate the same features, you can't reuse backtest predictions for live deployment and need to update your identifier for each new backtest.

    "},{"location":"freqai-running/#backtest-live-collected-predictions","title":"Backtest live collected predictions","text":"

    FreqAI allow you to reuse live historic predictions through the backtest parameter --freqai-backtest-live-models. This can be useful when you want to reuse predictions generated in dry/run for comparison or other study.

    The --timerange parameter must not be informed, as it will be automatically calculated through the data in the historic predictions file.

    "},{"location":"freqai-running/#downloading-data-to-cover-the-full-backtest-period","title":"Downloading data to cover the full backtest period","text":"

    For live/dry deployments, FreqAI will download the necessary data automatically. However, to use backtesting functionality, you need to download the necessary data using download-data (details here). You need to pay careful attention to understanding how much additional data needs to be downloaded to ensure that there is a sufficient amount of training data before the start of the backtesting time range. The amount of additional data can be roughly estimated by moving the start date of the time range backwards by train_period_days and the startup_candle_count (see the parameter table for detailed descriptions of these parameters) from the beginning of the desired backtesting time range.

    As an example, to backtest the --timerange 20210501-20210701 using the example config which sets train_period_days to 30, together with startup_candle_count: 40 on a maximum include_timeframes of 1h, the start date for the downloaded data needs to be 20210501 - 30 days - 40 * 1h / 24 hours = 20210330 (31.7 days earlier than the start of the desired training time range).

    "},{"location":"freqai-running/#deciding-the-size-of-the-sliding-training-window-and-backtesting-duration","title":"Deciding the size of the sliding training window and backtesting duration","text":"

    The backtesting time range is defined with the typical --timerange parameter in the configuration file. The duration of the sliding training window is set by train_period_days, whilst backtest_period_days is the sliding backtesting window, both in number of days (backtest_period_days can be a float to indicate sub-daily retraining in live/dry mode). In the presented example config (found in config_examples/config_freqai.example.json), the user is asking FreqAI to use a training period of 30 days and backtest on the subsequent 7 days. After the training of the model, FreqAI will backtest the subsequent 7 days. The \"sliding window\" then moves one week forward (emulating FreqAI retraining once per week in live mode) and the new model uses the previous 30 days (including the 7 days used for backtesting by the previous model) to train. This is repeated until the end of --timerange. This means that if you set --timerange 20210501-20210701, FreqAI will have trained 8 separate models at the end of --timerange (because the full range comprises 8 weeks).

    Note

    Although fractional backtest_period_days is allowed, you should be aware that the --timerange is divided by this value to determine the number of models that FreqAI will need to train in order to backtest the full range. For example, by setting a --timerange of 10 days, and a backtest_period_days of 0.1, FreqAI will need to train 100 models per pair to complete the full backtest. Because of this, a true backtest of FreqAI adaptive training would take a very long time. The best way to fully test a model is to run it dry and let it train constantly. In this case, backtesting would take the exact same amount of time as a dry run.

    "},{"location":"freqai-running/#defining-model-expirations","title":"Defining model expirations","text":"

    During dry/live mode, FreqAI trains each coin pair sequentially (on separate threads/GPU from the main Freqtrade bot). This means that there is always an age discrepancy between models. If you are training on 50 pairs, and each pair requires 5 minutes to train, the oldest model will be over 4 hours old. This may be undesirable if the characteristic time scale (the trade duration target) for a strategy is less than 4 hours. You can decide to only make trade entries if the model is less than a certain number of hours old by setting the expiration_hours in the config file:

        \"freqai\": {\n        \"expiration_hours\": 0.5,\n    }\n

    In the presented example config, the user will only allow predictions on models that are less than \u00bd hours old.

    "},{"location":"freqai-running/#controlling-the-model-learning-process","title":"Controlling the model learning process","text":"

    Model training parameters are unique to the selected machine learning library. FreqAI allows you to set any parameter for any library using the model_training_parameters dictionary in the config. The example config (found in config_examples/config_freqai.example.json) shows some of the example parameters associated with Catboost and LightGBM, but you can add any parameters available in those libraries or any other machine learning library you choose to implement.

    Data split parameters are defined in data_split_parameters which can be any parameters associated with scikit-learn's train_test_split() function. train_test_split() has a parameters called shuffle which allows to shuffle the data or keep it unshuffled. This is particularly useful to avoid biasing training with temporally auto-correlated data. More details about these parameters can be found the scikit-learn website (external website).

    The FreqAI specific parameter label_period_candles defines the offset (number of candles into the future) used for the labels. In the presented example config, the user is asking for labels that are 24 candles in the future.

    "},{"location":"freqai-running/#continual-learning","title":"Continual learning","text":"

    You can choose to adopt a continual learning scheme by setting \"continual_learning\": true in the config. By enabling continual_learning, after training an initial model from scratch, subsequent trainings will start from the final model state of the preceding training. This gives the new model a \"memory\" of the previous state. By default, this is set to False which means that all new models are trained from scratch, without input from previous models.

    Continual learning enforces a constant parameter space

    Since continual_learning means that the model parameter space cannot change between trainings, principal_component_analysis is automatically disabled when continual_learning is enabled. Hint: PCA changes the parameter space and the number of features, learn more about PCA here.

    Experimental functionality

    Beware that this is currently a naive approach to incremental learning, and it has a high probability of overfitting/getting stuck in local minima while the market moves away from your model. We have the mechanics available in FreqAI primarily for experimental purposes and so that it is ready for more mature approaches to continual learning in chaotic systems like the crypto market.

    "},{"location":"freqai-running/#hyperopt","title":"Hyperopt","text":"

    You can hyperopt using the same command as for typical Freqtrade hyperopt:

    freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates --config config_examples/config_freqai.example.json --timerange 20220428-20220507\n

    hyperopt requires you to have the data pre-downloaded in the same fashion as if you were doing backtesting. In addition, you must consider some restrictions when trying to hyperopt FreqAI strategies:

    • The --analyze-per-epoch hyperopt parameter is not compatible with FreqAI.
    • It's not possible to hyperopt indicators in the feature_engineering_*() and set_freqai_targets() functions. This means that you cannot optimize model parameters using hyperopt. Apart from this exception, it is possible to optimize all other spaces.
    • The backtesting instructions also apply to hyperopt.

    The best method for combining hyperopt and FreqAI is to focus on hyperopting entry/exit thresholds/criteria. You need to focus on hyperopting parameters that are not used in your features. For example, you should not try to hyperopt rolling window lengths in the feature creation, or any part of the FreqAI config which changes predictions. In order to efficiently hyperopt the FreqAI strategy, FreqAI stores predictions as dataframes and reuses them. Hence the requirement to hyperopt entry/exit thresholds/criteria only.

    A good example of a hyperoptable parameter in FreqAI is a threshold for the Dissimilarity Index (DI) DI_values beyond which we consider data points as outliers:

    di_max = IntParameter(low=1, high=20, default=10, space='buy', optimize=True, load=True)\ndataframe['outlier'] = np.where(dataframe['DI_values'] > self.di_max.value/10, 1, 0)\n

    This specific hyperopt would help you understand the appropriate DI_values for your particular parameter space.

    "},{"location":"freqai-running/#using-tensorboard","title":"Using Tensorboard","text":"

    Availability

    FreqAI includes tensorboard for a variety of models, including XGBoost, all PyTorch models, Reinforcement Learning, and Catboost. If you would like to see Tensorboard integrated into another model type, please open an issue on the Freqtrade GitHub

    Requirements

    Tensorboard logging requires the FreqAI torch installation/docker image.

    The easiest way to use tensorboard is to ensure freqai.activate_tensorboard is set to True (default setting) in your configuration file, run FreqAI, then open a separate shell and run:

    cd freqtrade\ntensorboard --logdir user_data/models/unique-id\n

    where unique-id is the identifier set in the freqai configuration file. This command must be run in a separate shell if you wish to view the output in your browser at 127.0.0.1:6060 (6060 is the default port used by Tensorboard).

    Deactivate for improved performance

    Tensorboard logging can slow down training and should be deactivated for production use.

    "},{"location":"freqai/","title":"Introduction","text":""},{"location":"freqai/#freqai","title":"FreqAI","text":""},{"location":"freqai/#introduction","title":"Introduction","text":"

    FreqAI is a software designed to automate a variety of tasks associated with training a predictive machine learning model to generate market forecasts given a set of input signals. In general, FreqAI aims to be a sandbox for easily deploying robust machine learning libraries on real-time data (details).

    Note

    FreqAI is, and always will be, a not-for-profit, open-source project. FreqAI does not have a crypto token, FreqAI does not sell signals, and FreqAI does not have a domain besides the present freqtrade documentation.

    Features include:

    • Self-adaptive retraining - Retrain models during live deployments to self-adapt to the market in a supervised manner
    • Rapid feature engineering - Create large rich feature sets (10k+ features) based on simple user-created strategies
    • High performance - Threading allows for adaptive model retraining on a separate thread (or on GPU if available) from model inferencing (prediction) and bot trade operations. Newest models and data are kept in RAM for rapid inferencing
    • Realistic backtesting - Emulate self-adaptive training on historic data with a backtesting module that automates retraining
    • Extensibility - The generalized and robust architecture allows for incorporating any machine learning library/method available in Python. Eight examples are currently available, including classifiers, regressors, and a convolutional neural network
    • Smart outlier removal - Remove outliers from training and prediction data sets using a variety of outlier detection techniques
    • Crash resilience - Store trained models to disk to make reloading from a crash fast and easy, and purge obsolete files for sustained dry/live runs
    • Automatic data normalization - Normalize the data in a smart and statistically safe way
    • Automatic data download - Compute timeranges for data downloads and update historic data (in live deployments)
    • Cleaning of incoming data - Handle NaNs safely before training and model inferencing
    • Dimensionality reduction - Reduce the size of the training data via Principal Component Analysis
    • Deploying bot fleets - Set one bot to train models while a fleet of consumers use signals.
    "},{"location":"freqai/#quick-start","title":"Quick start","text":"

    The easiest way to quickly test FreqAI is to run it in dry mode with the following command:

    freqtrade trade --config config_examples/config_freqai.example.json --strategy FreqaiExampleStrategy --freqaimodel LightGBMRegressor --strategy-path freqtrade/templates\n

    You will see the boot-up process of automatic data downloading, followed by simultaneous training and trading.

    Not for production

    The example strategy provided with the Freqtrade source code is designed for showcasing/testing a wide variety of FreqAI features. It is also designed to run on small computers so that it can be used as a benchmark between developers and users. It is not designed to be run in production.

    An example strategy, prediction model, and config to use as a starting points can be found in freqtrade/templates/FreqaiExampleStrategy.py, freqtrade/freqai/prediction_models/LightGBMRegressor.py, and config_examples/config_freqai.example.json, respectively.

    "},{"location":"freqai/#general-approach","title":"General approach","text":"

    You provide FreqAI with a set of custom base indicators (the same way as in a typical Freqtrade strategy) as well as target values (labels). For each pair in the whitelist, FreqAI trains a model to predict the target values based on the input of custom indicators. The models are then consistently retrained, with a predetermined frequency, to adapt to market conditions. FreqAI offers the ability to both backtest strategies (emulating reality with periodic retraining on historic data) and deploy dry/live runs. In dry/live conditions, FreqAI can be set to constant retraining in a background thread to keep models as up to date as possible.

    An overview of the algorithm, explaining the data processing pipeline and model usage, is shown below.

    "},{"location":"freqai/#important-machine-learning-vocabulary","title":"Important machine learning vocabulary","text":"

    Features - the parameters, based on historic data, on which a model is trained. All features for a single candle are stored as a vector. In FreqAI, you build a feature data set from anything you can construct in the strategy.

    Labels - the target values that the model is trained toward. Each feature vector is associated with a single label that is defined by you within the strategy. These labels intentionally look into the future and are what you are training the model to be able to predict.

    Training - the process of \"teaching\" the model to match the feature sets to the associated labels. Different types of models \"learn\" in different ways which means that one might be better than another for a specific application. More information about the different models that are already implemented in FreqAI can be found here.

    Train data - a subset of the feature data set that is fed to the model during training to \"teach\" the model how to predict the targets. This data directly influences weight connections in the model.

    Test data - a subset of the feature data set that is used to evaluate the performance of the model after training. This data does not influence nodal weights within the model.

    Inferencing - the process of feeding a trained model new unseen data on which it will make a prediction.

    "},{"location":"freqai/#install-prerequisites","title":"Install prerequisites","text":"

    The normal Freqtrade install process will ask if you wish to install FreqAI dependencies. You should reply \"yes\" to this question if you wish to use FreqAI. If you did not reply yes, you can manually install these dependencies after the install with:

    pip install -r requirements-freqai.txt\n

    Note

    Catboost will not be installed on low-powered arm devices (raspberry), since it does not provide wheels for this platform.

    "},{"location":"freqai/#usage-with-docker","title":"Usage with docker","text":"

    If you are using docker, a dedicated tag with FreqAI dependencies is available as :freqai. As such - you can replace the image line in your docker compose file with image: freqtradeorg/freqtrade:develop_freqai. This image contains the regular FreqAI dependencies. Similar to native installs, Catboost will not be available on ARM based devices. If you would like to use PyTorch or Reinforcement learning, you should use the torch or RL tags, image: freqtradeorg/freqtrade:develop_freqaitorch, image: freqtradeorg/freqtrade:develop_freqairl.

    docker-compose-freqai.yml

    We do provide an explicit docker-compose file for this in docker/docker-compose-freqai.yml - which can be used via docker compose -f docker/docker-compose-freqai.yml run ... - or can be copied to replace the original docker file. This docker-compose file also contains a (disabled) section to enable GPU resources within docker containers. This obviously assumes the system has GPU resources available.

    "},{"location":"freqai/#freqai-position-in-open-source-machine-learning-landscape","title":"FreqAI position in open-source machine learning landscape","text":"

    Forecasting chaotic time-series based systems, such as equity/cryptocurrency markets, requires a broad set of tools geared toward testing a wide range of hypotheses. Fortunately, a recent maturation of robust machine learning libraries (e.g. scikit-learn) has opened up a wide range of research possibilities. Scientists from a diverse range of fields can now easily prototype their studies on an abundance of established machine learning algorithms. Similarly, these user-friendly libraries enable \"citzen scientists\" to use their basic Python skills for data exploration. However, leveraging these machine learning libraries on historical and live chaotic data sources can be logistically difficult and expensive. Additionally, robust data collection, storage, and handling presents a disparate challenge. FreqAI aims to provide a generalized and extensible open-sourced framework geared toward live deployments of adaptive modeling for market forecasting. The FreqAI framework is effectively a sandbox for the rich world of open-source machine learning libraries. Inside the FreqAI sandbox, users find they can combine a wide variety of third-party libraries to test creative hypotheses on a free live 24/7 chaotic data source - cryptocurrency exchange data.

    "},{"location":"freqai/#citing-freqai","title":"Citing FreqAI","text":"

    FreqAI is published in the Journal of Open Source Software. If you find FreqAI useful in your research, please use the following citation:

    @article{Caulk2022, \n    doi = {10.21105/joss.04864},\n    url = {https://doi.org/10.21105/joss.04864},\n    year = {2022}, publisher = {The Open Journal},\n    volume = {7}, number = {80}, pages = {4864},\n    author = {Robert A. Caulk and Elin T\u00f6rnquist and Matthias Voppichler and Andrew R. Lawless and Ryan McMullan and Wagner Costa Santos and Timothy C. Pogue and Johan van der Vlugt and Stefan P. Gehring and Pascal Schmidt},\n    title = {FreqAI: generalizing adaptive modeling for chaotic time-series market forecasts},\n    journal = {Journal of Open Source Software} } \n
    "},{"location":"freqai/#common-pitfalls","title":"Common pitfalls","text":"

    FreqAI cannot be combined with dynamic VolumePairlists (or any pairlist filter that adds and removes pairs dynamically). This is for performance reasons - FreqAI relies on making quick predictions/retrains. To do this effectively, it needs to download all the training data at the beginning of a dry/live instance. FreqAI stores and appends new candles automatically for future retrains. This means that if new pairs arrive later in the dry run due to a volume pairlist, it will not have the data ready. However, FreqAI does work with the ShufflePairlist or a VolumePairlist which keeps the total pairlist constant (but reorders the pairs according to volume).

    "},{"location":"freqai/#additional-learning-materials","title":"Additional learning materials","text":"

    Here we compile some external materials that provide deeper looks into various components of FreqAI:

    • Real-time head-to-head: Adaptive modeling of financial market data using XGBoost and CatBoost
    • FreqAI - from price to prediction
    "},{"location":"freqai/#support","title":"Support","text":"

    You can find support for FreqAI in a variety of places, including the Freqtrade discord, the dedicated FreqAI discord, and in github issues.

    "},{"location":"freqai/#credits","title":"Credits","text":"

    FreqAI is developed by a group of individuals who all contribute specific skillsets to the project.

    Conception and software development: Robert Caulk @robcaulk

    Theoretical brainstorming and data analysis: Elin T\u00f6rnquist @th0rntwig

    Code review and software architecture brainstorming: @xmatthias

    Software development: Wagner Costa @wagnercosta Emre Suzen @aemr3 Timothy Pogue @wizrds

    Beta testing and bug reporting: Stefan Gehring @bloodhunter4rc, @longyu, Andrew Lawless @paranoidandy, Pascal Schmidt @smidelis, Ryan McMullan @smarmau, Juha Nyk\u00e4nen @suikula, Johan van der Vlugt @jooopiert, Rich\u00e1rd J\u00f3zsa @richardjosza

    "},{"location":"hyperopt/","title":"Hyperopt","text":"

    This page explains how to tune your strategy by finding the optimal parameters, a process called hyperparameter optimization. The bot uses algorithms included in the scikit-optimize package to accomplish this. The search will burn all your CPU cores, make your laptop sound like a fighter jet and still take a long time.

    In general, the search for best parameters starts with a few random combinations (see below for more details) and then uses Bayesian search with a ML regressor algorithm (currently ExtraTreesRegressor) to quickly find a combination of parameters in the search hyperspace that minimizes the value of the loss function.

    Hyperopt requires historic data to be available, just as backtesting does (hyperopt runs backtesting many times with different parameters). To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    Bug

    Hyperopt can crash when used with only 1 CPU Core as found out in Issue #1133

    Note

    Since 2021.4 release you no longer have to write a separate hyperopt class, but can configure the parameters directly in the strategy. The legacy method was supported up to 2021.8 and has been removed in 2021.9.

    "},{"location":"hyperopt/#install-hyperopt-dependencies","title":"Install hyperopt dependencies","text":"

    Since Hyperopt dependencies are not needed to run the bot itself, are heavy, can not be easily built on some platforms (like Raspberry PI), they are not installed by default. Before you run Hyperopt, you need to install the corresponding dependencies, as described in this section below.

    Note

    Since Hyperopt is a resource intensive process, running it on a Raspberry Pi is not recommended nor supported.

    "},{"location":"hyperopt/#docker","title":"Docker","text":"

    The docker-image includes hyperopt dependencies, no further action needed.

    "},{"location":"hyperopt/#easy-installation-script-setupsh-manual-installation","title":"Easy installation script (setup.sh) / Manual installation","text":"
    source .venv/bin/activate\npip install -r requirements-hyperopt.txt\n
    "},{"location":"hyperopt/#hyperopt-command-reference","title":"Hyperopt command reference","text":"
    usage: freqtrade hyperopt [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                          [--userdir PATH] [-s NAME] [--strategy-path PATH]\n                          [--recursive-strategy-search] [--freqaimodel NAME]\n                          [--freqaimodel-path PATH] [-i TIMEFRAME]\n                          [--timerange TIMERANGE]\n                          [--data-format-ohlcv {json,jsongz,hdf5}]\n                          [--max-open-trades INT]\n                          [--stake-amount STAKE_AMOUNT] [--fee FLOAT]\n                          [-p PAIRS [PAIRS ...]] [--hyperopt-path PATH]\n                          [--eps] [--dmmp] [--enable-protections]\n                          [--dry-run-wallet DRY_RUN_WALLET]\n                          [--timeframe-detail TIMEFRAME_DETAIL] [-e INT]\n                          [--spaces {all,buy,sell,roi,stoploss,trailing,protection,trades,default} [{all,buy,sell,roi,stoploss,trailing,protection,trades,default} ...]]\n                          [--print-all] [--no-color] [--print-json] [-j JOBS]\n                          [--random-state INT] [--min-trades INT]\n                          [--hyperopt-loss NAME] [--disable-param-export]\n                          [--ignore-missing-spaces] [--analyze-per-epoch]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --data-format-ohlcv {json,jsongz,hdf5}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `json`).\n  --max-open-trades INT\n                        Override the value of the `max_open_trades`\n                        configuration setting.\n  --stake-amount STAKE_AMOUNT\n                        Override the value of the `stake_amount` configuration\n                        setting.\n  --fee FLOAT           Specify fee ratio. Will be applied twice (on trade\n                        entry and exit).\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --hyperopt-path PATH  Specify additional lookup path for Hyperopt Loss\n                        functions.\n  --eps, --enable-position-stacking\n                        Allow buying the same pair multiple times (position\n                        stacking).\n  --dmmp, --disable-max-market-positions\n                        Disable applying `max_open_trades` during backtest\n                        (same as setting `max_open_trades` to a very high\n                        number).\n  --enable-protections, --enableprotections\n                        Enable protections for backtesting.Will slow\n                        backtesting down by a considerable amount, but will\n                        include configured protections\n  --dry-run-wallet DRY_RUN_WALLET, --starting-balance DRY_RUN_WALLET\n                        Starting balance, used for backtesting / hyperopt and\n                        dry-runs.\n  --timeframe-detail TIMEFRAME_DETAIL\n                        Specify detail timeframe for backtesting (`1m`, `5m`,\n                        `30m`, `1h`, `1d`).\n  -e INT, --epochs INT  Specify number of epochs (default: 100).\n  --spaces {all,buy,sell,roi,stoploss,trailing,protection,trades,default} [{all,buy,sell,roi,stoploss,trailing,protection,trades,default} ...]\n                        Specify which parameters to hyperopt. Space-separated\n                        list.\n  --print-all           Print all results, not only the best ones.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n  --print-json          Print output in JSON format.\n  -j JOBS, --job-workers JOBS\n                        The number of concurrently running jobs for\n                        hyperoptimization (hyperopt worker processes). If -1\n                        (default), all CPUs are used, for -2, all CPUs but one\n                        are used, etc. If 1 is given, no parallel computing\n                        code is used at all.\n  --random-state INT    Set random state to some positive integer for\n                        reproducible hyperopt results.\n  --min-trades INT      Set minimal desired number of trades for evaluations\n                        in the hyperopt optimization path (default: 1).\n  --hyperopt-loss NAME, --hyperoptloss NAME\n                        Specify the class name of the hyperopt loss function\n                        class (IHyperOptLoss). Different functions can\n                        generate completely different results, since the\n                        target for optimization is different. Built-in\n                        Hyperopt-loss-functions are:\n                        ShortTradeDurHyperOptLoss, OnlyProfitHyperOptLoss,\n                        SharpeHyperOptLoss, SharpeHyperOptLossDaily,\n                        SortinoHyperOptLoss, SortinoHyperOptLossDaily,\n                        CalmarHyperOptLoss, MaxDrawDownHyperOptLoss,\n                        MaxDrawDownRelativeHyperOptLoss,\n                        ProfitDrawDownHyperOptLoss\n  --disable-param-export\n                        Disable automatic hyperopt parameter export.\n  --ignore-missing-spaces, --ignore-unparameterized-spaces\n                        Suppress errors for any requested Hyperopt spaces that\n                        do not contain any parameters.\n  --analyze-per-epoch   Run populate_indicators once per epoch.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n  --recursive-strategy-search\n                        Recursively search for a strategy in the strategies\n                        folder.\n  --freqaimodel NAME    Specify a custom freqaimodels.\n  --freqaimodel-path PATH\n                        Specify additional lookup path for freqaimodels.\n
    "},{"location":"hyperopt/#hyperopt-checklist","title":"Hyperopt checklist","text":"

    Checklist on all tasks / possibilities in hyperopt

    Depending on the space you want to optimize, only some of the below are required:

    • define parameters with space='buy' - for entry signal optimization
    • define parameters with space='sell' - for exit signal optimization

    Note

    populate_indicators needs to create all indicators any of the spaces may use, otherwise hyperopt will not work.

    Rarely you may also need to create a nested class named HyperOpt and implement

    • roi_space - for custom ROI optimization (if you need the ranges for the ROI parameters in the optimization hyperspace that differ from default)
    • generate_roi_table - for custom ROI optimization (if you need the ranges for the values in the ROI table that differ from default or the number of entries (steps) in the ROI table which differs from the default 4 steps)
    • stoploss_space - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default)
    • trailing_space - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default)
    • max_open_trades_space - for custom max_open_trades optimization (if you need the ranges for the max_open_trades parameter in the optimization hyperspace that differ from default)

    Quickly optimize ROI, stoploss and trailing stoploss

    You can quickly optimize the spaces roi, stoploss and trailing without changing anything in your strategy.

    # Have a working strategy at hand.\nfreqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi stoploss trailing --strategy MyWorkingStrategy --config config.json -e 100\n
    "},{"location":"hyperopt/#hyperopt-execution-logic","title":"Hyperopt execution logic","text":"

    Hyperopt will first load your data into memory and will then run populate_indicators() once per Pair to generate all indicators, unless --analyze-per-epoch is specified.

    Hyperopt will then spawn into different processes (number of processors, or -j <n>), and run backtesting over and over again, changing the parameters that are part of the --spaces defined.

    For every new set of parameters, freqtrade will run first populate_entry_trend() followed by populate_exit_trend(), and then run the regular backtesting process to simulate trades.

    After backtesting, the results are passed into the loss function, which will evaluate if this result was better or worse than previous results. Based on the loss function result, hyperopt will determine the next set of parameters to try in the next round of backtesting.

    "},{"location":"hyperopt/#configure-your-guards-and-triggers","title":"Configure your Guards and Triggers","text":"

    There are two places you need to change in your strategy file to add a new buy hyperopt for testing:

    • Define the parameters at the class level hyperopt shall be optimizing.
    • Within populate_entry_trend() - use defined parameter values instead of raw constants.

    There you have two different types of indicators: 1. guards and 2. triggers.

    1. Guards are conditions like \"never buy if ADX < 10\", or never buy if current price is over EMA10.
    2. Triggers are ones that actually trigger buy in specific moment, like \"buy when EMA5 crosses over EMA10\" or \"buy when close price touches lower Bollinger band\".

    Guards and Triggers

    Technically, there is no difference between Guards and Triggers. However, this guide will make this distinction to make it clear that signals should not be \"sticking\". Sticking signals are signals that are active for multiple candles. This can lead into entering a signal late (right before the signal disappears - which means that the chance of success is a lot lower than right at the beginning).

    Hyper-optimization will, for each epoch round, pick one trigger and possibly multiple guards.

    "},{"location":"hyperopt/#exit-signal-optimization","title":"Exit signal optimization","text":"

    Similar to the entry-signal above, exit-signals can also be optimized. Place the corresponding settings into the following methods

    • Define the parameters at the class level hyperopt shall be optimizing, either naming them sell_*, or by explicitly defining space='sell'.
    • Within populate_exit_trend() - use defined parameter values instead of raw constants.

    The configuration and rules are the same than for buy signals.

    "},{"location":"hyperopt/#solving-a-mystery","title":"Solving a Mystery","text":"

    Let's say you are curious: should you use MACD crossings or lower Bollinger Bands to trigger your long entries. And you also wonder should you use RSI or ADX to help with those decisions. If you decide to use RSI or ADX, which values should I use for them?

    So let's use hyperparameter optimization to solve this mystery.

    "},{"location":"hyperopt/#defining-indicators-to-be-used","title":"Defining indicators to be used","text":"

    We start by calculating the indicators our strategy is going to use.

    class MyAwesomeStrategy(IStrategy):\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Generate all indicators used by the strategy\n        \"\"\"\n        dataframe['adx'] = ta.ADX(dataframe)\n        dataframe['rsi'] = ta.RSI(dataframe)\n        macd = ta.MACD(dataframe)\n        dataframe['macd'] = macd['macd']\n        dataframe['macdsignal'] = macd['macdsignal']\n        dataframe['macdhist'] = macd['macdhist']\n\n        bollinger = ta.BBANDS(dataframe, timeperiod=20, nbdevup=2.0, nbdevdn=2.0)\n        dataframe['bb_lowerband'] = bollinger['lowerband']\n        dataframe['bb_middleband'] = bollinger['middleband']\n        dataframe['bb_upperband'] = bollinger['upperband']\n        return dataframe\n
    "},{"location":"hyperopt/#hyperoptable-parameters","title":"Hyperoptable parameters","text":"

    We continue to define hyperoptable parameters:

    class MyAwesomeStrategy(IStrategy):\n    buy_adx = DecimalParameter(20, 40, decimals=1, default=30.1, space=\"buy\")\n    buy_rsi = IntParameter(20, 40, default=30, space=\"buy\")\n    buy_adx_enabled = BooleanParameter(default=True, space=\"buy\")\n    buy_rsi_enabled = CategoricalParameter([True, False], default=False, space=\"buy\")\n    buy_trigger = CategoricalParameter([\"bb_lower\", \"macd_cross_signal\"], default=\"bb_lower\", space=\"buy\")\n

    The above definition says: I have five parameters I want to randomly combine to find the best combination. buy_rsi is an integer parameter, which will be tested between 20 and 40. This space has a size of 20. buy_adx is a decimal parameter, which will be evaluated between 20 and 40 with 1 decimal place (so values are 20.1, 20.2, ...). This space has a size of 200. Then we have three category variables. First two are either True or False. We use these to either enable or disable the ADX and RSI guards. The last one we call trigger and use it to decide which buy trigger we want to use.

    Parameter space assignment

    Parameters must either be assigned to a variable named buy_* or sell_* - or contain space='buy' | space='sell' to be assigned to a space correctly. If no parameter is available for a space, you'll receive the error that no space was found when running hyperopt. Parameters with unclear space (e.g. adx_period = IntParameter(4, 24, default=14) - no explicit nor implicit space) will not be detected and will therefore be ignored.

    So let's write the buy strategy using these values:

        def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        conditions = []\n        # GUARDS AND TRENDS\n        if self.buy_adx_enabled.value:\n            conditions.append(dataframe['adx'] > self.buy_adx.value)\n        if self.buy_rsi_enabled.value:\n            conditions.append(dataframe['rsi'] < self.buy_rsi.value)\n\n        # TRIGGERS\n        if self.buy_trigger.value == 'bb_lower':\n            conditions.append(dataframe['close'] < dataframe['bb_lowerband'])\n        if self.buy_trigger.value == 'macd_cross_signal':\n            conditions.append(qtpylib.crossed_above(\n                dataframe['macd'], dataframe['macdsignal']\n            ))\n\n        # Check that volume is not 0\n        conditions.append(dataframe['volume'] > 0)\n\n        if conditions:\n            dataframe.loc[\n                reduce(lambda x, y: x & y, conditions),\n                'enter_long'] = 1\n\n        return dataframe\n

    Hyperopt will now call populate_entry_trend() many times (epochs) with different value combinations. It will use the given historical data and simulate buys based on the buy signals generated with the above function. Based on the results, hyperopt will tell you which parameter combination produced the best results (based on the configured loss function).

    Note

    The above setup expects to find ADX, RSI and Bollinger Bands in the populated indicators. When you want to test an indicator that isn't used by the bot currently, remember to add it to the populate_indicators() method in your strategy or hyperopt file.

    "},{"location":"hyperopt/#parameter-types","title":"Parameter types","text":"

    There are four parameter types each suited for different purposes.

    • IntParameter - defines an integral parameter with upper and lower boundaries of search space.
    • DecimalParameter - defines a floating point parameter with a limited number of decimals (default 3). Should be preferred instead of RealParameter in most cases.
    • RealParameter - defines a floating point parameter with upper and lower boundaries and no precision limit. Rarely used as it creates a space with a near infinite number of possibilities.
    • CategoricalParameter - defines a parameter with a predetermined number of choices.
    • BooleanParameter - Shorthand for CategoricalParameter([True, False]) - great for \"enable\" parameters.
    "},{"location":"hyperopt/#parameter-options","title":"Parameter options","text":"

    There are two parameter options that can help you to quickly test various ideas:

    • optimize - when set to False, the parameter will not be included in optimization process. (Default: True)
    • load - when set to False, results of a previous hyperopt run (in buy_params and sell_params either in your strategy or the JSON output file) will not be used as the starting value for subsequent hyperopts. The default value specified in the parameter will be used instead. (Default: True)

    Effects of load=False on backtesting

    Be aware that setting the load option to False will mean backtesting will also use the default value specified in the parameter and not the value found through hyperoptimisation.

    Warning

    Hyperoptable parameters cannot be used in populate_indicators - as hyperopt does not recalculate indicators for each epoch, so the starting value would be used in this case.

    "},{"location":"hyperopt/#optimizing-an-indicator-parameter","title":"Optimizing an indicator parameter","text":"

    Assuming you have a simple strategy in mind - a EMA cross strategy (2 Moving averages crossing) - and you'd like to find the ideal parameters for this strategy. By default, we assume a stoploss of 5% - and a take-profit (minimal_roi) of 10% - which means freqtrade will sell the trade once 10% profit has been reached.

    from pandas import DataFrame\nfrom functools import reduce\n\nimport talib.abstract as ta\n\nfrom freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, \n                                IStrategy, IntParameter)\nimport freqtrade.vendor.qtpylib.indicators as qtpylib\n\nclass MyAwesomeStrategy(IStrategy):\n    stoploss = -0.05\n    timeframe = '15m'\n    minimal_roi = {\n        \"0\":  0.10\n    }\n    # Define the parameter spaces\n    buy_ema_short = IntParameter(3, 50, default=5)\n    buy_ema_long = IntParameter(15, 200, default=50)\n\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"Generate all indicators used by the strategy\"\"\"\n\n        # Calculate all ema_short values\n        for val in self.buy_ema_short.range:\n            dataframe[f'ema_short_{val}'] = ta.EMA(dataframe, timeperiod=val)\n\n        # Calculate all ema_long values\n        for val in self.buy_ema_long.range:\n            dataframe[f'ema_long_{val}'] = ta.EMA(dataframe, timeperiod=val)\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        conditions = []\n        conditions.append(qtpylib.crossed_above(\n                dataframe[f'ema_short_{self.buy_ema_short.value}'], dataframe[f'ema_long_{self.buy_ema_long.value}']\n            ))\n\n        # Check that volume is not 0\n        conditions.append(dataframe['volume'] > 0)\n\n        if conditions:\n            dataframe.loc[\n                reduce(lambda x, y: x & y, conditions),\n                'enter_long'] = 1\n        return dataframe\n\n    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        conditions = []\n        conditions.append(qtpylib.crossed_above(\n                dataframe[f'ema_long_{self.buy_ema_long.value}'], dataframe[f'ema_short_{self.buy_ema_short.value}']\n            ))\n\n        # Check that volume is not 0\n        conditions.append(dataframe['volume'] > 0)\n\n        if conditions:\n            dataframe.loc[\n                reduce(lambda x, y: x & y, conditions),\n                'exit_long'] = 1\n        return dataframe\n

    Breaking it down:

    Using self.buy_ema_short.range will return a range object containing all entries between the Parameters low and high value. In this case (IntParameter(3, 50, default=5)), the loop would run for all numbers between 3 and 50 ([3, 4, 5, ... 49, 50]). By using this in a loop, hyperopt will generate 48 new columns (['buy_ema_3', 'buy_ema_4', ... , 'buy_ema_50']).

    Hyperopt itself will then use the selected value to create the buy and sell signals.

    While this strategy is most likely too simple to provide consistent profit, it should serve as an example how optimize indicator parameters.

    Note

    self.buy_ema_short.range will act differently between hyperopt and other modes. For hyperopt, the above example may generate 48 new columns, however for all other modes (backtesting, dry/live), it will only generate the column for the selected value. You should therefore avoid using the resulting column with explicit values (values other than self.buy_ema_short.value).

    Note

    range property may also be used with DecimalParameter and CategoricalParameter. RealParameter does not provide this property due to infinite search space.

    Performance tip

    During normal hyperopting, indicators are calculated once and supplied to each epoch, linearly increasing RAM usage as a factor of increasing cores. As this also has performance implications, there are two alternatives to reduce RAM usage

    • Move ema_short and ema_long calculations from populate_indicators() to populate_entry_trend(). Since populate_entry_trend() will be calculated every epoch, you don't need to use .range functionality.
    • hyperopt provides --analyze-per-epoch which will move the execution of populate_indicators() to the epoch process, calculating a single value per parameter per epoch instead of using the .range functionality. In this case, .range functionality will only return the actually used value.

    These alternatives will reduce RAM usage, but increase CPU usage. However, your hyperopting run will be less likely to fail due to Out Of Memory (OOM) issues.

    Whether you are using .range functionality or the alternatives above, you should try to use space ranges as small as possible since this will improve CPU/RAM usage.

    "},{"location":"hyperopt/#optimizing-protections","title":"Optimizing protections","text":"

    Freqtrade can also optimize protections. How you optimize protections is up to you, and the following should be considered as example only.

    The strategy will simply need to define the \"protections\" entry as property returning a list of protection configurations.

    from pandas import DataFrame\nfrom functools import reduce\n\nimport talib.abstract as ta\n\nfrom freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, \n                                IStrategy, IntParameter)\nimport freqtrade.vendor.qtpylib.indicators as qtpylib\n\nclass MyAwesomeStrategy(IStrategy):\n    stoploss = -0.05\n    timeframe = '15m'\n    # Define the parameter spaces\n    cooldown_lookback = IntParameter(2, 48, default=5, space=\"protection\", optimize=True)\n    stop_duration = IntParameter(12, 200, default=5, space=\"protection\", optimize=True)\n    use_stop_protection = BooleanParameter(default=True, space=\"protection\", optimize=True)\n\n\n    @property\n    def protections(self):\n        prot = []\n\n        prot.append({\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": self.cooldown_lookback.value\n        })\n        if self.use_stop_protection.value:\n            prot.append({\n                \"method\": \"StoplossGuard\",\n                \"lookback_period_candles\": 24 * 3,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": self.stop_duration.value,\n                \"only_per_pair\": False\n            })\n\n        return prot\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # ...\n

    You can then run hyperopt as follows: freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --strategy MyAwesomeStrategy --spaces protection

    Note

    The protection space is not part of the default space, and is only available with the Parameters Hyperopt interface, not with the legacy hyperopt interface (which required separate hyperopt files). Freqtrade will also automatically change the \"--enable-protections\" flag if the protection space is selected.

    Warning

    If protections are defined as property, entries from the configuration will be ignored. It is therefore recommended to not define protections in the configuration.

    "},{"location":"hyperopt/#migrating-from-previous-property-setups","title":"Migrating from previous property setups","text":"

    A migration from a previous setup is pretty simple, and can be accomplished by converting the protections entry to a property. In simple terms, the following configuration will be converted to the below.

    class MyAwesomeStrategy(IStrategy):\n    protections = [\n        {\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": 4\n        }\n    ]\n

    Result

    class MyAwesomeStrategy(IStrategy):\n\n    @property\n    def protections(self):\n        return [\n            {\n                \"method\": \"CooldownPeriod\",\n                \"stop_duration_candles\": 4\n            }\n        ]\n

    You will then obviously also change potential interesting entries to parameters to allow hyper-optimization.

    "},{"location":"hyperopt/#optimizing-max_entry_position_adjustment","title":"Optimizing max_entry_position_adjustment","text":"

    While max_entry_position_adjustment is not a separate space, it can still be used in hyperopt by using the property approach shown above.

    from pandas import DataFrame\nfrom functools import reduce\n\nimport talib.abstract as ta\n\nfrom freqtrade.strategy import (BooleanParameter, CategoricalParameter, DecimalParameter, \n                                IStrategy, IntParameter)\nimport freqtrade.vendor.qtpylib.indicators as qtpylib\n\nclass MyAwesomeStrategy(IStrategy):\n    stoploss = -0.05\n    timeframe = '15m'\n\n    # Define the parameter spaces\n    max_epa = CategoricalParameter([-1, 0, 1, 3, 5, 10], default=1, space=\"buy\", optimize=True)\n\n    @property\n    def max_entry_position_adjustment(self):\n        return self.max_epa.value\n\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # ...\n
    Using IntParameter

    You can also use the IntParameter for this optimization, but you must explicitly return an integer:

    max_epa = IntParameter(-1, 10, default=1, space=\"buy\", optimize=True)\n\n@property\ndef max_entry_position_adjustment(self):\n    return int(self.max_epa.value)\n

    "},{"location":"hyperopt/#loss-functions","title":"Loss-functions","text":"

    Each hyperparameter tuning requires a target. This is usually defined as a loss function (sometimes also called objective function), which should decrease for more desirable results, and increase for bad results.

    A loss function must be specified via the --hyperopt-loss <Class-name> argument (or optionally via the configuration under the \"hyperopt_loss\" key). This class should be in its own file within the user_data/hyperopts/ directory.

    Currently, the following loss functions are builtin:

    • ShortTradeDurHyperOptLoss - (default legacy Freqtrade hyperoptimization loss function) - Mostly for short trade duration and avoiding losses.
    • OnlyProfitHyperOptLoss - takes only amount of profit into consideration.
    • SharpeHyperOptLoss - optimizes Sharpe Ratio calculated on trade returns relative to standard deviation.
    • SharpeHyperOptLossDaily - optimizes Sharpe Ratio calculated on daily trade returns relative to standard deviation.
    • SortinoHyperOptLoss - optimizes Sortino Ratio calculated on trade returns relative to downside standard deviation.
    • SortinoHyperOptLossDaily - optimizes Sortino Ratio calculated on daily trade returns relative to downside standard deviation.
    • MaxDrawDownHyperOptLoss - Optimizes Maximum absolute drawdown.
    • MaxDrawDownRelativeHyperOptLoss - Optimizes both maximum absolute drawdown while also adjusting for maximum relative drawdown.
    • CalmarHyperOptLoss - Optimizes Calmar Ratio calculated on trade returns relative to max drawdown.
    • ProfitDrawDownHyperOptLoss - Optimizes by max Profit & min Drawdown objective. DRAWDOWN_MULT variable within the hyperoptloss file can be adjusted to be stricter or more flexible on drawdown purposes.

    Creation of a custom loss function is covered in the Advanced Hyperopt part of the documentation.

    "},{"location":"hyperopt/#execute-hyperopt","title":"Execute Hyperopt","text":"

    Once you have updated your hyperopt configuration you can run it. Because hyperopt tries a lot of combinations to find the best parameters it will take time to get a good result.

    We strongly recommend to use screen or tmux to prevent any connection loss.

    freqtrade hyperopt --config config.json --hyperopt-loss <hyperoptlossname> --strategy <strategyname> -e 500 --spaces all\n

    The -e option will set how many evaluations hyperopt will do. Since hyperopt uses Bayesian search, running too many epochs at once may not produce greater results. Experience has shown that best results are usually not improving much after 500-1000 epochs. Doing multiple runs (executions) with a few 1000 epochs and different random state will most likely produce different results.

    The --spaces all option determines that all possible parameters should be optimized. Possibilities are listed below.

    Note

    Hyperopt will store hyperopt results with the timestamp of the hyperopt start time. Reading commands (hyperopt-list, hyperopt-show) can use --hyperopt-filename <filename> to read and display older hyperopt results. You can find a list of filenames with ls -l user_data/hyperopt_results/.

    "},{"location":"hyperopt/#execute-hyperopt-with-different-historical-data-source","title":"Execute Hyperopt with different historical data source","text":"

    If you would like to hyperopt parameters using an alternate historical data set that you have on-disk, use the --datadir PATH option. By default, hyperopt uses data from directory user_data/data.

    "},{"location":"hyperopt/#running-hyperopt-with-a-smaller-test-set","title":"Running Hyperopt with a smaller test-set","text":"

    Use the --timerange argument to change how much of the test-set you want to use. For example, to use one month of data, pass --timerange 20210101-20210201 (from january 2021 - february 2021) to the hyperopt call.

    Full command:

    freqtrade hyperopt --strategy <strategyname> --timerange 20210101-20210201\n
    "},{"location":"hyperopt/#running-hyperopt-with-smaller-search-space","title":"Running Hyperopt with Smaller Search Space","text":"

    Use the --spaces option to limit the search space used by hyperopt. Letting Hyperopt optimize everything is a huuuuge search space. Often it might make more sense to start by just searching for initial buy algorithm. Or maybe you just want to optimize your stoploss or roi table for that awesome new buy strategy you have.

    Legal values are:

    • all: optimize everything
    • buy: just search for a new buy strategy
    • sell: just search for a new sell strategy
    • roi: just optimize the minimal profit table for your strategy
    • stoploss: search for the best stoploss value
    • trailing: search for the best trailing stop values
    • trades: search for the best max open trades values
    • protection: search for the best protection parameters (read the protections section on how to properly define these)
    • default: all except trailing and protection
    • space-separated list of any of the above values for example --spaces roi stoploss

    The default Hyperopt Search Space, used when no --space command line option is specified, does not include the trailing hyperspace. We recommend you to run optimization for the trailing hyperspace separately, when the best parameters for other hyperspaces were found, validated and pasted into your custom strategy.

    "},{"location":"hyperopt/#understand-the-hyperopt-result","title":"Understand the Hyperopt Result","text":"

    Once Hyperopt is completed you can use the result to update your strategy. Given the following result from hyperopt:

    Best result:\n\n    44/100:    135 trades. Avg profit  0.57%. Total profit  0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367\n\n    # Buy hyperspace params:\n    buy_params = {\n        'buy_adx': 44,\n        'buy_rsi': 29,\n        'buy_adx_enabled': False,\n        'buy_rsi_enabled': True,\n        'buy_trigger': 'bb_lower'\n    }\n

    You should understand this result like:

    • The buy trigger that worked best was bb_lower.
    • You should not use ADX because 'buy_adx_enabled': False.
    • You should consider using the RSI indicator ('buy_rsi_enabled': True) and the best value is 29.0 ('buy_rsi': 29.0)
    "},{"location":"hyperopt/#automatic-parameter-application-to-the-strategy","title":"Automatic parameter application to the strategy","text":"

    When using Hyperoptable parameters, the result of your hyperopt-run will be written to a json file next to your strategy (so for MyAwesomeStrategy.py, the file would be MyAwesomeStrategy.json). This file is also updated when using the hyperopt-show sub-command, unless --disable-param-export is provided to either of the 2 commands.

    Your strategy class can also contain these results explicitly. Simply copy hyperopt results block and paste them at class level, replacing old parameters (if any). New parameters will automatically be loaded next time strategy is executed.

    Transferring your whole hyperopt result to your strategy would then look like:

    class MyAwesomeStrategy(IStrategy):\n    # Buy hyperspace params:\n    buy_params = {\n        'buy_adx': 44,\n        'buy_rsi': 29,\n        'buy_adx_enabled': False,\n        'buy_rsi_enabled': True,\n        'buy_trigger': 'bb_lower'\n    }\n

    Note

    Values in the configuration file will overwrite Parameter-file level parameters - and both will overwrite parameters within the strategy. The prevalence is therefore: config > parameter file > strategy *_params > parameter default

    "},{"location":"hyperopt/#understand-hyperopt-roi-results","title":"Understand Hyperopt ROI results","text":"

    If you are optimizing ROI (i.e. if optimization search-space contains 'all', 'default' or 'roi'), your result will look as follows and include a ROI table:

    Best result:\n\n    44/100:    135 trades. Avg profit  0.57%. Total profit  0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367\n\n    # ROI table:\n    minimal_roi = {\n        0: 0.10674,\n        21: 0.09158,\n        78: 0.03634,\n        118: 0\n    }\n

    In order to use this best ROI table found by Hyperopt in backtesting and for live trades/dry-run, copy-paste it as the value of the minimal_roi attribute of your custom strategy:

        # Minimal ROI designed for the strategy.\n    # This attribute will be overridden if the config file contains \"minimal_roi\"\n    minimal_roi = {\n        0: 0.10674,\n        21: 0.09158,\n        78: 0.03634,\n        118: 0\n    }\n

    As stated in the comment, you can also use it as the value of the minimal_roi setting in the configuration file.

    "},{"location":"hyperopt/#default-roi-search-space","title":"Default ROI Search Space","text":"

    If you are optimizing ROI, Freqtrade creates the 'roi' optimization hyperspace for you -- it's the hyperspace of components for the ROI tables. By default, each ROI table generated by the Freqtrade consists of 4 rows (steps). Hyperopt implements adaptive ranges for ROI tables with ranges for values in the ROI steps that depend on the timeframe used. By default the values vary in the following ranges (for some of the most used timeframes, values are rounded to 3 digits after the decimal point):

    # step 1m 5m 1h 1d 1 0 0.011...0.119 0 0.03...0.31 0 0.068...0.711 0 0.121...1.258 2 2...8 0.007...0.042 10...40 0.02...0.11 120...480 0.045...0.252 2880...11520 0.081...0.446 3 4...20 0.003...0.015 20...100 0.01...0.04 240...1200 0.022...0.091 5760...28800 0.040...0.162 4 6...44 0.0 30...220 0.0 360...2640 0.0 8640...63360 0.0

    These ranges should be sufficient in most cases. The minutes in the steps (ROI dict keys) are scaled linearly depending on the timeframe used. The ROI values in the steps (ROI dict values) are scaled logarithmically depending on the timeframe used.

    If you have the generate_roi_table() and roi_space() methods in your custom hyperopt, remove them in order to utilize these adaptive ROI tables and the ROI hyperoptimization space generated by Freqtrade by default.

    Override the roi_space() method if you need components of the ROI tables to vary in other ranges. Override the generate_roi_table() and roi_space() methods and implement your own custom approach for generation of the ROI tables during hyperoptimization if you need a different structure of the ROI tables or other amount of rows (steps).

    A sample for these methods can be found in the overriding pre-defined spaces section.

    Reduced search space

    To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however overriding pre-defined spaces to change this to your needs.

    "},{"location":"hyperopt/#understand-hyperopt-stoploss-results","title":"Understand Hyperopt Stoploss results","text":"

    If you are optimizing stoploss values (i.e. if optimization search-space contains 'all', 'default' or 'stoploss'), your result will look as follows and include stoploss:

    Best result:\n\n    44/100:    135 trades. Avg profit  0.57%. Total profit  0.03871918 BTC (0.7722%). Avg duration 180.4 mins. Objective: 1.94367\n\n    # Buy hyperspace params:\n    buy_params = {\n        'buy_adx': 44,\n        'buy_rsi': 29,\n        'buy_adx_enabled': False,\n        'buy_rsi_enabled': True,\n        'buy_trigger': 'bb_lower'\n    }\n\n    stoploss: -0.27996\n

    In order to use this best stoploss value found by Hyperopt in backtesting and for live trades/dry-run, copy-paste it as the value of the stoploss attribute of your custom strategy:

        # Optimal stoploss designed for the strategy\n    # This attribute will be overridden if the config file contains \"stoploss\"\n    stoploss = -0.27996\n

    As stated in the comment, you can also use it as the value of the stoploss setting in the configuration file.

    "},{"location":"hyperopt/#default-stoploss-search-space","title":"Default Stoploss Search Space","text":"

    If you are optimizing stoploss values, Freqtrade creates the 'stoploss' optimization hyperspace for you. By default, the stoploss values in that hyperspace vary in the range -0.35...-0.02, which is sufficient in most cases.

    If you have the stoploss_space() method in your custom hyperopt file, remove it in order to utilize Stoploss hyperoptimization space generated by Freqtrade by default.

    Override the stoploss_space() method and define the desired range in it if you need stoploss values to vary in other range during hyperoptimization. A sample for this method can be found in the overriding pre-defined spaces section.

    Reduced search space

    To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however overriding pre-defined spaces to change this to your needs.

    "},{"location":"hyperopt/#understand-hyperopt-trailing-stop-results","title":"Understand Hyperopt Trailing Stop results","text":"

    If you are optimizing trailing stop values (i.e. if optimization search-space contains 'all' or 'trailing'), your result will look as follows and include trailing stop parameters:

    Best result:\n\n    45/100:    606 trades. Avg profit  1.04%. Total profit  0.31555614 BTC ( 630.48%). Avg duration 150.3 mins. Objective: -1.10161\n\n    # Trailing stop:\n    trailing_stop = True\n    trailing_stop_positive = 0.02001\n    trailing_stop_positive_offset = 0.06038\n    trailing_only_offset_is_reached = True\n

    In order to use these best trailing stop parameters found by Hyperopt in backtesting and for live trades/dry-run, copy-paste them as the values of the corresponding attributes of your custom strategy:

        # Trailing stop\n    # These attributes will be overridden if the config file contains corresponding values.\n    trailing_stop = True\n    trailing_stop_positive = 0.02001\n    trailing_stop_positive_offset = 0.06038\n    trailing_only_offset_is_reached = True\n

    As stated in the comment, you can also use it as the values of the corresponding settings in the configuration file.

    "},{"location":"hyperopt/#default-trailing-stop-search-space","title":"Default Trailing Stop Search Space","text":"

    If you are optimizing trailing stop values, Freqtrade creates the 'trailing' optimization hyperspace for you. By default, the trailing_stop parameter is always set to True in that hyperspace, the value of the trailing_only_offset_is_reached vary between True and False, the values of the trailing_stop_positive and trailing_stop_positive_offset parameters vary in the ranges 0.02...0.35 and 0.01...0.1 correspondingly, which is sufficient in most cases.

    Override the trailing_space() method and define the desired range in it if you need values of the trailing stop parameters to vary in other ranges during hyperoptimization. A sample for this method can be found in the overriding pre-defined spaces section.

    Reduced search space

    To limit the search space further, Decimals are limited to 3 decimal places (a precision of 0.001). This is usually sufficient, every value more precise than this will usually result in overfitted results. You can however overriding pre-defined spaces to change this to your needs.

    "},{"location":"hyperopt/#reproducible-results","title":"Reproducible results","text":"

    The search for optimal parameters starts with a few (currently 30) random combinations in the hyperspace of parameters, random Hyperopt epochs. These random epochs are marked with an asterisk character (*) in the first column in the Hyperopt output.

    The initial state for generation of these random values (random state) is controlled by the value of the --random-state command line option. You can set it to some arbitrary value of your choice to obtain reproducible results.

    If you have not set this value explicitly in the command line options, Hyperopt seeds the random state with some random value for you. The random state value for each Hyperopt run is shown in the log, so you can copy and paste it into the --random-state command line option to repeat the set of the initial random epochs used.

    If you have not changed anything in the command line options, configuration, timerange, Strategy and Hyperopt classes, historical data and the Loss Function -- you should obtain same hyper-optimization results with same random state value used.

    "},{"location":"hyperopt/#output-formatting","title":"Output formatting","text":"

    By default, hyperopt prints colorized results -- epochs with positive profit are printed in the green color. This highlighting helps you find epochs that can be interesting for later analysis. Epochs with zero total profit or with negative profits (losses) are printed in the normal color. If you do not need colorization of results (for instance, when you are redirecting hyperopt output to a file) you can switch colorization off by specifying the --no-color option in the command line.

    You can use the --print-all command line option if you would like to see all results in the hyperopt output, not only the best ones. When --print-all is used, current best results are also colorized by default -- they are printed in bold (bright) style. This can also be switched off with the --no-color command line option.

    Windows and color output

    Windows does not support color-output natively, therefore it is automatically disabled. To have color-output for hyperopt running under windows, please consider using WSL.

    "},{"location":"hyperopt/#position-stacking-and-disabling-max-market-positions","title":"Position stacking and disabling max market positions","text":"

    In some situations, you may need to run Hyperopt (and Backtesting) with the --eps/--enable-position-staking and --dmmp/--disable-max-market-positions arguments.

    By default, hyperopt emulates the behavior of the Freqtrade Live Run/Dry Run, where only one open trade is allowed for every traded pair. The total number of trades open for all pairs is also limited by the max_open_trades setting. During Hyperopt/Backtesting this may lead to some potential trades to be hidden (or masked) by previously open trades.

    The --eps/--enable-position-stacking argument allows emulation of buying the same pair multiple times, while --dmmp/--disable-max-market-positions disables applying max_open_trades during Hyperopt/Backtesting (which is equal to setting max_open_trades to a very high number).

    Note

    Dry/live runs will NOT use position stacking - therefore it does make sense to also validate the strategy without this as it's closer to reality.

    You can also enable position stacking in the configuration file by explicitly setting \"position_stacking\"=true.

    "},{"location":"hyperopt/#out-of-memory-errors","title":"Out of Memory errors","text":"

    As hyperopt consumes a lot of memory (the complete data needs to be in memory once per parallel backtesting process), it's likely that you run into \"out of memory\" errors. To combat these, you have multiple options:

    • Reduce the amount of pairs.
    • Reduce the timerange used (--timerange <timerange>).
    • Avoid using --timeframe-detail (this loads a lot of additional data into memory).
    • Reduce the number of parallel processes (-j <n>).
    • Increase the memory of your machine.
    • Use --analyze-per-epoch if you're using a lot of parameters with .range functionality.
    "},{"location":"hyperopt/#the-objective-has-been-evaluated-at-this-point-before","title":"The objective has been evaluated at this point before.","text":"

    If you see The objective has been evaluated at this point before. - then this is a sign that your space has been exhausted, or is close to that. Basically all points in your space have been hit (or a local minima has been hit) - and hyperopt does no longer find points in the multi-dimensional space it did not try yet. Freqtrade tries to counter the \"local minima\" problem by using new, randomized points in this case.

    Example:

    buy_ema_short = IntParameter(5, 20, default=10, space=\"buy\", optimize=True)\n# This is the only parameter in the buy space\n

    The buy_ema_short space has 15 possible values (5, 6, ... 19, 20). If you now run hyperopt for the buy space, hyperopt will only have 15 values to try before running out of options. Your epochs should therefore be aligned to the possible values - or you should be ready to interrupt a run if you norice a lot of The objective has been evaluated at this point before. warnings.

    "},{"location":"hyperopt/#show-details-of-hyperopt-results","title":"Show details of Hyperopt results","text":"

    After you run Hyperopt for the desired amount of epochs, you can later list all results for analysis, select only best or profitable once, and show the details for any of the epochs previously evaluated. This can be done with the hyperopt-list and hyperopt-show sub-commands. The usage of these sub-commands is described in the Utils chapter.

    "},{"location":"hyperopt/#validate-backtesting-results","title":"Validate backtesting results","text":"

    Once the optimized strategy has been implemented into your strategy, you should backtest this strategy to make sure everything is working as expected.

    To achieve same the results (number of trades, their durations, profit, etc.) as during Hyperopt, please use the same configuration and parameters (timerange, timeframe, ...) used for hyperopt --dmmp/--disable-max-market-positions and --eps/--enable-position-stacking for Backtesting.

    "},{"location":"hyperopt/#why-do-my-backtest-results-not-match-my-hyperopt-results","title":"Why do my backtest results not match my hyperopt results?","text":"

    Should results not match, check the following factors:

    • You may have added parameters to hyperopt in populate_indicators() where they will be calculated only once for all epochs. If you are, for example, trying to optimise multiple SMA timeperiod values, the hyperoptable timeperiod parameter should be placed in populate_entry_trend() which is calculated every epoch. See Optimizing an indicator parameter.
    • If you have disabled the auto-export of hyperopt parameters into the JSON parameters file, double-check to make sure you transferred all hyperopted values into your strategy correctly.
    • Check the logs to verify what parameters are being set and what values are being used.
    • Pay special care to the stoploss, max_open_trades and trailing stoploss parameters, as these are often set in configuration files, which override changes to the strategy. Check the logs of your backtest to ensure that there were no parameters inadvertently set by the configuration (like stoploss, max_open_trades or trailing_stop).
    • Verify that you do not have an unexpected parameters JSON file overriding the parameters or the default hyperopt settings in your strategy.
    • Verify that any protections that are enabled in backtesting are also enabled when hyperopting, and vice versa. When using --space protection, protections are auto-enabled for hyperopting.
    "},{"location":"installation/","title":"Installation","text":"

    This page explains how to prepare your environment for running the bot.

    The freqtrade documentation describes various ways to install freqtrade

    • Docker images (separate page)
    • Script Installation
    • Manual Installation
    • Installation with Conda

    Please consider using the prebuilt docker images to get started quickly while evaluating how freqtrade works.

    "},{"location":"installation/#information","title":"Information","text":"

    For Windows installation, please use the windows installation guide.

    The easiest way to install and run Freqtrade is to clone the bot Github repository and then run the ./setup.sh script, if it's available for your platform.

    Version considerations

    When cloning the repository the default working branch has the name develop. This branch contains all last features (can be considered as relatively stable, thanks to automated tests). The stable branch contains the code of the last release (done usually once per month on an approximately one week old snapshot of the develop branch to prevent packaging bugs, so potentially it's more stable).

    Note

    Python3.9 or higher and the corresponding pip are assumed to be available. The install-script will warn you and stop if that's not the case. git is also needed to clone the Freqtrade repository. Also, python headers (python<yourversion>-dev / python<yourversion>-devel) must be available for the installation to complete successfully.

    Up-to-date clock

    The clock on the system running the bot must be accurate, synchronized to a NTP server frequently enough to avoid problems with communication to the exchanges.

    "},{"location":"installation/#requirements","title":"Requirements","text":"

    These requirements apply to both Script Installation and Manual Installation.

    ARM64 systems

    If you are running an ARM64 system (like a MacOS M1 or an Oracle VM), please use docker to run freqtrade. While native installation is possible with some manual effort, this is not supported at the moment.

    "},{"location":"installation/#install-guide","title":"Install guide","text":"
    • Python >= 3.9
    • pip
    • git
    • virtualenv (Recommended)
    • TA-Lib (install instructions below)
    "},{"location":"installation/#install-code","title":"Install code","text":"

    We've included/collected install instructions for Ubuntu, MacOS, and Windows. These are guidelines and your success may vary with other distros. OS Specific steps are listed first, the common section below is necessary for all systems.

    Note

    Python3.9 or higher and the corresponding pip are assumed to be available.

    Debian/UbuntuRaspberryPi/Raspbian

    The following assumes the latest Raspbian Buster lite image. This image comes with python3.9 preinstalled, making it easy to get freqtrade up and running.

    Tested using a Raspberry Pi 3 with the Raspbian Buster lite image, all updates applied.

    sudo apt-get install python3-venv libatlas-base-dev cmake curl\n# Use pywheels.org to speed up installation\nsudo echo \"[global]\\nextra-index-url=https://www.piwheels.org/simple\" > tee /etc/pip.conf\n\ngit clone https://github.com/freqtrade/freqtrade.git\ncd freqtrade\n\nbash setup.sh -i\n

    Installation duration

    Depending on your internet speed and the Raspberry Pi version, installation can take multiple hours to complete. Due to this, we recommend to use the pre-build docker-image for Raspberry, by following the Docker quickstart documentation

    Note

    The above does not install hyperopt dependencies. To install these, please use python3 -m pip install -e .[hyperopt]. We do not advise to run hyperopt on a Raspberry Pi, since this is a very resource-heavy operation, which should be done on powerful machine.

    "},{"location":"installation/#install-necessary-dependencies","title":"Install necessary dependencies","text":"
    # update repository\nsudo apt-get update\n\n# install packages\nsudo apt install -y python3-pip python3-venv python3-dev python3-pandas git curl\n
    "},{"location":"installation/#freqtrade-repository","title":"Freqtrade repository","text":"

    Freqtrade is an open source crypto-currency trading bot, whose code is hosted on github.com

    # Download `develop` branch of freqtrade repository\ngit clone https://github.com/freqtrade/freqtrade.git\n\n# Enter downloaded directory\ncd freqtrade\n\n# your choice (1): novice user\ngit checkout stable\n\n# your choice (2): advanced user\ngit checkout develop\n

    (1) This command switches the cloned repository to the use of the stable branch. It's not needed, if you wish to stay on the (2) develop branch.

    You may later switch between branches at any time with the git checkout stable/git checkout develop commands.

    Install from pypi

    An alternative way to install Freqtrade is from pypi. The downside is that this method requires ta-lib to be correctly installed beforehand, and is therefore currently not the recommended way to install Freqtrade.

    pip install freqtrade\n
    "},{"location":"installation/#script-installation","title":"Script Installation","text":"

    First of the ways to install Freqtrade, is to use provided the Linux/MacOS ./setup.sh script, which install all dependencies and help you configure the bot.

    Make sure you fulfill the Requirements and have downloaded the Freqtrade repository.

    "},{"location":"installation/#use-setupsh-install-linuxmacos","title":"Use /setup.sh -install (Linux/MacOS)","text":"

    If you are on Debian, Ubuntu or MacOS, freqtrade provides the script to install freqtrade.

    # --install, Install freqtrade from scratch\n./setup.sh -i\n
    "},{"location":"installation/#activate-your-virtual-environment","title":"Activate your virtual environment","text":"

    Each time you open a new terminal, you must run source .venv/bin/activate to activate your virtual environment.

    # activate virtual environment\nsource ./.venv/bin/activate\n
    "},{"location":"installation/#congratulations","title":"Congratulations","text":"

    You are ready, and run the bot

    "},{"location":"installation/#other-options-of-setupsh-script","title":"Other options of /setup.sh script","text":"

    You can as well update, configure and reset the codebase of your bot with ./script.sh

    # --update, Command git pull to update.\n./setup.sh -u\n# --reset, Hard reset your develop/stable branch.\n./setup.sh -r\n
    ** --install **\n\nWith this option, the script will install the bot and most dependencies:\nYou will need to have git and python3.9+ installed beforehand for this to work.\n\n* Mandatory software as: `ta-lib`\n* Setup your virtualenv under `.venv/`\n\nThis option is a combination of installation tasks and `--reset`\n\n** --update **\n\nThis option will pull the last version of your current branch and update your virtualenv. Run the script with this option periodically to update your bot.\n\n** --reset **\n\nThis option will hard reset your branch (only if you are on either `stable` or `develop`) and recreate your virtualenv.\n
    "},{"location":"installation/#manual-installation","title":"Manual Installation","text":"

    Make sure you fulfill the Requirements and have downloaded the Freqtrade repository.

    "},{"location":"installation/#install-ta-lib","title":"Install TA-Lib","text":""},{"location":"installation/#ta-lib-script-installation","title":"TA-Lib script installation","text":"
    sudo ./build_helpers/install_ta-lib.sh\n

    Note

    This will use the ta-lib tar.gz included in this repository.

    "},{"location":"installation/#ta-lib-manual-installation","title":"TA-Lib manual installation","text":"

    Official installation guide

    wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz\ntar xvzf ta-lib-0.4.0-src.tar.gz\ncd ta-lib\nsed -i.bak \"s|0.00000001|0.000000000000000001 |g\" src/ta_func/ta_utility.h\n./configure --prefix=/usr/local\nmake\nsudo make install\n# On debian based systems (debian, ubuntu, ...) - updating ldconfig might be necessary.\nsudo ldconfig  \ncd ..\nrm -rf ./ta-lib*\n
    "},{"location":"installation/#setup-python-virtual-environment-virtualenv","title":"Setup Python virtual environment (virtualenv)","text":"

    You will run freqtrade in separated virtual environment

    # create virtualenv in directory /freqtrade/.venv\npython3 -m venv .venv\n\n# run virtualenv\nsource .venv/bin/activate\n
    "},{"location":"installation/#install-python-dependencies","title":"Install python dependencies","text":"
    python3 -m pip install --upgrade pip\npython3 -m pip install -r requirements.txt\npython3 -m pip install -e .\n
    "},{"location":"installation/#congratulations_1","title":"Congratulations","text":"

    You are ready, and run the bot

    "},{"location":"installation/#optional-post-installation-tasks","title":"(Optional) Post-installation Tasks","text":"

    Note

    If you run the bot on a server, you should consider using Docker or a terminal multiplexer like screen or tmux to avoid that the bot is stopped on logout.

    On Linux with software suite systemd, as an optional post-installation task, you may wish to setup the bot to run as a systemd service or configure it to send the log messages to the syslog/rsyslog or journald daemons. See Advanced Logging for details.

    "},{"location":"installation/#installation-with-conda","title":"Installation with Conda","text":"

    Freqtrade can also be installed with Miniconda or Anaconda. We recommend using Miniconda as it's installation footprint is smaller. Conda will automatically prepare and manage the extensive library-dependencies of the Freqtrade program.

    "},{"location":"installation/#what-is-conda","title":"What is Conda?","text":"

    Conda is a package, dependency and environment manager for multiple programming languages: conda docs

    "},{"location":"installation/#installation-with-conda_1","title":"Installation with conda","text":""},{"location":"installation/#install-conda","title":"Install Conda","text":"

    Installing on linux

    Installing on windows

    Answer all questions. After installation, it is mandatory to turn your terminal OFF and ON again.

    "},{"location":"installation/#freqtrade-download","title":"Freqtrade download","text":"

    Download and install freqtrade.

    # download freqtrade\ngit clone https://github.com/freqtrade/freqtrade.git\n\n# enter downloaded directory 'freqtrade'\ncd freqtrade      \n
    "},{"location":"installation/#freqtrade-install-conda-environment","title":"Freqtrade install: Conda Environment","text":"
    conda create --name freqtrade python=3.12\n

    Creating Conda Environment

    The conda command create -n automatically installs all nested dependencies for the selected libraries, general structure of installation command is:

    # choose your own packages\nconda env create -n [name of the environment] [python version] [packages]\n
    "},{"location":"installation/#enterexit-freqtrade-environment","title":"Enter/exit freqtrade environment","text":"

    To check available environments, type

    conda env list\n

    Enter installed environment

    # enter conda environment\nconda activate freqtrade\n\n# exit conda environment - don't do it now\nconda deactivate\n

    Install last python dependencies with pip

    python3 -m pip install --upgrade pip\npython3 -m pip install -r requirements.txt\npython3 -m pip install -e .\n

    Patch conda libta-lib (Linux only)

    # Ensure that the environment is active!\nconda activate freqtrade\n\ncd build_helpers\nbash install_ta-lib.sh ${CONDA_PREFIX} nosudo\n
    "},{"location":"installation/#congratulations_2","title":"Congratulations","text":"

    You are ready, and run the bot

    "},{"location":"installation/#important-shortcuts","title":"Important shortcuts","text":"
    # list installed conda environments\nconda env list\n\n# activate base environment\nconda activate\n\n# activate freqtrade environment\nconda activate freqtrade\n\n#deactivate any conda environments\nconda deactivate                              \n
    "},{"location":"installation/#further-info-on-anaconda","title":"Further info on anaconda","text":"

    New heavy packages

    It may happen that creating a new Conda environment, populated with selected packages at the moment of creation takes less time than installing a large, heavy library or application, into previously set environment.

    pip install within conda

    The documentation of conda says that pip should NOT be used within conda, because internal problems can occur. However, they are rare. Anaconda Blogpost

    Nevertheless, that is why, the conda-forge channel is preferred:

    • more libraries are available (less need for pip)
    • conda-forge works better with pip
    • the libraries are newer

    Happy trading!

    "},{"location":"installation/#you-are-ready","title":"You are ready","text":"

    You've made it this far, so you have successfully installed freqtrade.

    "},{"location":"installation/#initialize-the-configuration","title":"Initialize the configuration","text":"
    # Step 1 - Initialize user folder\nfreqtrade create-userdir --userdir user_data\n\n# Step 2 - Create a new configuration file\nfreqtrade new-config --config user_data/config.json\n

    You are ready to run, read Bot Configuration, remember to start with dry_run: True and verify that everything is working.

    To learn how to setup your configuration, please refer to the Bot Configuration documentation page.

    "},{"location":"installation/#start-the-bot","title":"Start the Bot","text":"
    freqtrade trade --config user_data/config.json --strategy SampleStrategy\n

    Warning

    You should read through the rest of the documentation, backtest the strategy you're going to use, and use dry-run before enabling trading with real money.

    "},{"location":"installation/#troubleshooting","title":"Troubleshooting","text":""},{"location":"installation/#common-problem-command-not-found","title":"Common problem: \"command not found\"","text":"

    If you used (1)Script or (2)Manual installation, you need to run the bot in virtual environment. If you get error as below, make sure venv is active.

    # if:\nbash: freqtrade: command not found\n\n# then activate your virtual environment\nsource ./.venv/bin/activate\n
    "},{"location":"installation/#macos-installation-error","title":"MacOS installation error","text":"

    Newer versions of MacOS may have installation failed with errors like error: command 'g++' failed with exit status 1.

    This error will require explicit installation of the SDK Headers, which are not installed by default in this version of MacOS. For MacOS 10.14, this can be accomplished with the below command.

    open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg\n

    If this file is inexistent, then you're probably on a different version of MacOS, so you may need to consult the internet for specific resolution details.

    "},{"location":"leverage/","title":"Trading with Leverage","text":"

    Beta feature

    This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.

    Multiple bots on one account

    You can't run 2 bots on the same account with leverage. For leveraged / margin trading, freqtrade assumes it's the only user of the account, and all liquidation levels are calculated based on this assumption.

    Trading with leverage is very risky

    Do not trade with a leverage > 1 using a strategy that hasn't shown positive results in a live run using the spot market. Check the stoploss of your strategy. With a leverage of 2, a stoploss of 0.5 (50%) would be too low, and these trades would be liquidated before reaching that stoploss. We do not assume any responsibility for eventual losses that occur from using this software or this mode.

    Please only use advanced trading modes when you know how freqtrade (and your strategy) works. Also, never risk more than what you can afford to lose.

    If you already have an existing strategy, please read the strategy migration guide to migrate your strategy from a freqtrade v2 strategy, to strategy of version 3 which can short and trade futures.

    "},{"location":"leverage/#shorting","title":"Shorting","text":"

    Shorting is not possible when trading with trading_mode set to spot. To short trade, trading_mode must be set to margin(currently unavailable) or futures, with margin_mode set to cross(currently unavailable) or isolated

    For a strategy to short, the strategy class must set the class variable can_short = True

    Please read strategy customization for instructions on how to set signals to enter and exit short trades.

    "},{"location":"leverage/#understand-trading_mode","title":"Understand trading_mode","text":"

    The possible values are: spot (default), margin(Currently unavailable) or futures.

    "},{"location":"leverage/#spot","title":"Spot","text":"

    Regular trading mode (low risk)

    • Long trades only (No short trades).
    • No leverage.
    • No Liquidation.
    • Profits gained/lost are equal to the change in value of the assets (minus trading fees).
    "},{"location":"leverage/#leverage-trading-modes","title":"Leverage trading modes","text":"

    With leverage, a trader borrows capital from the exchange. The capital must be re-payed fully to the exchange (potentially with interest), and the trader keeps any profits, or pays any losses, from any trades made using the borrowed capital.

    Because the capital must always be re-payed, exchanges will liquidate (forcefully sell the traders assets) a trade made using borrowed capital when the total value of assets in the leverage account drops to a certain point (a point where the total value of losses is less than the value of the collateral that the trader actually owns in the leverage account), in order to ensure that the trader has enough capital to pay the borrowed assets back to the exchange. The exchange will also charge a liquidation fee, adding to the traders losses.

    For this reason, DO NOT TRADE WITH LEVERAGE IF YOU DON'T KNOW EXACTLY WHAT YOUR DOING. LEVERAGE TRADING IS HIGH RISK, AND CAN RESULT IN THE VALUE OF YOUR ASSETS DROPPING TO 0 VERY QUICKLY, WITH NO CHANCE OF INCREASING IN VALUE AGAIN.

    "},{"location":"leverage/#margin-currently-unavailable","title":"Margin (currently unavailable)","text":"

    Trading occurs on the spot market, but the exchange lends currency to you in an amount equal to the chosen leverage. You pay the amount lent to you back to the exchange with interest, and your profits/losses are multiplied by the leverage specified.

    "},{"location":"leverage/#futures","title":"Futures","text":"

    Perpetual swaps (also known as Perpetual Futures) are contracts traded at a price that is closely tied to the underlying asset they are based off of (ex.). You are not trading the actual asset but instead are trading a derivative contract. Perpetual swap contracts can last indefinitely, in contrast to futures or option contracts.

    In addition to the gains/losses from the change in price of the futures contract, traders also exchange funding fees, which are gains/losses worth an amount that is derived from the difference in price between the futures contract and the underlying asset. The difference in price between a futures contract and the underlying asset varies between exchanges.

    To trade in futures markets, you'll have to set trading_mode to \"futures\". You will also have to pick a \"margin mode\" (explanation below) - with freqtrade currently only supporting isolated margin.

    \"trading_mode\": \"futures\",\n\"margin_mode\": \"isolated\"\n
    "},{"location":"leverage/#pair-namings","title":"Pair namings","text":"

    Freqtrade follows the ccxt naming conventions for futures. A futures pair will therefore have the naming of base/quote:settle (e.g. ETH/USDT:USDT).

    "},{"location":"leverage/#margin-mode","title":"Margin mode","text":"

    On top of trading_mode - you will also have to configure your margin_mode. While freqtrade currently only supports one margin mode, this will change, and by configuring it now you're all set for future updates.

    The possible values are: isolated, or cross(currently unavailable).

    "},{"location":"leverage/#isolated-margin-mode","title":"Isolated margin mode","text":"

    Each market(trading pair), keeps collateral in a separate account

    \"margin_mode\": \"isolated\"\n
    "},{"location":"leverage/#cross-margin-mode-currently-unavailable","title":"Cross margin mode (currently unavailable)","text":"

    One account is used to share collateral between markets (trading pairs). Margin is taken from total account balance to avoid liquidation when needed.

    \"margin_mode\": \"cross\"\n

    Please read the exchange specific notes for exchanges that support this mode and how they differ.

    "},{"location":"leverage/#set-leverage-to-use","title":"Set leverage to use","text":"

    Different strategies and risk profiles will require different levels of leverage. While you could configure one static leverage value - freqtrade offers you the flexibility to adjust this via strategy leverage callback - which allows you to use different leverages by pair, or based on some other factor benefitting your strategy result.

    If not implemented, leverage defaults to 1x (no leverage).

    Warning

    Higher leverage also equals higher risk - be sure you fully understand the implications of using leverage!

    "},{"location":"leverage/#understand-liquidation_buffer","title":"Understand liquidation_buffer","text":"

    Defaults to 0.05

    A ratio specifying how large of a safety net to place between the liquidation price and the stoploss to prevent a position from reaching the liquidation price. This artificial liquidation price is calculated as:

    freqtrade_liquidation_price = liquidation_price \u00b1 (abs(open_rate - liquidation_price) * liquidation_buffer)

    • \u00b1 = + for long trades
    • \u00b1 = - for short trades

    Possible values are any floats between 0.0 and 0.99

    ex: If a trade is entered at a price of 10 coin/USDT, and the liquidation price of this trade is 8 coin/USDT, then with liquidation_buffer set to 0.05 the minimum stoploss for this trade would be \\(8 + ((10 - 8) * 0.05) = 8 + 0.1 = 8.1\\)

    A liquidation_buffer of 0.0, or a low liquidation_buffer is likely to result in liquidations, and liquidation fees

    Currently Freqtrade is able to calculate liquidation prices, but does not calculate liquidation fees. Setting your liquidation_buffer to 0.0, or using a low liquidation_buffer could result in your positions being liquidated. Freqtrade does not track liquidation fees, so liquidations will result in inaccurate profit/loss results for your bot. If you use a low liquidation_buffer, it is recommended to use stoploss_on_exchange if your exchange supports this.

    "},{"location":"leverage/#unavailable-funding-rates","title":"Unavailable funding rates","text":"

    For futures data, exchanges commonly provide the futures candles, the marks, and the funding rates. However, it is common that whilst candles and marks might be available, the funding rates are not. This can affect backtesting timeranges, i.e. you may only be able to test recent timeranges and not earlier, experiencing the No data found. Terminating. error. To get around this, add the futures_funding_rate config option as listed in configuration.md, and it is recommended that you set this to 0, unless you know a given specific funding rate for your pair, exchange and timerange. Setting this to anything other than 0 can have drastic effects on your profit calculations within strategy, e.g. within the custom_exit, custom_stoploss, etc functions.

    This will mean your backtests are inaccurate.

    This will not overwrite funding rates that are available from the exchange, but bear in mind that setting a false funding rate will mean backtesting results will be inaccurate for historical timeranges where funding rates are not available.

    "},{"location":"leverage/#developer","title":"Developer","text":""},{"location":"leverage/#margin-mode_1","title":"Margin mode","text":"

    For shorts, the currency which pays the interest fee for the borrowed currency is purchased at the same time of the closing trade (This means that the amount purchased in short closing trades is greater than the amount sold in short opening trades).

    For longs, the currency which pays the interest fee for the borrowed will already be owned by the user and does not need to be purchased. The interest is subtracted from the close_value of the trade.

    All Fees are included in current_profit calculations during the trade.

    "},{"location":"leverage/#futures-mode","title":"Futures mode","text":"

    Funding fees are either added or subtracted from the total amount of a trade

    "},{"location":"lookahead-analysis/","title":"Lookahead analysis","text":"

    This page explains how to validate your strategy in terms of look ahead bias.

    Checking look ahead bias is the bane of any strategy since it is sometimes very easy to introduce backtest bias - but very hard to detect.

    Backtesting initializes all timestamps at once and calculates all indicators in the beginning. This means that if your indicators or entry/exit signals could look into future candles and falsify your backtest.

    Lookahead-analysis requires historic data to be available. To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    This command is built upon backtesting since it internally chains backtests and pokes at the strategy to provoke it to show look ahead bias. This is done by not looking at the strategy itself - but at the results it returned. The results are things like changed indicator-values and moved entries/exits compared to the full backtest.

    You can use commands of Backtesting. It also supports the lookahead-analysis of freqai strategies.

    • --cache is forced to \"none\".
    • --max-open-trades is forced to be at least equal to the number of pairs.
    • --dry-run-wallet is forced to be basically infinite (1 billion).
    • --stake-amount is forced to be a static 10000 (10k).
    • --enable-protections is forced to be off.

    Those are set to avoid users accidentally generating false positives.

    "},{"location":"lookahead-analysis/#lookahead-analysis-command-reference","title":"Lookahead-analysis command reference","text":"
    usage: freqtrade lookahead-analysis [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                    [-d PATH] [--userdir PATH] [-s NAME]\n                                    [--strategy-path PATH]\n                                    [--recursive-strategy-search]\n                                    [--freqaimodel NAME]\n                                    [--freqaimodel-path PATH] [-i TIMEFRAME]\n                                    [--timerange TIMERANGE]\n                                    [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                                    [--max-open-trades INT]\n                                    [--stake-amount STAKE_AMOUNT]\n                                    [--fee FLOAT] [-p PAIRS [PAIRS ...]]\n                                    [--dry-run-wallet DRY_RUN_WALLET]\n                                    [--timeframe-detail TIMEFRAME_DETAIL]\n                                    [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]\n                                    [--export {none,trades,signals}]\n                                    [--export-filename PATH]\n                                    [--breakdown {day,week,month} [{day,week,month} ...]]\n                                    [--cache {none,day,week,month}]\n                                    [--freqai-backtest-live-models]\n                                    [--minimum-trade-amount INT]\n                                    [--targeted-trade-amount INT]\n                                    [--lookahead-analysis-exportfilename LOOKAHEAD_ANALYSIS_EXPORTFILENAME]\n\noptions:\n  --minimum-trade-amount INT\n                        Minimum trade amount for lookahead-analysis\n  --targeted-trade-amount INT\n                        Targeted trade amount for lookahead analysis\n  --lookahead-analysis-exportfilename LOOKAHEAD_ANALYSIS_EXPORTFILENAME\n                        Use this csv-filename to store lookahead-analysis-\n                        results\n

    The above Output was reduced to options lookahead-analysis adds on top of regular backtesting commands.

    "},{"location":"lookahead-analysis/#summary","title":"Summary","text":"

    Checks a given strategy for look ahead bias via lookahead-analysis Look ahead bias means that the backtest uses data from future candles thereby not making it viable beyond backtesting and producing false hopes for the one backtesting.

    "},{"location":"lookahead-analysis/#introduction","title":"Introduction","text":"

    Many strategies - without the programmer knowing - have fallen prey to look ahead bias.

    Any backtest will populate the full dataframe including all time stamps at the beginning. If the programmer is not careful or oblivious how things work internally (which sometimes can be really hard to find out) then it will just look into the future making the strategy amazing but not realistic.

    This command is made to try to verify the validity in the form of the aforementioned look ahead bias.

    "},{"location":"lookahead-analysis/#how-does-the-command-work","title":"How does the command work?","text":"

    It will start with a backtest of all pairs to generate a baseline for indicators and entries/exits. After the backtest ran, it will look if the minimum-trade-amount is met and if not cancel the lookahead-analysis for this strategy.

    After setting the baseline it will then do additional runs for every entry and exit separately. When a verification-backtest is done, it will compare the indicators as the signal (either entry or exit) and report the bias. After all signals have been verified or falsified a result-table will be generated for the user to see.

    "},{"location":"lookahead-analysis/#caveats","title":"Caveats","text":"
    • lookahead-analysis can only verify / falsify the trades it calculated and verified. If the strategy has many different signals / signal types, it's up to you to select appropriate parameters to ensure that all signals have triggered at least once. Not triggered signals will not have been verified. This could lead to a false-negative (the strategy will then be reported as non-biased).
    • lookahead-analysis has access to everything that backtesting has too. Please don't provoke any configs like enabling position stacking. If you decide to do so, then make doubly sure that you won't ever run out of max_open_trades amount and neither leftover money in your wallet.
    "},{"location":"plotting/","title":"Plotting","text":"

    This page explains how to plot prices, indicators and profits.

    Deprecated

    The commands described in this page (plot-dataframe, plot-profit) should be considered deprecated and are in maintenance mode. This is mostly for the performance problems even medium sized plots can cause, but also because \"store a file and open it in a browser\" isn't very intuitive from a UI perspective.

    While there are no immediate plans to remove them, they are not actively maintained - and may be removed short-term should major changes be required to keep them working.

    Please use FreqUI for plotting needs, which doesn't struggle with the same performance problems.

    "},{"location":"plotting/#installation-setup","title":"Installation / Setup","text":"

    Plotting modules use the Plotly library. You can install / upgrade this by running the following command:

    pip install -U -r requirements-plot.txt\n
    "},{"location":"plotting/#plot-price-and-indicators","title":"Plot price and indicators","text":"

    The freqtrade plot-dataframe subcommand shows an interactive graph with three subplots:

    • Main plot with candlesticks and indicators following price (sma/ema)
    • Volume bars
    • Additional indicators as specified by --indicators2

    Possible arguments:

    usage: freqtrade plot-dataframe [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                [-d PATH] [--userdir PATH] [-s NAME]\n                                [--strategy-path PATH] [-p PAIRS [PAIRS ...]]\n                                [--indicators1 INDICATORS1 [INDICATORS1 ...]]\n                                [--indicators2 INDICATORS2 [INDICATORS2 ...]]\n                                [--plot-limit INT] [--db-url PATH]\n                                [--trade-source {DB,file}] [--export EXPORT]\n                                [--export-filename PATH]\n                                [--timerange TIMERANGE] [-i TIMEFRAME]\n                                [--no-trades]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --indicators1 INDICATORS1 [INDICATORS1 ...]\n                        Set indicators from your strategy you want in the\n                        first row of the graph. Space-separated list. Example:\n                        `ema3 ema5`. Default: `['sma', 'ema3', 'ema5']`.\n  --indicators2 INDICATORS2 [INDICATORS2 ...]\n                        Set indicators from your strategy you want in the\n                        third row of the graph. Space-separated list. Example:\n                        `fastd fastk`. Default: `['macd', 'macdsignal']`.\n  --plot-limit INT      Specify tick limit for plotting. Notice: too high\n                        values cause huge files. Default: 750.\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --trade-source {DB,file}\n                        Specify the source for trades (Can be DB or file\n                        (backtest file)) Default: file\n  --export EXPORT       Export backtest results, argument are: trades.\n                        Example: `--export=trades`\n  --export-filename PATH\n                        Save backtest results to the file with this filename.\n                        Requires `--export` to be set as well. Example:\n                        `--export-filename=user_data/backtest_results/backtest\n                        _today.json`\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --no-trades           Skip using trades from backtesting file and DB.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n

    Example:

    freqtrade plot-dataframe -p BTC/ETH --strategy AwesomeStrategy\n

    The -p/--pairs argument can be used to specify pairs you would like to plot.

    Note

    The freqtrade plot-dataframe subcommand generates one plot-file per pair.

    Specify custom indicators. Use --indicators1 for the main plot and --indicators2 for the subplot below (if values are in a different range than prices).

    freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --indicators1 sma ema --indicators2 macd\n
    "},{"location":"plotting/#further-usage-examples","title":"Further usage examples","text":"

    To plot multiple pairs, separate them with a space:

    freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH XRP/ETH\n

    To plot a timerange (to zoom in)

    freqtrade plot-dataframe --strategy AwesomeStrategy -p BTC/ETH --timerange=20180801-20180805\n

    To plot trades stored in a database use --db-url in combination with --trade-source DB:

    freqtrade plot-dataframe --strategy AwesomeStrategy --db-url sqlite:///tradesv3.dry_run.sqlite -p BTC/ETH --trade-source DB\n

    To plot trades from a backtesting result, use --export-filename <filename>

    freqtrade plot-dataframe --strategy AwesomeStrategy --export-filename user_data/backtest_results/backtest-result.json -p BTC/ETH\n
    "},{"location":"plotting/#plot-dataframe-basics","title":"Plot dataframe basics","text":"

    The plot-dataframe subcommand requires backtesting data, a strategy and either a backtesting-results file or a database, containing trades corresponding to the strategy.

    The resulting plot will have the following elements:

    • Green triangles: Buy signals from the strategy. (Note: not every buy signal generates a trade, compare to cyan circles.)
    • Red triangles: Sell signals from the strategy. (Also, not every sell signal terminates a trade, compare to red and green squares.)
    • Cyan circles: Trade entry points.
    • Red squares: Trade exit points for trades with loss or 0% profit.
    • Green squares: Trade exit points for profitable trades.
    • Indicators with values corresponding to the candle scale (e.g. SMA/EMA), as specified with --indicators1.
    • Volume (bar chart at the bottom of the main chart).
    • Indicators with values in different scales (e.g. MACD, RSI) below the volume bars, as specified with --indicators2.

    Bollinger Bands

    Bollinger bands are automatically added to the plot if the columns bb_lowerband and bb_upperband exist, and are painted as a light blue area spanning from the lower band to the upper band.

    "},{"location":"plotting/#advanced-plot-configuration","title":"Advanced plot configuration","text":"

    An advanced plot configuration can be specified in the strategy in the plot_config parameter.

    Additional features when using plot_config include:

    • Specify colors per indicator
    • Specify additional subplots
    • Specify indicator pairs to fill area in between

    The sample plot configuration below specifies fixed colors for the indicators. Otherwise, consecutive plots may produce different color schemes each time, making comparisons difficult. It also allows multiple subplots to display both MACD and RSI at the same time.

    Plot type can be configured using type key. Possible types are:

    • scatter corresponding to plotly.graph_objects.Scatter class (default).
    • bar corresponding to plotly.graph_objects.Bar class.

    Extra parameters to plotly.graph_objects.* constructor can be specified in plotly dict.

    Sample configuration with inline comments explaining the process:

    @property\ndef plot_config(self):\n    \"\"\"\n        There are a lot of solutions how to build the return dictionary.\n        The only important point is the return value.\n        Example:\n            plot_config = {'main_plot': {}, 'subplots': {}}\n\n    \"\"\"\n    plot_config = {}\n    plot_config['main_plot'] = {\n        # Configuration for main plot indicators.\n        # Assumes 2 parameters, emashort and emalong to be specified.\n        f'ema_{self.emashort.value}': {'color': 'red'},\n        f'ema_{self.emalong.value}': {'color': '#CCCCCC'},\n        # By omitting color, a random color is selected.\n        'sar': {},\n        # fill area between senkou_a and senkou_b\n        'senkou_a': {\n            'color': 'green', #optional\n            'fill_to': 'senkou_b',\n            'fill_label': 'Ichimoku Cloud', #optional\n            'fill_color': 'rgba(255,76,46,0.2)', #optional\n        },\n        # plot senkou_b, too. Not only the area to it.\n        'senkou_b': {}\n    }\n    plot_config['subplots'] = {\n         # Create subplot MACD\n        \"MACD\": {\n            'macd': {'color': 'blue', 'fill_to': 'macdhist'},\n            'macdsignal': {'color': 'orange'},\n            'macdhist': {'type': 'bar', 'plotly': {'opacity': 0.9}}\n        },\n        # Additional subplot RSI\n        \"RSI\": {\n            'rsi': {'color': 'red'}\n        }\n    }\n\n    return plot_config\n
    As attribute (former method)

    Assigning plot_config is also possible as Attribute (this used to be the default way). This has the disadvantage that strategy parameters are not available, preventing certain configurations from working.

        plot_config = {\n        'main_plot': {\n            # Configuration for main plot indicators.\n            # Specifies `ema10` to be red, and `ema50` to be a shade of gray\n            'ema10': {'color': 'red'},\n            'ema50': {'color': '#CCCCCC'},\n            # By omitting color, a random color is selected.\n            'sar': {},\n        # fill area between senkou_a and senkou_b\n        'senkou_a': {\n            'color': 'green', #optional\n            'fill_to': 'senkou_b',\n            'fill_label': 'Ichimoku Cloud', #optional\n            'fill_color': 'rgba(255,76,46,0.2)', #optional\n        },\n        # plot senkou_b, too. Not only the area to it.\n        'senkou_b': {}\n        },\n        'subplots': {\n            # Create subplot MACD\n            \"MACD\": {\n                'macd': {'color': 'blue', 'fill_to': 'macdhist'},\n                'macdsignal': {'color': 'orange'},\n                'macdhist': {'type': 'bar', 'plotly': {'opacity': 0.9}}\n            },\n            # Additional subplot RSI\n            \"RSI\": {\n                'rsi': {'color': 'red'}\n            }\n        }\n    }\n

    Note

    The above configuration assumes that ema10, ema50, senkou_a, senkou_b, macd, macdsignal, macdhist and rsi are columns in the DataFrame created by the strategy.

    Warning

    plotly arguments are only supported with plotly library and will not work with freq-ui.

    Trade position adjustments

    If position_adjustment_enable / adjust_trade_position() is used, the trade initial buy price is averaged over multiple orders and the trade start price will most likely appear outside the candle range.

    "},{"location":"plotting/#plot-profit","title":"Plot profit","text":"

    The plot-profit subcommand shows an interactive graph with three plots:

    • Average closing price for all pairs.
    • The summarized profit made by backtesting. Note that this is not the real-world profit, but more of an estimate.
    • Profit for each individual pair.
    • Parallelism of trades.
    • Underwater (Periods of drawdown).

    The first graph is good to get a grip of how the overall market progresses.

    The second graph will show if your algorithm works or doesn't. Perhaps you want an algorithm that steadily makes small profits, or one that acts less often, but makes big swings. This graph will also highlight the start (and end) of the Max drawdown period.

    The third graph can be useful to spot outliers, events in pairs that cause profit spikes.

    The forth graph can help you analyze trade parallelism, showing how often max_open_trades have been maxed out.

    Possible options for the freqtrade plot-profit subcommand:

    usage: freqtrade plot-profit [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                             [-d PATH] [--userdir PATH] [-s NAME]\n                             [--strategy-path PATH] [-p PAIRS [PAIRS ...]]\n                             [--timerange TIMERANGE] [--export EXPORT]\n                             [--export-filename PATH] [--db-url PATH]\n                             [--trade-source {DB,file}] [-i TIMEFRAME]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -p PAIRS [PAIRS ...], --pairs PAIRS [PAIRS ...]\n                        Limit command to these pairs. Pairs are space-\n                        separated.\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n  --export EXPORT       Export backtest results, argument are: trades.\n                        Example: `--export=trades`\n  --export-filename PATH, --backtest-filename PATH\n                        Use backtest results from this filename.\n                        Requires `--export` to be set as well. Example:\n                        `--export-filename=user_data/backtest_results/backtest\n                        _today.json`\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --trade-source {DB,file}\n                        Specify the source for trades (Can be DB or file\n                        (backtest file)) Default: file\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --auto-open           Automatically open generated plot.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n

    The -p/--pairs argument, can be used to limit the pairs that are considered for this calculation.

    Examples:

    Use custom backtest-export file

    freqtrade plot-profit  -p LTC/BTC --export-filename user_data/backtest_results/backtest-result.json\n

    Use custom database

    freqtrade plot-profit  -p LTC/BTC --db-url sqlite:///tradesv3.sqlite --trade-source DB\n
    freqtrade --datadir user_data/data/binance_save/ plot-profit -p LTC/BTC\n
    "},{"location":"plugins/","title":"Plugins","text":""},{"location":"plugins/#pairlists-and-pairlist-handlers","title":"Pairlists and Pairlist Handlers","text":"

    Pairlist Handlers define the list of pairs (pairlist) that the bot should trade. They are configured in the pairlists section of the configuration settings.

    In your configuration, you can use Static Pairlist (defined by the StaticPairList Pairlist Handler) and Dynamic Pairlist (defined by the VolumePairList and PercentChangePairList Pairlist Handlers).

    Additionally, AgeFilter, PrecisionFilter, PriceFilter, ShuffleFilter, SpreadFilter and VolatilityFilter act as Pairlist Filters, removing certain pairs and/or moving their positions in the pairlist.

    If multiple Pairlist Handlers are used, they are chained and a combination of all Pairlist Handlers forms the resulting pairlist the bot uses for trading and backtesting. Pairlist Handlers are executed in the sequence they are configured. You can define either StaticPairList, VolumePairList, ProducerPairList, RemotePairList, MarketCapPairList or PercentChangePairList as the starting Pairlist Handler.

    Inactive markets are always removed from the resulting pairlist. Explicitly blacklisted pairs (those in the pair_blacklist configuration setting) are also always removed from the resulting pairlist.

    "},{"location":"plugins/#pair-blacklist","title":"Pair blacklist","text":"

    The pair blacklist (configured via exchange.pair_blacklist in the configuration) disallows certain pairs from trading. This can be as simple as excluding DOGE/BTC - which will remove exactly this pair.

    The pair-blacklist does also support wildcards (in regex-style) - so BNB/.* will exclude ALL pairs that start with BNB. You may also use something like .*DOWN/BTC or .*UP/BTC to exclude leveraged tokens (check Pair naming conventions for your exchange!)

    "},{"location":"plugins/#available-pairlist-handlers","title":"Available Pairlist Handlers","text":"
    • StaticPairList (default, if not configured differently)
    • VolumePairList
    • PercentChangePairList
    • ProducerPairList
    • RemotePairList
    • MarketCapPairList
    • AgeFilter
    • FullTradesFilter
    • OffsetFilter
    • PerformanceFilter
    • PrecisionFilter
    • PriceFilter
    • ShuffleFilter
    • SpreadFilter
    • RangeStabilityFilter
    • VolatilityFilter

    Testing pairlists

    Pairlist configurations can be quite tricky to get right. Best use the test-pairlist utility sub-command to test your configuration quickly.

    "},{"location":"plugins/#static-pair-list","title":"Static Pair List","text":"

    By default, the StaticPairList method is used, which uses a statically defined pair whitelist from the configuration. The pairlist also supports wildcards (in regex-style) - so .*/BTC will include all pairs with BTC as a stake.

    It uses configuration from exchange.pair_whitelist and exchange.pair_blacklist.

    \"pairlists\": [\n    {\"method\": \"StaticPairList\"}\n],\n

    By default, only currently enabled pairs are allowed. To skip pair validation against active markets, set \"allow_inactive\": true within the StaticPairList configuration. This can be useful for backtesting expired pairs (like quarterly spot-markets). This option must be configured along with exchange.skip_pair_validation in the exchange configuration.

    When used in a \"follow-up\" position (e.g. after VolumePairlist), all pairs in 'pair_whitelist' will be added to the end of the pairlist.

    "},{"location":"plugins/#volume-pair-list","title":"Volume Pair List","text":"

    VolumePairList employs sorting/filtering of pairs by their trading volume. It selects number_assets top pairs with sorting based on the sort_key (which can only be quoteVolume).

    When used in the chain of Pairlist Handlers in a non-leading position (after StaticPairList and other Pairlist Filters), VolumePairList considers outputs of previous Pairlist Handlers, adding its sorting/selection of the pairs by the trading volume.

    When used in the leading position of the chain of Pairlist Handlers, the pair_whitelist configuration setting is ignored. Instead, VolumePairList selects the top assets from all available markets with matching stake-currency on the exchange.

    The refresh_period setting allows to define the period (in seconds), at which the pairlist will be refreshed. Defaults to 1800s (30 minutes). The pairlist cache (refresh_period) on VolumePairList is only applicable to generating pairlists. Filtering instances (not the first position in the list) will not apply any cache (beyond caching candles for the duration of the candle in advanced mode) and will always use up-to-date data.

    VolumePairList is per default based on the ticker data from exchange, as reported by the ccxt library:

    • The quoteVolume is the amount of quote (stake) currency traded (bought or sold) in last 24 hours.
    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"max_value\": 8000000,\n        \"refresh_period\": 1800\n    }\n],\n

    You can define a minimum volume with min_value - which will filter out pairs with a volume lower than the specified value in the specified timerange. In addition to that, you can also define a maximum volume with max_value - which will filter out pairs with a volume higher than the specified value in the specified timerange.

    "},{"location":"plugins/#volumepairlist-advanced-mode","title":"VolumePairList Advanced mode","text":"

    VolumePairList can also operate in an advanced mode to build volume over a given timerange of specified candle size. It utilizes exchange historical candle data, builds a typical price (calculated by (open+high+low)/3) and multiplies the typical price with every candle's volume. The sum is the quoteVolume over the given range. This allows different scenarios, for a more smoothened volume, when using longer ranges with larger candle sizes, or the opposite when using a short range with small candles.

    For convenience lookback_days can be specified, which will imply that 1d candles will be used for the lookback. In the example below the pairlist would be created based on the last 7 days:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 7\n    }\n],\n

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range based volume can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with VolumeFilter to narrow the pairlist down for further range volume calculation.

    Unsupported exchanges

    On some exchanges (like Gemini), regular VolumePairList does not work as the api does not natively provide 24h volume. This can be worked around by using candle data to build the volume. To roughly simulate 24h volume, you can use the following configuration. Please note that These pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    More sophisticated approach can be used, by using lookback_timeframe for candle size and lookback_period which specifies the amount of candles. This example will build the volume pairs based on a rolling period of 3 days of 1h candles:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    Note

    VolumePairList does not support backtesting mode.

    "},{"location":"plugins/#percent-change-pair-list","title":"Percent Change Pair List","text":"

    PercentChangePairList filters and sorts pairs based on the percentage change in their price over the last 24 hours or any defined timeframe as part of advanced options. This allows traders to focus on assets that have experienced significant price movements, either positive or negative.

    Configuration Options

    • number_assets: Specifies the number of top pairs to select based on the 24-hour percentage change.
    • min_value: Sets a minimum percentage change threshold. Pairs with a percentage change below this value will be filtered out.
    • max_value: Sets a maximum percentage change threshold. Pairs with a percentage change above this value will be filtered out.
    • sort_direction: Specifies the order in which pairs are sorted based on their percentage change. Accepts two values: asc for ascending order and desc for descending order.
    • refresh_period: Defines the interval (in seconds) at which the pairlist will be refreshed. The default is 1800 seconds (30 minutes).
    • lookback_days: Number of days to look back. When lookback_days is selected, the lookback_timeframe is defaulted to 1 day.
    • lookback_timeframe: Timeframe to use for the lookback period.
    • lookback_period: Number of periods to look back at.

    When PercentChangePairList is used after other Pairlist Handlers, it will operate on the outputs of those handlers. If it is the leading Pairlist Handler, it will select pairs from all available markets with the specified stake currency.

    PercentChangePairList uses ticker data from the exchange, provided via the ccxt library: The percentage change is calculated as the change in price over the last 24 hours.

    Unsupported exchanges

    On some exchanges (like HTX), regular PercentChangePairList does not work as the api does not natively provide 24h percent change in price. This can be worked around by using candle data to calculate the percentage change. To roughly simulate 24h percent change, you can use the following configuration. Please note that these pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 20,\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    Example Configuration to Read from Ticker

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"min_value\": -10,\n        \"max_value\": 50\n    }\n],\n

    In this configuration:

    1. The top 15 pairs are selected based on the highest percentage change in price over the last 24 hours.
    2. Only pairs with a percentage change between -10% and 50% are considered.

    Example Configuration to Read from Candles

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"sort_key\": \"percentage\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    This example builds the percent change pairs based on a rolling period of 3 days of 1-hour candles by using lookback_timeframe for candle size and lookback_period which specifies the number of candles.

    The percent change in price is calculated using the following formula, which expresses the percentage difference between the current candle's close price and the previous candle's close price, as defined by the specified timeframe and lookback period:

    \\[ Percent Change = (\\frac{Current Close - Previous Close}{Previous Close}) * 100 \\]

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range-based percent change can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with PercentChangePairList to narrow the pairlist down for further percent-change calculation.

    Backtesting

    PercentChangePairList does not support backtesting mode.

    "},{"location":"plugins/#producerpairlist","title":"ProducerPairList","text":"

    With ProducerPairList, you can reuse the pairlist from a Producer without explicitly defining the pairlist on each consumer.

    Consumer mode is required for this pairlist to work.

    The pairlist will perform a check on active pairs against the current exchange configuration to avoid attempting to trade on invalid markets.

    You can limit the length of the pairlist with the optional parameter number_assets. Using \"number_assets\"=0 or omitting this key will result in the reuse of all producer pairs valid for the current setup.

    \"pairlists\": [\n    {\n        \"method\": \"ProducerPairList\",\n        \"number_assets\": 5,\n        \"producer_name\": \"default\",\n    }\n],\n

    Combining pairlists

    This pairlist can be combined with all other pairlists and filters for further pairlist reduction, and can also act as an \"additional\" pairlist, on top of already defined pairs. ProducerPairList can also be used multiple times in sequence, combining the pairs from multiple producers. Obviously in complex such configurations, the Producer may not provide data for all pairs, so the strategy must be fit for this.

    "},{"location":"plugins/#remotepairlist","title":"RemotePairList","text":"

    It allows the user to fetch a pairlist from a remote server or a locally stored json file within the freqtrade directory, enabling dynamic updates and customization of the trading pairlist.

    The RemotePairList is defined in the pairlists section of the configuration settings. It uses the following configuration options:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"processing_mode\": \"filter\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"bearer_token\": \"my-bearer-token\",\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    The optional mode option specifies if the pairlist should be used as a blacklist or as a whitelist. The default value is \"whitelist\".

    The optional processing_mode option in the RemotePairList configuration determines how the retrieved pairlist is processed. It can have two values: \"filter\" or \"append\". The default value is \"filter\".

    In \"filter\" mode, the retrieved pairlist is used as a filter. Only the pairs present in both the original pairlist and the retrieved pairlist are included in the final pairlist. Other pairs are filtered out.

    In \"append\" mode, the retrieved pairlist is added to the original pairlist. All pairs from both lists are included in the final pairlist without any filtering.

    The pairlist_url option specifies the URL of the remote server where the pairlist is located, or the path to a local file (if file:/// is prepended). This allows the user to use either a remote server or a local file as the source for the pairlist.

    The save_to_file option, when provided with a valid filename, saves the processed pairlist to that file in JSON format. This option is optional, and by default, the pairlist is not saved to a file.

    Multi bot with shared pairlist example

    save_to_file can be used to save the pairlist to a file with Bot1:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    This saved pairlist file can be loaded by Bot2, or any additional bot with this configuration:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"file:///user_data/filename.json\",\n        \"number_assets\": 10,\n        \"refresh_period\": 10,\n        \"keep_pairlist_on_failure\": true,\n    }\n]\n

    The user is responsible for providing a server or local file that returns a JSON object with the following structure:

    {\n    \"pairs\": [\"XRP/USDT\", \"ETH/USDT\", \"LTC/USDT\"],\n    \"refresh_period\": 1800\n}\n

    The pairs property should contain a list of strings with the trading pairs to be used by the bot. The refresh_period property is optional and specifies the number of seconds that the pairlist should be cached before being refreshed.

    The optional keep_pairlist_on_failure specifies whether the previous received pairlist should be used if the remote server is not reachable or returns an error. The default value is true.

    The optional read_timeout specifies the maximum amount of time (in seconds) to wait for a response from the remote source, The default value is 60.

    The optional bearer_token will be included in the requests Authorization Header.

    Note

    In case of a server error the last received pairlist will be kept if keep_pairlist_on_failure is set to true, when set to false a empty pairlist is returned.

    "},{"location":"plugins/#marketcappairlist","title":"MarketCapPairList","text":"

    MarketCapPairList employs sorting/filtering of pairs by their marketcap rank based of CoinGecko. It will only recognize coins up to the coin placed at rank 250. The returned pairlist will be sorted based of their marketcap ranks.

    \"pairlists\": [\n    {\n        \"method\": \"MarketCapPairList\",\n        \"number_assets\": 20,\n        \"max_rank\": 50,\n        \"refresh_period\": 86400\n    }\n]\n

    number_assets defines the maximum number of pairs returned by the pairlist. max_rank will determine the maximum rank used in creating/filtering the pairlist. It's expected that some coins within the top max_rank marketcap will not be included in the resulting pairlist since not all pairs will have active trading pairs in your preferred market/stake/exchange combination.

    refresh_period setting defines the period (in seconds) at which the marketcap rank data will be refreshed. Defaults to 86,400s (1 day). The pairlist cache (refresh_period) is applicable on both generating pairlists (first position in the list) and filtering instances (not the first position in the list).

    "},{"location":"plugins/#agefilter","title":"AgeFilter","text":"

    Removes pairs that have been listed on the exchange for less than min_days_listed days (defaults to 10) or more than max_days_listed days (defaults None mean infinity).

    When pairs are first listed on an exchange they can suffer huge price drops and volatility in the first few days while the pair goes through its price-discovery period. Bots can often be caught out buying before the pair has finished dropping in price.

    This filter allows freqtrade to ignore pairs until they have been listed for at least min_days_listed days and listed before max_days_listed.

    "},{"location":"plugins/#fulltradesfilter","title":"FullTradesFilter","text":"

    Shrink whitelist to consist only in-trade pairs when the trade slots are full (when max_open_trades isn't being set to -1 in the config).

    When the trade slots are full, there is no need to calculate indicators of the rest of the pairs (except informative pairs) since no new trade can be opened. By shrinking the whitelist to just the in-trade pairs, you can improve calculation speeds and reduce CPU usage. When a trade slot is free (either a trade is closed or max_open_trades value in config is increased), then the whitelist will return to normal state.

    When multiple pairlist filters are being used, it's recommended to put this filter at second position directly below the primary pairlist, so when the trade slots are full, the bot doesn't have to download data for the rest of the filters.

    Backtesting

    FullTradesFilter does not support backtesting mode.

    "},{"location":"plugins/#offsetfilter","title":"OffsetFilter","text":"

    Offsets an incoming pairlist by a given offset value.

    As an example it can be used in conjunction with VolumeFilter to remove the top X volume pairs. Or to split a larger pairlist on two bot instances.

    Example to remove the first 10 pairs from the pairlist, and takes the next 20 (taking items 10-30 of the initial list):

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"OffsetFilter\",\n        \"offset\": 10,\n        \"number_assets\": 20\n    }\n],\n

    Warning

    When OffsetFilter is used to split a larger pairlist among multiple bots in combination with VolumeFilter it can not be guaranteed that pairs won't overlap due to slightly different refresh intervals for the VolumeFilter.

    Note

    An offset larger than the total length of the incoming pairlist will result in an empty pairlist.

    "},{"location":"plugins/#performancefilter","title":"PerformanceFilter","text":"

    Sorts pairs by past trade performance, as follows:

    1. Positive performance.
    2. No closed trades yet.
    3. Negative performance.

    Trade count is used as a tie breaker.

    You can use the minutes parameter to only consider performance of the past X minutes (rolling window). Not defining this parameter (or setting it to 0) will use all-time performance.

    The optional min_profit (as ratio -> a setting of 0.01 corresponds to 1%) parameter defines the minimum profit a pair must have to be considered. Pairs below this level will be filtered out. Using this parameter without minutes is highly discouraged, as it can lead to an empty pairlist without a way to recover.

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"PerformanceFilter\",\n        \"minutes\": 1440,  // rolling 24h\n        \"min_profit\": 0.01  // minimal profit 1%\n    }\n],\n

    As this Filter uses past performance of the bot, it'll have some startup-period - and should only be used after the bot has a few 100 trades in the database.

    Backtesting

    PerformanceFilter does not support backtesting mode.

    "},{"location":"plugins/#precisionfilter","title":"PrecisionFilter","text":"

    Filters low-value coins which would not allow setting stoplosses.

    Namely, pairs are blacklisted if a variance of one percent or more in the stop price would be caused by precision rounding on the exchange, i.e. rounded(stop_price) <= rounded(stop_price * 0.99). The idea is to avoid coins with a value VERY close to their lower trading boundary, not allowing setting of proper stoploss.

    PrecisionFilter is pointless for futures trading

    The above does not apply to shorts. And for longs, in theory the trade will be liquidated first.

    Backtesting

    PrecisionFilter does not support backtesting mode using multiple strategies.

    "},{"location":"plugins/#pricefilter","title":"PriceFilter","text":"

    The PriceFilter allows filtering of pairs by price. Currently the following price filters are supported:

    • min_price
    • max_price
    • max_value
    • low_price_ratio

    The min_price setting removes pairs where the price is below the specified price. This is useful if you wish to avoid trading very low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_price setting removes pairs where the price is above the specified price. This is useful if you wish to trade only low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_value setting removes pairs where the minimum value change is above a specified value. This is useful when an exchange has unbalanced limits. For example, if step-size = 1 (so you can only buy 1, or 2, or 3, but not 1.1 Coins) - and the price is pretty high (like 20$) as the coin has risen sharply since the last limit adaption. As a result of the above, you can only buy for 20$, or 40$ - but not for 25$. On exchanges that deduct fees from the receiving currency (e.g. binance) - this can result in high value coins / amounts that are unsellable as the amount is slightly below the limit.

    The low_price_ratio setting removes pairs where a raise of 1 price unit (pip) is above the low_price_ratio ratio. This option is disabled by default, and will only apply if set to > 0.

    For PriceFilter at least one of its min_price, max_price or low_price_ratio settings must be applied.

    Calculation example:

    Min price precision for SHITCOIN/BTC is 8 decimals. If its price is 0.00000011 - one price step above would be 0.00000012, which is ~9% higher than the previous price value. You may filter out this pair by using PriceFilter with low_price_ratio set to 0.09 (9%) or with min_price set to 0.00000011, correspondingly.

    Low priced pairs

    Low priced pairs with high \"1 pip movements\" are dangerous since they are often illiquid and it may also be impossible to place the desired stoploss, which can often result in high losses since price needs to be rounded to the next tradable price - so instead of having a stoploss of -5%, you could end up with a stoploss of -9% simply due to price rounding.

    "},{"location":"plugins/#shufflefilter","title":"ShuffleFilter","text":"

    Shuffles (randomizes) pairs in the pairlist. It can be used for preventing the bot from trading some of the pairs more frequently then others when you want all pairs be treated with the same priority.

    By default, ShuffleFilter will shuffle pairs once per candle. To shuffle on every iteration, set \"shuffle_frequency\" to \"iteration\" instead of the default of \"candle\".

        {\n        \"method\": \"ShuffleFilter\", \n        \"shuffle_frequency\": \"candle\",\n        \"seed\": 42\n    }\n

    Tip

    You may set the seed value for this Pairlist to obtain reproducible results, which can be useful for repeated backtesting sessions. If seed is not set, the pairs are shuffled in the non-repeatable random order. ShuffleFilter will automatically detect runmodes and apply the seed only for backtesting modes - if a seed value is set.

    "},{"location":"plugins/#spreadfilter","title":"SpreadFilter","text":"

    Removes pairs that have a difference between asks and bids above the specified ratio, max_spread_ratio (defaults to 0.005).

    Example:

    If DOGE/BTC maximum bid is 0.00000026 and minimum ask is 0.00000027, the ratio is calculated as: 1 - bid/ask ~= 0.037 which is > 0.005 and this pair will be filtered out.

    "},{"location":"plugins/#rangestabilityfilter","title":"RangeStabilityFilter","text":"

    Removes pairs where the difference between lowest low and highest high over lookback_days days is below min_rate_of_change or above max_rate_of_change. Since this is a filter that requires additional data, the results are cached for refresh_period.

    In the below example: If the trading range over the last 10 days is <1% or >99%, remove the pair from the whitelist.

    \"pairlists\": [\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"max_rate_of_change\": 0.99,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting for this pairlist.

    Tip

    This Filter can be used to automatically remove stable coin pairs, which have a very low trading range, and are therefore extremely difficult to trade with profit. Additionally, it can also be used to automatically remove pairs with extreme high/low variance over a given amount of time.

    "},{"location":"plugins/#volatilityfilter","title":"VolatilityFilter","text":"

    Volatility is the degree of historical variation of a pairs over time, it is measured by the standard deviation of logarithmic daily returns. Returns are assumed to be normally distributed, although actual distribution might be different. In a normal distribution, 68% of observations fall within one standard deviation and 95% of observations fall within two standard deviations. Assuming a volatility of 0.05 means that the expected returns for 20 out of 30 days is expected to be less than 5% (one standard deviation). Volatility is a positive ratio of the expected deviation of return and can be greater than 1.00. Please refer to the wikipedia definition of volatility.

    This filter removes pairs if the average volatility over a lookback_days days is below min_volatility or above max_volatility. Since this is a filter that requires additional data, the results are cached for refresh_period.

    This filter can be used to narrow down your pairs to a certain volatility or avoid very volatile pairs.

    In the below example: If the volatility over the last 10 days is not in the range of 0.05-0.50, remove the pair from the whitelist. The filter is applied every 24h.

    \"pairlists\": [\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting mode for this pairlist.

    "},{"location":"plugins/#full-example-of-pairlist-handlers","title":"Full example of Pairlist Handlers","text":"

    The below example blacklists BNB/BTC, uses VolumePairList with 20 assets, sorting pairs by quoteVolume and applies PrecisionFilter and PriceFilter, filtering all assets where 1 price unit is > 1%. Then the SpreadFilter and VolatilityFilter is applied and pairs are finally shuffled with the random seed set to some predefined value.

    \"exchange\": {\n    \"pair_whitelist\": [],\n    \"pair_blacklist\": [\"BNB/BTC\"]\n},\n\"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\"\n    },\n    {\"method\": \"AgeFilter\", \"min_days_listed\": 10},\n    {\"method\": \"PrecisionFilter\"},\n    {\"method\": \"PriceFilter\", \"low_price_ratio\": 0.01},\n    {\"method\": \"SpreadFilter\", \"max_spread_ratio\": 0.005},\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"refresh_period\": 86400\n    },\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    },\n    {\"method\": \"ShuffleFilter\", \"seed\": 42}\n],\n
    "},{"location":"plugins/#protections","title":"Protections","text":"

    Beta feature

    This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.

    Protections will protect your strategy from unexpected events and market conditions by temporarily stop trading for either one pair, or for all pairs. All protection end times are rounded up to the next candle to avoid sudden, unexpected intra-candle buys.

    Note

    Not all Protections will work for all strategies, and parameters will need to be tuned for your strategy to improve performance.

    Tip

    Each Protection can be configured multiple times with different parameters, to allow different levels of protection (short-term / long-term).

    Backtesting

    Protections are supported by backtesting and hyperopt, but must be explicitly enabled by using the --enable-protections flag.

    Setting protections from the configuration

    Setting protections from the configuration via \"protections\": [], key should be considered deprecated and will be removed in a future version. It is also no longer guaranteed that your protections apply to the strategy in cases where the strategy defines protections as property.

    "},{"location":"plugins/#available-protections","title":"Available Protections","text":"
    • StoplossGuard Stop trading if a certain amount of stoploss occurred within a certain time window.
    • MaxDrawdown Stop trading if max-drawdown is reached.
    • LowProfitPairs Lock pairs with low profits
    • CooldownPeriod Don't enter a trade right after selling a trade.
    "},{"location":"plugins/#common-settings-to-all-protections","title":"Common settings to all Protections","text":"Parameter Description method Protection name to use. Datatype: String, selected from available Protections stop_duration_candles For how many candles should the lock be set? Datatype: Positive integer (in candles) stop_duration how many minutes should protections be locked. Cannot be used together with stop_duration_candles. Datatype: Float (in minutes) lookback_period_candles Only trades that completed within the last lookback_period_candles candles will be considered. This setting may be ignored by some Protections. Datatype: Positive integer (in candles). lookback_period Only trades that completed after current_time - lookback_period will be considered. Cannot be used together with lookback_period_candles. This setting may be ignored by some Protections. Datatype: Float (in minutes) trade_limit Number of trades required at minimum (not used by all Protections). Datatype: Positive integer unlock_at Time when trading will be unlocked regularly (not used by all Protections). Datatype: string Input Format: \"HH:MM\" (24-hours)

    Durations

    Durations (stop_duration* and lookback_period* can be defined in either minutes or candles). For more flexibility when testing different timeframes, all below examples will use the \"candle\" definition.

    "},{"location":"plugins/#stoploss-guard","title":"Stoploss Guard","text":"

    StoplossGuard selects all trades within lookback_period in minutes (or in candles when using lookback_period_candles). If trade_limit or more trades resulted in stoploss, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    This applies across all pairs, unless only_per_pair is set to true, which will then only look at one pair at a time.

    Similarly, this protection will by default look at all trades (long and short). For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long stoplosses.

    required_profit will determine the required relative profit (or loss) for stoplosses to consider. This should normally not be set and defaults to 0.0 - which means all losing stoplosses will be triggering a block.

    The below example stops trading for all pairs for 4 candles after the last trade if the bot hit stoploss 4 times within the last 24 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"StoplossGuard\",\n            \"lookback_period_candles\": 24,\n            \"trade_limit\": 4,\n            \"stop_duration_candles\": 4,\n            \"required_profit\": 0.0,\n            \"only_per_pair\": False,\n            \"only_per_side\": False\n        }\n    ]\n

    Note

    StoplossGuard considers all trades with the results \"stop_loss\", \"stoploss_on_exchange\" and \"trailing_stop_loss\" if the resulting profit was negative. trade_limit and lookback_period will need to be tuned for your strategy.

    "},{"location":"plugins/#maxdrawdown","title":"MaxDrawdown","text":"

    MaxDrawdown uses all trades within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the maximum drawdown. If the drawdown is below max_allowed_drawdown, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles) after the last trade - assuming that the bot needs some time to let markets recover.

    The below sample stops trading for 12 candles if max-drawdown is > 20% considering all pairs - with a minimum of trade_limit trades - within the last 48 candles. If desired, lookback_period and/or stop_duration can be used.

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"MaxDrawdown\",\n            \"lookback_period_candles\": 48,\n            \"trade_limit\": 20,\n            \"stop_duration_candles\": 12,\n            \"max_allowed_drawdown\": 0.2\n        },\n    ]\n
    "},{"location":"plugins/#low-profit-pairs","title":"Low Profit Pairs","text":"

    LowProfitPairs uses all trades for a pair within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the overall profit ratio. If that ratio is below required_profit, that pair will be locked for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long losses.

    The below example will stop trading a pair for 60 minutes if the pair does not have a required profit of 2% (and a minimum of 2 trades) within the last 6 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"LowProfitPairs\",\n            \"lookback_period_candles\": 6,\n            \"trade_limit\": 2,\n            \"stop_duration\": 60,\n            \"required_profit\": 0.02,\n            \"only_per_pair\": False,\n        }\n    ]\n
    "},{"location":"plugins/#cooldown-period","title":"Cooldown Period","text":"

    CooldownPeriod locks a pair for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at) after exiting, avoiding a re-entry for this pair for stop_duration minutes.

    The below example will stop trading a pair for 2 candles after closing a trade, allowing this pair to \"cool down\".

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": 2\n        }\n    ]\n

    Note

    This Protection applies only at pair-level, and will never lock all pairs globally. This Protection does not consider lookback_period as it only looks at the latest trade.

    "},{"location":"plugins/#full-example-of-protections","title":"Full example of Protections","text":"

    All protections can be combined at will, also with different parameters, creating a increasing wall for under-performing pairs. All protections are evaluated in the sequence they are defined.

    The below example assumes a timeframe of 1 hour:

    • Locks each pair after selling for an additional 5 candles (CooldownPeriod), giving other pairs a chance to get filled.
    • Stops trading for 4 hours (4 * 1h candles) if the last 2 days (48 * 1h candles) had 20 trades, which caused a max-drawdown of more than 20%. (MaxDrawdown).
    • Stops trading if more than 4 stoploss occur for all pairs within a 1 day (24 * 1h candles) limit (StoplossGuard).
    • Locks all pairs that had 2 Trades within the last 6 hours (6 * 1h candles) with a combined profit ratio of below 0.02 (<2%) (LowProfitPairs).
    • Locks all pairs for 2 candles that had a profit of below 0.01 (<1%) within the last 24h (24 * 1h candles), a minimum of 4 trades.
    from freqtrade.strategy import IStrategy\n\nclass AwesomeStrategy(IStrategy)\n    timeframe = '1h'\n\n    @property\n    def protections(self):\n        return [\n            {\n                \"method\": \"CooldownPeriod\",\n                \"stop_duration_candles\": 5\n            },\n            {\n                \"method\": \"MaxDrawdown\",\n                \"lookback_period_candles\": 48,\n                \"trade_limit\": 20,\n                \"stop_duration_candles\": 4,\n                \"max_allowed_drawdown\": 0.2\n            },\n            {\n                \"method\": \"StoplossGuard\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"only_per_pair\": False\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 6,\n                \"trade_limit\": 2,\n                \"stop_duration_candles\": 60,\n                \"required_profit\": 0.02\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"required_profit\": 0.01\n            }\n        ]\n    # ...\n
    "},{"location":"producer-consumer/","title":"Producer / Consumer mode","text":"

    freqtrade provides a mechanism whereby an instance (also called consumer) may listen to messages from an upstream freqtrade instance (also called producer) using the message websocket. Mainly, analyzed_df and whitelist messages. This allows the reuse of computed indicators (and signals) for pairs in multiple bots without needing to compute them multiple times.

    See Message Websocket in the Rest API docs for setting up the api_server configuration for your message websocket (this will be your producer).

    Note

    We strongly recommend to set ws_token to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"producer-consumer/#configuration","title":"Configuration","text":"

    Enable subscribing to an instance by adding the external_message_consumer section to the consumer's config file.

    {\n    //...\n   \"external_message_consumer\": {\n        \"enabled\": true,\n        \"producers\": [\n            {\n                \"name\": \"default\", // This can be any name you'd like, default is \"default\"\n                \"host\": \"127.0.0.1\", // The host from your producer's api_server config\n                \"port\": 8080, // The port from your producer's api_server config\n                \"secure\": false, // Use a secure websockets connection, default false\n                \"ws_token\": \"sercet_Ws_t0ken\" // The ws_token from your producer's api_server config\n            }\n        ],\n        // The following configurations are optional, and usually not required\n        // \"wait_timeout\": 300,\n        // \"ping_timeout\": 10,\n        // \"sleep_time\": 10,\n        // \"remove_entry_exit_signals\": false,\n        // \"message_size_limit\": 8\n    }\n    //...\n}\n
    Parameter Description enabled Required. Enable consumer mode. If set to false, all other settings in this section are ignored.Defaults to false. Datatype: boolean . producers Required. List of producers Datatype: Array. producers.name Required. Name of this producer. This name must be used in calls to get_producer_pairs() and get_producer_df() if more than one producer is used. Datatype: string producers.host Required. The hostname or IP address from your producer. Datatype: string producers.port Required. The port matching the above host.Defaults to 8080. Datatype: Integer producers.secure Optional. Use ssl in websockets connection. Default False. Datatype: string producers.ws_token Required. ws_token as configured on the producer. Datatype: string Optional settings wait_timeout Timeout until we ping again if no message is received. Defaults to 300. Datatype: Integer - in seconds. ping_timeout Ping timeout Defaults to 10. Datatype: Integer - in seconds. sleep_time Sleep time before retrying to connect.Defaults to 10. Datatype: Integer - in seconds. remove_entry_exit_signals Remove signal columns from the dataframe (set them to 0) on dataframe receipt.Defaults to false. Datatype: Boolean. message_size_limit Size limit per messageDefaults to 8. Datatype: Integer - Megabytes.

    Instead of (or as well as) calculating indicators in populate_indicators() the follower instance listens on the connection to a producer instance's messages (or multiple producer instances in advanced configurations) and requests the producer's most recently analyzed dataframes for each pair in the active whitelist.

    A consumer instance will then have a full copy of the analyzed dataframes without the need to calculate them itself.

    "},{"location":"producer-consumer/#examples","title":"Examples","text":""},{"location":"producer-consumer/#example-producer-strategy","title":"Example - Producer Strategy","text":"

    A simple strategy with multiple indicators. No special considerations are required in the strategy itself.

    class ProducerStrategy(IStrategy):\n    #...\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Calculate indicators in the standard freqtrade way which can then be broadcast to other instances\n        \"\"\"\n        dataframe['rsi'] = ta.RSI(dataframe)\n        bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)\n        dataframe['bb_lowerband'] = bollinger['lower']\n        dataframe['bb_middleband'] = bollinger['mid']\n        dataframe['bb_upperband'] = bollinger['upper']\n        dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Populates the entry signal for the given dataframe\n        \"\"\"\n        dataframe.loc[\n            (\n                (qtpylib.crossed_above(dataframe['rsi'], self.buy_rsi.value)) &\n                (dataframe['tema'] <= dataframe['bb_middleband']) &\n                (dataframe['tema'] > dataframe['tema'].shift(1)) &\n                (dataframe['volume'] > 0)\n            ),\n            'enter_long'] = 1\n\n        return dataframe\n

    FreqAI

    You can use this to setup FreqAI on a powerful machine, while you run consumers on simple machines like raspberries, which can interpret the signals generated from the producer in different ways.

    "},{"location":"producer-consumer/#example-consumer-strategy","title":"Example - Consumer Strategy","text":"

    A logically equivalent strategy which calculates no indicators itself, but will have the same analyzed dataframes available to make trading decisions based on the indicators calculated in the producer. In this example the consumer has the same entry criteria, however this is not necessary. The consumer may use different logic to enter/exit trades, and only use the indicators as specified.

    class ConsumerStrategy(IStrategy):\n    #...\n    process_only_new_candles = False # required for consumers\n\n    _columns_to_expect = ['rsi_default', 'tema_default', 'bb_middleband_default']\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Use the websocket api to get pre-populated indicators from another freqtrade instance.\n        Use `self.dp.get_producer_df(pair)` to get the dataframe\n        \"\"\"\n        pair = metadata['pair']\n        timeframe = self.timeframe\n\n        producer_pairs = self.dp.get_producer_pairs()\n        # You can specify which producer to get pairs from via:\n        # self.dp.get_producer_pairs(\"my_other_producer\")\n\n        # This func returns the analyzed dataframe, and when it was analyzed\n        producer_dataframe, _ = self.dp.get_producer_df(pair)\n        # You can get other data if the producer makes it available:\n        # self.dp.get_producer_df(\n        #   pair,\n        #   timeframe=\"1h\",\n        #   candle_type=CandleType.SPOT,\n        #   producer_name=\"my_other_producer\"\n        # )\n\n        if not producer_dataframe.empty:\n            # If you plan on passing the producer's entry/exit signal directly,\n            # specify ffill=False or it will have unintended results\n            merged_dataframe = merge_informative_pair(dataframe, producer_dataframe,\n                                                      timeframe, timeframe,\n                                                      append_timeframe=False,\n                                                      suffix=\"default\")\n            return merged_dataframe\n        else:\n            dataframe[self._columns_to_expect] = 0\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        \"\"\"\n        Populates the entry signal for the given dataframe\n        \"\"\"\n        # Use the dataframe columns as if we calculated them ourselves\n        dataframe.loc[\n            (\n                (qtpylib.crossed_above(dataframe['rsi_default'], self.buy_rsi.value)) &\n                (dataframe['tema_default'] <= dataframe['bb_middleband_default']) &\n                (dataframe['tema_default'] > dataframe['tema_default'].shift(1)) &\n                (dataframe['volume'] > 0)\n            ),\n            'enter_long'] = 1\n\n        return dataframe\n

    Using upstream signals

    By setting remove_entry_exit_signals=false, you can also use the producer's signals directly. They should be available as enter_long_default (assuming suffix=\"default\" was used) - and can be used as either signal directly, or as additional indicator.

    "},{"location":"recursive-analysis/","title":"Recursive analysis","text":"

    This page explains how to validate your strategy for inaccuracies due to recursive issues with certain indicators.

    A recursive formula defines any term of a sequence relative to its preceding term(s). An example of a recursive formula is an = an-1 + b.

    Why does this matter for Freqtrade? In backtesting, the bot will get full data of the pairs according to the timerange specified. But in a dry/live run, the bot will be limited by the amount of data each exchanges gives.

    For example, to calculate a very basic indicator called steps, the first row's value is always 0, while the following rows' values are equal to the value of the previous row plus 1. If I were to calculate it using the latest 1000 candles, then the steps value of the first row is 0, and the steps value at the last closed candle is 999.

    What happens if the calculation is using only the latest 500 candles? Then instead of 999, the steps value at last closed candle is 499. The difference of the value means your backtest result can differ from your dry/live run result.

    The recursive-analysis command requires historic data to be available. To learn how to get data for the pairs and exchange you're interested in, head over to the Data Downloading section of the documentation.

    This command is built upon preparing different lengths of data and calculates indicators based on them. This does not backtest the strategy itself, but rather only calculates the indicators. After calculating the indicators of different startup candle values (startup_candle_count) are done, the values of last rows across all specified startup_candle_count are compared to see how much variance they show compared to the base calculation.

    Command settings:

    • Use the -p option to set your desired pair to analyze. Since we are only looking at indicator values, using more than one pair is redundant. Preferably use a pair with a relatively high price and at least moderate volatility, such as BTC or ETH, to avoid rounding issues that can make the results inaccurate. If no pair is set on the command, the pair used for this analysis is the first pair in the whitelist.
    • It is recommended to set a long timerange (at least 5000 candles) so that the initial indicators' calculation that is going to be used as a benchmark has very small or no recursive issues itself. For example, for a 5m timeframe, a timerange of 5000 candles would be equal to 18 days.
    • --cache is forced to \"none\" to avoid loading previous indicators calculation automatically.

    In addition to the recursive formula check, this command also carries out a simple lookahead bias check on the indicator values only. For a full lookahead check, use Lookahead-analysis.

    "},{"location":"recursive-analysis/#recursive-analysis-command-reference","title":"Recursive-analysis command reference","text":"
    usage: freqtrade recursive-analysis [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                    [-d PATH] [--userdir PATH] [-s NAME]\n                                    [--strategy-path PATH]\n                                    [--recursive-strategy-search]\n                                    [--freqaimodel NAME]\n                                    [--freqaimodel-path PATH] [-i TIMEFRAME]\n                                    [--timerange TIMERANGE]\n                                    [--data-format-ohlcv {json,jsongz,hdf5,feather,parquet}]\n                                    [-p PAIR]\n                                    [--freqai-backtest-live-models]\n                                    [--startup-candle STARTUP_CANDLES [STARTUP_CANDLES ...]]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i TIMEFRAME, --timeframe TIMEFRAME\n                        Specify timeframe (`1m`, `5m`, `30m`, `1h`, `1d`).\n  --data-format-ohlcv {json,jsongz,hdf5,feather,parquet}\n                        Storage format for downloaded candle (OHLCV) data.\n                        (default: `feather`).\n  -p PAIR, --pairs PAIR\n                        Limit command to this pair.\n  --startup-candle STARTUP_CANDLE [STARTUP_CANDLE ...]\n                        Provide a space-separated list of startup_candle_count to\n                        be checked. Default : `199 399 499 999 1999`.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n\nStrategy arguments:\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --strategy-path PATH  Specify additional strategy lookup path.\n  --timerange TIMERANGE\n                        Specify what timerange of data to use.\n
    "},{"location":"recursive-analysis/#why-are-odd-numbered-default-startup-candles-used","title":"Why are odd-numbered default startup candles used?","text":"

    The default value for startup candles are odd numbers. When the bot fetches candle data from the exchange's API, the last candle is the one being checked by the bot and the rest of the data are the \"startup candles\".

    For example, Binance allows 1000 candles per API call. When the bot receives 1000 candles, the last candle is the \"current candle\", and the preceding 999 candles are the \"startup candles\". By setting the startup candle count as 1000 instead of 999, the bot will try to fetch 1001 candles instead. The exchange API will then send candle data in a paginated form, i.e. in case of the Binance API, this will be two groups- one of length 1000 and another of length 1. This results in the bot thinking the strategy needs 1001 candles of data, and so it will download 2000 candles worth of data instead, which means there will be 1 \"current candle\" and 1999 \"startup candles\".

    Furthermore, exchanges limit the number of consecutive bulk API calls, e.g. Binance allows 5 calls. In this case, only 5000 candles can be downloaded from Binance API without hitting the API rate limit, which means the max startup_candle_count you can have is 4999.

    Please note that this candle limit may be changed in the future by the exchanges without any prior notice.

    "},{"location":"recursive-analysis/#how-does-the-command-work","title":"How does the command work?","text":"
    • Firstly an initial indicator calculation is carried out using the supplied timerange to generate a benchmark for indicator values.
    • After setting the benchmark it will then carry out additional runs for each of the different startup candle count values.
    • The command will then compare the indicator values at the last candle rows and report the differences in a table.
    "},{"location":"recursive-analysis/#understanding-the-recursive-analysis-output","title":"Understanding the recursive-analysis output","text":"

    This is an example of an output results table where at least one indicator has a recursive formula issue:

    | indicators   | 20      | 40      | 80     | 100    | 150     | 300     | 999    |\n|--------------+---------+---------+--------+--------+---------+---------+--------|\n| rsi_30       | nan%    | -6.025% | 0.612% | 0.828% | -0.140% | 0.000%  | 0.000% |\n| rsi_14       | 24.141% | -0.876% | 0.070% | 0.007% | -0.000% | -0.000% | -      |\n

    The column headers indicate the different startup_candle_count used in the analysis. The values in the table indicate the variance of the calculated indicators compared to the benchmark value.

    nan% means the value of that indicator cannot be calculated due to lack of data. In this example, you cannot calculate RSI with length 30 with just 21 candles (1 current candle + 20 startup candles).

    Users should assess the table per indicator to decide if the specified startup_candle_count results in a sufficiently small variance so that the indicator does not have any effect on entries and/or exits.

    As such, aiming for absolute zero variance (shown by - value) might not be the best option, because some indicators might require you to use such a long startup_candle_count to have zero variance.

    "},{"location":"recursive-analysis/#caveats","title":"Caveats","text":"
    • recursive-analysis will only calculate and compare the indicator values at the last row. The output table reports the percentage differences between the different startup candle count calculations and the original benchmark calculation. Whether it has any actual impact on your entries and exits is not included.
    • The ideal scenario is that indicators will have no variance (or at least very close to 0%) despite the startup candle being varied. In reality, indicators such as EMA are using a recursive formula to calculate indicator values, so the goal is not necessarily to have zero percentage variance, but to have the variance low enough (and therefore startup_candle_count high enough) that the recursion inherent in the indicator will not have any real impact on trading decisions.
    • recursive-analysis will only run calculations on populate_indicators and @informative decorator(s). If you put any indicator calculation on populate_entry_trend or populate_exit_trend, it won't be calculated.
    "},{"location":"rest-api/","title":"REST API","text":""},{"location":"rest-api/#frequi","title":"FreqUI","text":"

    FreqUI now has it's own dedicated documentation section - please refer to that section for all information regarding the FreqUI.

    "},{"location":"rest-api/#configuration","title":"Configuration","text":"

    Enable the rest API by adding the api_server section to your configuration and setting api_server.enabled to true.

    Sample configuration:

        \"api_server\": {\n        \"enabled\": true,\n        \"listen_ip_address\": \"127.0.0.1\",\n        \"listen_port\": 8080,\n        \"verbosity\": \"error\",\n        \"enable_openapi\": false,\n        \"jwt_secret_key\": \"somethingrandom\",\n        \"CORS_origins\": [],\n        \"username\": \"Freqtrader\",\n        \"password\": \"SuperSecret1!\",\n        \"ws_token\": \"sercet_Ws_t0ken\"\n    },\n

    Security warning

    By default, the configuration listens on localhost only (so it's not reachable from other systems). We strongly recommend to not expose this API to the internet and choose a strong, unique password, since others will potentially be able to control your bot.

    API/UI Access on a remote servers

    If you're running on a VPS, you should consider using either a ssh tunnel, or setup a VPN (openVPN, wireguard) to connect to your bot. This will ensure that freqUI is not directly exposed to the internet, which is not recommended for security reasons (freqUI does not support https out of the box). Setup of these tools is not part of this tutorial, however many good tutorials can be found on the internet.

    You can then access the API by going to http://127.0.0.1:8080/api/v1/ping in a browser to check if the API is running correctly. This should return the response:

    {\"status\":\"pong\"}\n

    All other endpoints return sensitive info and require authentication and are therefore not available through a web browser.

    "},{"location":"rest-api/#security","title":"Security","text":"

    To generate a secure password, best use a password manager, or use the below code.

    import secrets\nsecrets.token_hex()\n

    JWT token

    Use the same method to also generate a JWT secret key (jwt_secret_key).

    Password selection

    Please make sure to select a very strong, unique password to protect your bot from unauthorized access. Also change jwt_secret_key to something random (no need to remember this, but it'll be used to encrypt your session, so it better be something unique!).

    "},{"location":"rest-api/#configuration-with-docker","title":"Configuration with docker","text":"

    If you run your bot using docker, you'll need to have the bot listen to incoming connections. The security is then handled by docker.

        \"api_server\": {\n        \"enabled\": true,\n        \"listen_ip_address\": \"0.0.0.0\",\n        \"listen_port\": 8080,\n        \"username\": \"Freqtrader\",\n        \"password\": \"SuperSecret1!\",\n        //...\n    },\n

    Make sure that the following 2 lines are available in your docker-compose file:

        ports:\n      - \"127.0.0.1:8080:8080\"\n

    Security warning

    By using \"8080:8080\" (or \"0.0.0.0:8080:8080\") in the docker port mapping, the API will be available to everyone connecting to the server under the correct port, so others may be able to control your bot. This may be safe if you're running the bot in a secure environment (like your home network), but it's not recommended to expose the API to the internet.

    "},{"location":"rest-api/#rest-api_1","title":"Rest API","text":""},{"location":"rest-api/#consuming-the-api","title":"Consuming the API","text":"

    You can consume the API by using freqtrade-client (also available as scripts/rest_client.py). This command can be installed independent of the bot by using pip install freqtrade-client.

    This module is designed to be lightweight, and only depends on the requests and python-rapidjson modules, skipping all heavy dependencies freqtrade otherwise needs.

    freqtrade-client <command> [optional parameters]\n

    By default, the script assumes 127.0.0.1 (localhost) and port 8080 to be used, however you can specify a configuration file to override this behaviour.

    "},{"location":"rest-api/#minimalistic-client-config","title":"Minimalistic client config","text":"
    {\n    \"api_server\": {\n        \"enabled\": true,\n        \"listen_ip_address\": \"0.0.0.0\",\n        \"listen_port\": 8080,\n        \"username\": \"Freqtrader\",\n        \"password\": \"SuperSecret1!\",\n        //...\n    }\n}\n
    freqtrade-client --config rest_config.json <command> [optional parameters]\n

    Commands with many arguments may require keyword arguments (for clarity) - which can be provided as follows:

    freqtrade-client --config rest_config.json forceenter BTC/USDT long enter_tag=GutFeeling\n

    This method will work for all arguments - check the \"show\" command for a list of available parameters.

    Programmatic use

    The freqtrade-client package (installable independent of freqtrade) can be used in your own scripts to interact with the freqtrade API. to do so, please use the following:

    from freqtrade_client import FtRestClient\n\n\nclient = FtRestClient(server_url, username, password)\n\n# Get the status of the bot\nping = client.ping()\nprint(ping)\n# ... \n

    For a full list of available commands, please refer to the list below.

    "},{"location":"rest-api/#available-endpoints","title":"Available endpoints","text":"Command Description ping Simple command testing the API Readiness - requires no authentication. start Starts the trader. stop Stops the trader. stopbuy Stops the trader from opening new trades. Gracefully closes open trades according to their rules. reload_config Reloads the configuration file. trades List last trades. Limited to 500 trades per call. trade/<tradeid> Get specific trade. trades/<tradeid> DELETE - Remove trade from the database. Tries to close open orders. Requires manual handling of this trade on the exchange. trades/<tradeid>/open-order DELETE - Cancel open order for this trade. trades/<tradeid>/reload GET - Reload a trade from the Exchange. Only works in live, and can potentially help recover a trade that was manually sold on the exchange. show_config Shows part of the current configuration with relevant settings to operation. logs Shows last log messages. status Lists all open trades. count Displays number of trades used and available. entries [pair] Shows profit statistics for each enter tags for given pair (or all pairs if pair isn't given). Pair is optional. exits [pair] Shows profit statistics for each exit reasons for given pair (or all pairs if pair isn't given). Pair is optional. mix_tags [pair] Shows profit statistics for each combinations of enter tag + exit reasons for given pair (or all pairs if pair isn't given). Pair is optional. locks Displays currently locked pairs. delete_lock <lock_id> Deletes (disables) the lock by id. locks add <pair>, <until>, [side], [reason] Locks a pair until \"until\". (Until will be rounded up to the nearest timeframe). profit Display a summary of your profit/loss from close trades and some stats about your performance. forceexit <trade_id> [order_type] [amount] Instantly exits the given trade (ignoring minimum_roi), using the given order type (\"market\" or \"limit\", uses your config setting if not specified), and the chosen amount (full sell if not specified). forceexit all Instantly exits all open trades (Ignoring minimum_roi). forceenter <pair> [rate] Instantly enters the given pair. Rate is optional. (force_entry_enable must be set to True) forceenter <pair> <side> [rate] Instantly longs or shorts the given pair. Rate is optional. (force_entry_enable must be set to True) performance Show performance of each finished trade grouped by pair. balance Show account balance per currency. daily <n> Shows profit or loss per day, over the last n days (n defaults to 7). weekly <n> Shows profit or loss per week, over the last n days (n defaults to 4). monthly <n> Shows profit or loss per month, over the last n days (n defaults to 3). stats Display a summary of profit / loss reasons as well as average holding times. whitelist Show the current whitelist. blacklist [pair] Show the current blacklist, or adds a pair to the blacklist. edge Show validated pairs by Edge if it is enabled. pair_candles Returns dataframe for a pair / timeframe combination while the bot is running. Alpha pair_history Returns an analyzed dataframe for a given timerange, analyzed by a given strategy. Alpha plot_config Get plot config from the strategy (or nothing if not configured). Alpha strategies List strategies in strategy directory. Alpha strategy <strategy> Get specific Strategy content. Alpha available_pairs List available backtest data. Alpha version Show version. sysinfo Show information about the system load. health Show bot health (last bot loop).

    Alpha status

    Endpoints labeled with Alpha status above may change at any time without notice.

    Possible commands can be listed from the rest-client script using the help command.

    freqtrade-client help\n
    Possible commands:\n\navailable_pairs\n    Return available pair (backtest data) based on timeframe / stake_currency selection\n\n        :param timeframe: Only pairs with this timeframe available.\n        :param stake_currency: Only pairs that include this timeframe\n\nbalance\n    Get the account balance.\n\nblacklist\n    Show the current blacklist.\n\n        :param add: List of coins to add (example: \"BNB/BTC\")\n\ncancel_open_order\n    Cancel open order for trade.\n\n        :param trade_id: Cancels open orders for this trade.\n\ncount\n    Return the amount of open trades.\n\ndaily\n    Return the profits for each day, and amount of trades.\n\ndelete_lock\n    Delete (disable) lock from the database.\n\n        :param lock_id: ID for the lock to delete\n\ndelete_trade\n    Delete trade from the database.\n        Tries to close open orders. Requires manual handling of this asset on the exchange.\n\n        :param trade_id: Deletes the trade with this ID from the database.\n\nedge\n    Return information about edge.\n\nforcebuy\n    Buy an asset.\n\n        :param pair: Pair to buy (ETH/BTC)\n        :param price: Optional - price to buy\n\nforceenter\n    Force entering a trade\n\n        :param pair: Pair to buy (ETH/BTC)\n        :param side: 'long' or 'short'\n        :param price: Optional - price to buy\n\nforceexit\n    Force-exit a trade.\n\n        :param tradeid: Id of the trade (can be received via status command)\n        :param ordertype: Order type to use (must be market or limit)\n        :param amount: Amount to sell. Full sell if not given\n\nhealth\n    Provides a quick health check of the running bot.\n\nlocks\n    Return current locks\n\nlogs\n    Show latest logs.\n\n        :param limit: Limits log messages to the last <limit> logs. No limit to get the entire log.\n\npair_candles\n    Return live dataframe for <pair><timeframe>.\n\n        :param pair: Pair to get data for\n        :param timeframe: Only pairs with this timeframe available.\n        :param limit: Limit result to the last n candles.\n\npair_history\n    Return historic, analyzed dataframe\n\n        :param pair: Pair to get data for\n        :param timeframe: Only pairs with this timeframe available.\n        :param strategy: Strategy to analyze and get values for\n        :param timerange: Timerange to get data for (same format than --timerange endpoints)\n\nperformance\n    Return the performance of the different coins.\n\nping\n    simple ping\n\nplot_config\n    Return plot configuration if the strategy defines one.\n\nprofit\n    Return the profit summary.\n\nreload_config\n    Reload configuration.\n\nshow_config\n        Returns part of the configuration, relevant for trading operations.\n\nstart\n    Start the bot if it's in the stopped state.\n\nstats\n    Return the stats report (durations, sell-reasons).\n\nstatus\n    Get the status of open trades.\n\nstop\n    Stop the bot. Use `start` to restart.\n\nstopbuy\n    Stop buying (but handle sells gracefully). Use `reload_config` to reset.\n\nstrategies\n    Lists available strategies\n\nstrategy\n    Get strategy details\n\n        :param strategy: Strategy class name\n\nsysinfo\n    Provides system information (CPU, RAM usage)\n\ntrade\n    Return specific trade\n\n        :param trade_id: Specify which trade to get.\n\ntrades\n    Return trades history, sorted by id\n\n        :param limit: Limits trades to the X last trades. Max 500 trades.\n        :param offset: Offset by this amount of trades.\n\nversion\n    Return the version of the bot.\n\nwhitelist\n    Show the current whitelist.\n
    "},{"location":"rest-api/#message-websocket","title":"Message WebSocket","text":"

    The API Server includes a websocket endpoint for subscribing to RPC messages from the freqtrade Bot. This can be used to consume real-time data from your bot, such as entry/exit fill messages, whitelist changes, populated indicators for pairs, and more.

    This is also used to setup Producer/Consumer mode in Freqtrade.

    Assuming your rest API is set to 127.0.0.1 on port 8080, the endpoint is available at http://localhost:8080/api/v1/message/ws.

    To access the websocket endpoint, the ws_token is required as a query parameter in the endpoint URL.

    To generate a safe ws_token you can run the following code:

    >>> import secrets\n>>> secrets.token_urlsafe(25)\n'hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q'\n

    You would then add that token under ws_token in your api_server config. Like so:

    \"api_server\": {\n    \"enabled\": true,\n    \"listen_ip_address\": \"127.0.0.1\",\n    \"listen_port\": 8080,\n    \"verbosity\": \"error\",\n    \"enable_openapi\": false,\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [],\n    \"username\": \"Freqtrader\",\n    \"password\": \"SuperSecret1!\",\n    \"ws_token\": \"hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q\" // <-----\n},\n

    You can now connect to the endpoint at http://localhost:8080/api/v1/message/ws?token=hZ-y58LXyX_HZ8O1cJzVyN6ePWrLpNQv4Q.

    Reuse of example tokens

    Please do not use the above example token. To make sure you are secure, generate a completely new token.

    "},{"location":"rest-api/#using-the-websocket","title":"Using the WebSocket","text":"

    Once connected to the WebSocket, the bot will broadcast RPC messages to anyone who is subscribed to them. To subscribe to a list of messages, you must send a JSON request through the WebSocket like the one below. The data key must be a list of message type strings.

    {\n  \"type\": \"subscribe\",\n  \"data\": [\"whitelist\", \"analyzed_df\"] // A list of string message types\n}\n

    For a list of message types, please refer to the RPCMessageType enum in freqtrade/enums/rpcmessagetype.py

    Now anytime those types of RPC messages are sent in the bot, you will receive them through the WebSocket as long as the connection is active. They typically take the same form as the request:

    {\n  \"type\": \"analyzed_df\",\n  \"data\": {\n      \"key\": [\"NEO/BTC\", \"5m\", \"spot\"],\n      \"df\": {}, // The dataframe\n      \"la\": \"2022-09-08 22:14:41.457786+00:00\"\n  }\n}\n
    "},{"location":"rest-api/#reverse-proxy-setup","title":"Reverse Proxy setup","text":"

    When using Nginx, the following configuration is required for WebSockets to work (Note this configuration is incomplete, it's missing some information and can not be used as is):

    Please make sure to replace <freqtrade_listen_ip> (and the subsequent port) with the IP and Port matching your configuration/setup.

    http {\n    map $http_upgrade $connection_upgrade {\n        default upgrade;\n        '' close;\n    }\n\n    #...\n\n    server {\n        #...\n\n        location / {\n            proxy_http_version 1.1;\n            proxy_pass http://<freqtrade_listen_ip>:8080;\n            proxy_set_header Upgrade $http_upgrade;\n            proxy_set_header Connection $connection_upgrade;\n            proxy_set_header Host $host;\n        }\n    }\n}\n

    To properly configure your reverse proxy (securely), please consult it's documentation for proxying websockets.

    • Traefik: Traefik supports websockets out of the box, see the documentation
    • Caddy: Caddy v2 supports websockets out of the box, see the documentation

    SSL certificates

    You can use tools like certbot to setup ssl certificates to access your bot's UI through encrypted connection by using any of the above reverse proxies. While this will protect your data in transit, we do not recommend to run the freqtrade API outside of your private network (VPN, SSH tunnel).

    "},{"location":"rest-api/#openapi-interface","title":"OpenAPI interface","text":"

    To enable the builtin openAPI interface (Swagger UI), specify \"enable_openapi\": true in the api_server configuration. This will enable the Swagger UI at the /docs endpoint. By default, that's running at http://localhost:8080/docs - but it'll depend on your settings.

    "},{"location":"rest-api/#advanced-api-usage-using-jwt-tokens","title":"Advanced API usage using JWT tokens","text":"

    Note

    The below should be done in an application (a Freqtrade REST API client, which fetches info via API), and is not intended to be used on a regular basis.

    Freqtrade's REST API also offers JWT (JSON Web Tokens). You can login using the following command, and subsequently use the resulting access_token.

    > curl -X POST --user Freqtrader http://localhost:8080/api/v1/token/login\n{\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk2ODEsIm5iZiI6MTU4OTExOTY4MSwianRpIjoiMmEwYmY0NWUtMjhmOS00YTUzLTlmNzItMmM5ZWVlYThkNzc2IiwiZXhwIjoxNTg5MTIwNTgxLCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.qt6MAXYIa-l556OM7arBvYJ0SDI9J8bIk3_glDujF5g\",\"refresh_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk2ODEsIm5iZiI6MTU4OTExOTY4MSwianRpIjoiZWQ1ZWI3YjAtYjMwMy00YzAyLTg2N2MtNWViMjIxNWQ2YTMxIiwiZXhwIjoxNTkxNzExNjgxLCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJ0eXBlIjoicmVmcmVzaCJ9.d1AT_jYICyTAjD0fiQAr52rkRqtxCjUGEMwlNuuzgNQ\"}\n\n> access_token=\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk2ODEsIm5iZiI6MTU4OTExOTY4MSwianRpIjoiMmEwYmY0NWUtMjhmOS00YTUzLTlmNzItMmM5ZWVlYThkNzc2IiwiZXhwIjoxNTg5MTIwNTgxLCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.qt6MAXYIa-l556OM7arBvYJ0SDI9J8bIk3_glDujF5g\"\n# Use access_token for authentication\n> curl -X GET --header \"Authorization: Bearer ${access_token}\" http://localhost:8080/api/v1/count\n

    Since the access token has a short timeout (15 min) - the token/refresh request should be used periodically to get a fresh access token:

    > curl -X POST --header \"Authorization: Bearer ${refresh_token}\"http://localhost:8080/api/v1/token/refresh\n{\"access_token\":\"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1ODkxMTk5NzQsIm5iZiI6MTU4OTExOTk3NCwianRpIjoiMDBjNTlhMWUtMjBmYS00ZTk0LTliZjAtNWQwNTg2MTdiZDIyIiwiZXhwIjoxNTg5MTIwODc0LCJpZGVudGl0eSI6eyJ1IjoiRnJlcXRyYWRlciJ9LCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MifQ.1seHlII3WprjjclY6DpRhen0rqdF4j6jbvxIhUFaSbs\"}\n
    "},{"location":"rest-api/#cors","title":"CORS","text":"

    This whole section is only necessary in cross-origin cases (where you multiple bot API's running on localhost:8081, localhost:8082, ...), and want to combine them into one FreqUI instance.

    Technical explanation

    All web-based front-ends are subject to CORS - Cross-Origin Resource Sharing. Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems. Also, the standard disallows * CORS policies for requests with credentials, so this setting must be set appropriately.

    Users can allow access from different origin URL's to the bot API via the CORS_origins configuration setting. It consists of a list of allowed URL's that are allowed to consume resources from the bot's API.

    Assuming your application is deployed as https://frequi.freqtrade.io/home/ - this would mean that the following configuration becomes necessary:

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"https://frequi.freqtrade.io\"],\n    //...\n}\n

    In the following (pretty common) case, FreqUI is accessible on http://localhost:8080/trade (this is what you see in your navbar when navigating to freqUI).

    The correct configuration for this case is http://localhost:8080 - the main part of the URL including the port.

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"http://localhost:8080\"],\n    //...\n}\n

    trailing Slash

    The trailing slash is not allowed in the CORS_origins configuration (e.g. \"http://localhots:8080/\"). Such a configuration will not take effect, and the cors errors will remain.

    Note

    We strongly recommend to also set jwt_secret_key to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"sql_cheatsheet/","title":"SQL Helper","text":"

    This page contains some help if you want to query your sqlite db.

    Other Database systems

    To use other Database Systems like PostgreSQL or MariaDB, you can use the same queries, but you need to use the respective client for the database system. Click here to learn how to setup a different database system with freqtrade.

    Warning

    If you are not familiar with SQL, you should be very careful when running queries on your database. Always make sure to have a backup of your database before running any queries.

    "},{"location":"sql_cheatsheet/#install-sqlite3","title":"Install sqlite3","text":"

    Sqlite3 is a terminal based sqlite application. Feel free to use a visual Database editor like SqliteBrowser if you feel more comfortable with that.

    "},{"location":"sql_cheatsheet/#ubuntudebian-installation","title":"Ubuntu/Debian installation","text":"
    sudo apt-get install sqlite3\n
    "},{"location":"sql_cheatsheet/#using-sqlite3-via-docker","title":"Using sqlite3 via docker","text":"

    The freqtrade docker image does contain sqlite3, so you can edit the database without having to install anything on the host system.

    docker compose exec freqtrade /bin/bash\nsqlite3 <database-file>.sqlite\n
    "},{"location":"sql_cheatsheet/#open-the-db","title":"Open the DB","text":"
    sqlite3\n.open <filepath>\n
    "},{"location":"sql_cheatsheet/#table-structure","title":"Table structure","text":""},{"location":"sql_cheatsheet/#list-tables","title":"List tables","text":"
    .tables\n
    "},{"location":"sql_cheatsheet/#display-table-structure","title":"Display table structure","text":"
    .schema <table_name>\n
    "},{"location":"sql_cheatsheet/#get-all-trades-in-the-table","title":"Get all trades in the table","text":"
    SELECT * FROM trades;\n
    "},{"location":"sql_cheatsheet/#destructive-queries","title":"Destructive queries","text":"

    Queries that write to the database. These queries should usually not be necessary as freqtrade tries to handle all database operations itself - or exposes them via API or telegram commands.

    Warning

    Please make sure you have a backup of your database before running any of the below queries.

    Danger

    You should also never run any writing query (update, insert, delete) while a bot is connected to the database. This can and will lead to data corruption - most likely, without the possibility of recovery.

    "},{"location":"sql_cheatsheet/#fix-trade-still-open-after-a-manual-exit-on-the-exchange","title":"Fix trade still open after a manual exit on the exchange","text":"

    Warning

    Manually selling a pair on the exchange will not be detected by the bot and it will try to sell anyway. Whenever possible, /forceexit should be used to accomplish the same thing. It is strongly advised to backup your database file before making any manual changes.

    Note

    This should not be necessary after /forceexit, as force_exit orders are closed automatically by the bot on the next iteration.

    UPDATE trades\nSET is_open=0,\n  close_date=<close_date>,\n  close_rate=<close_rate>,\n  close_profit = close_rate / open_rate - 1,\n  close_profit_abs = (amount * <close_rate> * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),\n  exit_reason=<exit_reason>\nWHERE id=<trade_ID_to_update>;\n
    "},{"location":"sql_cheatsheet/#example","title":"Example","text":"
    UPDATE trades\nSET is_open=0,\n  close_date='2020-06-20 03:08:45.103418',\n  close_rate=0.19638016,\n  close_profit=0.0496,\n  close_profit_abs = (amount * 0.19638016 * (1 - fee_close) - (amount * (open_rate * (1 - fee_open)))),\n  exit_reason='force_exit'  \nWHERE id=31;\n
    "},{"location":"sql_cheatsheet/#remove-trade-from-the-database","title":"Remove trade from the database","text":"

    Use RPC Methods to delete trades

    Consider using /delete <tradeid> via telegram or rest API. That's the recommended way to deleting trades.

    If you'd still like to remove a trade from the database directly, you can use the below query.

    Danger

    Some systems (Ubuntu) disable foreign keys in their sqlite3 packaging. When using sqlite - please ensure that foreign keys are on by running PRAGMA foreign_keys = ON before the above query.

    DELETE FROM trades WHERE id = <tradeid>;\n\nDELETE FROM trades WHERE id = 31;\n

    Warning

    This will remove this trade from the database. Please make sure you got the correct id and NEVER run this query without the where clause.

    "},{"location":"stoploss/","title":"Stop Loss","text":"

    The stoploss configuration parameter is loss as ratio that should trigger a sale. For example, value -0.10 will cause immediate sell if the profit dips below -10% for a given trade. This parameter is optional. Stoploss calculations do include fees, so a stoploss of -10% is placed exactly 10% below the entry point.

    Most of the strategy files already include the optimal stoploss value.

    Info

    All stoploss properties mentioned in this file can be set in the Strategy, or in the configuration. Configuration values will override the strategy values.

    "},{"location":"stoploss/#stop-loss-on-exchangefreqtrade","title":"Stop Loss On-Exchange/Freqtrade","text":"

    Those stoploss modes can be on exchange or off exchange.

    These modes can be configured with these values:

        'emergency_exit': 'market',\n    'stoploss_on_exchange': False\n    'stoploss_on_exchange_interval': 60,\n    'stoploss_on_exchange_limit_ratio': 0.99\n

    Stoploss on exchange is only supported for the following exchanges, and not all exchanges support both stop-limit and stop-market. The Order-type will be ignored if only one mode is available.

    Exchange stop-loss type Binance limit Binance Futures market, limit Bingx market, limit HTX (former Huobi) limit kraken market, limit Gate limit Okx limit Kucoin stop-limit, stop-market

    Tight stoploss

    Do not set too low/tight stoploss value when using stop loss on exchange! If set to low/tight you will have greater risk of missing fill on the order and stoploss will not work.

    "},{"location":"stoploss/#stoploss_on_exchange-and-stoploss_on_exchange_limit_ratio","title":"stoploss_on_exchange and stoploss_on_exchange_limit_ratio","text":"

    Enable or Disable stop loss on exchange. If the stoploss is on exchange it means a stoploss limit order is placed on the exchange immediately after buy order fills. This will protect you against sudden crashes in market, as the order execution happens purely within the exchange, and has no potential network overhead.

    If stoploss_on_exchange uses limit orders, the exchange needs 2 prices, the stoploss_price and the Limit price. stoploss defines the stop-price where the limit order is placed - and limit should be slightly below this. If an exchange supports both limit and market stoploss orders, then the value of stoploss will be used to determine the stoploss type.

    Calculation example: we bought the asset at 100$. Stop-price is 95$, then limit would be 95 * 0.99 = 94.05$ - so the limit order fill can happen between 95$ and 94.05$.

    For example, assuming the stoploss is on exchange, and trailing stoploss is enabled, and the market is going up, then the bot automatically cancels the previous stoploss order and puts a new one with a stop value higher than the previous stoploss order.

    Note

    If stoploss_on_exchange is enabled and the stoploss is cancelled manually on the exchange, then the bot will create a new stoploss order.

    "},{"location":"stoploss/#stoploss_on_exchange_interval","title":"stoploss_on_exchange_interval","text":"

    In case of stoploss on exchange there is another parameter called stoploss_on_exchange_interval. This configures the interval in seconds at which the bot will check the stoploss and update it if necessary. The bot cannot do these every 5 seconds (at each iteration), otherwise it would get banned by the exchange. So this parameter will tell the bot how often it should update the stoploss order. The default value is 60 (1 minute). This same logic will reapply a stoploss order on the exchange should you cancel it accidentally.

    "},{"location":"stoploss/#stoploss_price_type","title":"stoploss_price_type","text":"

    Only applies to futures

    stoploss_price_type only applies to futures markets (on exchanges where it's available). Freqtrade will perform a validation of this setting on startup, failing to start if an invalid setting for your exchange has been selected. Supported price types are gonna differs between each exchanges. Please check with your exchange on which price types it supports.

    Stoploss on exchange on futures markets can trigger on different price types. The naming for these prices in exchange terminology often varies, but is usually something around \"last\" (or \"contract price\" ), \"mark\" and \"index\".

    Acceptable values for this setting are \"last\", \"mark\" and \"index\" - which freqtrade will transfer automatically to the corresponding API type, and place the stoploss on exchange order correspondingly.

    "},{"location":"stoploss/#force_exit","title":"force_exit","text":"

    force_exit is an optional value, which defaults to the same value as exit and is used when sending a /forceexit command from Telegram or from the Rest API.

    "},{"location":"stoploss/#force_entry","title":"force_entry","text":"

    force_entry is an optional value, which defaults to the same value as entry and is used when sending a /forceentry command from Telegram or from the Rest API.

    "},{"location":"stoploss/#emergency_exit","title":"emergency_exit","text":"

    emergency_exit is an optional value, which defaults to market and is used when creating stop loss on exchange orders fails. The below is the default which is used if not changed in strategy or configuration file.

    Example from strategy file:

    order_types = {\n    \"entry\": \"limit\",\n    \"exit\": \"limit\",\n    \"emergency_exit\": \"market\",\n    \"stoploss\": \"market\",\n    \"stoploss_on_exchange\": True,\n    \"stoploss_on_exchange_interval\": 60,\n    \"stoploss_on_exchange_limit_ratio\": 0.99\n}\n
    "},{"location":"stoploss/#stop-loss-types","title":"Stop Loss Types","text":"

    At this stage the bot contains the following stoploss support modes:

    1. Static stop loss.
    2. Trailing stop loss.
    3. Trailing stop loss, custom positive loss.
    4. Trailing stop loss only once the trade has reached a certain offset.
    5. Custom stoploss function
    "},{"location":"stoploss/#static-stop-loss","title":"Static Stop Loss","text":"

    This is very simple, you define a stop loss of x (as a ratio of price, i.e. x * 100% of price). This will try to sell the asset once the loss exceeds the defined loss.

    Example of stop loss:

        stoploss = -0.10\n

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    "},{"location":"stoploss/#trailing-stop-loss","title":"Trailing Stop Loss","text":"

    The initial value for this is stoploss, just as you would define your static Stop loss. To enable trailing stoploss:

        stoploss = -0.10\n    trailing_stop = True\n

    This will now activate an algorithm, which automatically moves the stop loss up every time the price of your asset increases.

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    • assuming the asset now increases to 102$
    • the stop loss will now be -10% of 102$ = 91.8$
    • now the asset drops in value to 101$, the stop loss will still be 91.8$ and would trigger at 91.8$.

    In summary: The stoploss will be adjusted to be always be -10% of the highest observed price.

    "},{"location":"stoploss/#trailing-stop-loss-custom-positive-loss","title":"Trailing stop loss, custom positive loss","text":"

    You could also have a default stop loss when you are in the red with your buy (buy - fee), but once you hit a positive result (or an offset you define) the system will utilize a new stop loss, which can have a different value. For example, your default stop loss is -10%, but once you have more than 0% profit (example 0.1%) a different trailing stoploss will be used.

    Note

    If you want the stoploss to only be changed when you break even of making a profit (what most users want) please refer to next section with offset enabled.

    Both values require trailing_stop to be set to true and trailing_stop_positive with a value.

        stoploss = -0.10\n    trailing_stop = True\n    trailing_stop_positive = 0.02\n    trailing_stop_positive_offset = 0.0\n    trailing_only_offset_is_reached = False  # Default - not necessary for this example\n

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    • assuming the asset now increases to 102$
    • the stop loss will now be -2% of 102$ = 99.96$ (99.96$ stop loss will be locked in and will follow asset price increments with -2%)
    • now the asset drops in value to 101$, the stop loss will still be 99.96$ and would trigger at 99.96$

    The 0.02 would translate to a -2% stop loss. Before this, stoploss is used for the trailing stoploss.

    Use an offset to change your stoploss

    Use trailing_stop_positive_offset to ensure that your new trailing stoploss will be in profit by setting trailing_stop_positive_offset higher than trailing_stop_positive. Your first new stoploss value will then already have locked in profits.

    Example with simplified math:

        stoploss = -0.10\n    trailing_stop = True\n    trailing_stop_positive = 0.02\n    trailing_stop_positive_offset = 0.03\n
    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%, so the stop loss would get triggered once the asset drops below 90$
    • assuming the asset now increases to 102$
    • the stoploss will now be at 91.8$ - 10% below the highest observed rate
    • assuming the asset now increases to 103.5$ (above the offset configured)
    • the stop loss will now be -2% of 103.5$ = 101.43$
    • now the asset drops in value to 102$, the stop loss will still be 101.43$ and would trigger once price breaks below 101.43$
    "},{"location":"stoploss/#trailing-stop-loss-only-once-the-trade-has-reached-a-certain-offset","title":"Trailing stop loss only once the trade has reached a certain offset","text":"

    You can also keep a static stoploss until the offset is reached, and then trail the trade to take profits once the market turns.

    If trailing_only_offset_is_reached = True then the trailing stoploss is only activated once the offset is reached. Until then, the stoploss remains at the configured stoploss. This option can be used with or without trailing_stop_positive, but uses trailing_stop_positive_offset as offset.

    Configuration (offset is buy-price + 3%):

        stoploss = -0.10\n    trailing_stop = True\n    trailing_stop_positive = 0.02\n    trailing_stop_positive_offset = 0.03\n    trailing_only_offset_is_reached = True\n

    For example, simplified math:

    • the bot buys an asset at a price of 100$
    • the stop loss is defined at -10%
    • the stop loss would get triggered once the asset drops below 90$
    • stoploss will remain at 90$ unless asset increases to or above the configured offset
    • assuming the asset now increases to 103$ (where we have the offset configured)
    • the stop loss will now be -2% of 103$ = 100.94$
    • now the asset drops in value to 101$, the stop loss will still be 100.94$ and would trigger at 100.94$

    Tip

    Make sure to have this value (trailing_stop_positive_offset) lower than minimal ROI, otherwise minimal ROI will apply first and sell the trade.

    "},{"location":"stoploss/#stoploss-and-leverage","title":"Stoploss and Leverage","text":"

    Stoploss should be thought of as \"risk on this trade\" - so a stoploss of 10% on a 100$ trade means you are willing to lose 10$ (10%) on this trade - which would trigger if the price moves 10% to the downside.

    When using leverage, the same principle is applied - with stoploss defining the risk on the trade (the amount you are willing to lose).

    Therefore, a stoploss of 10% on a 10x trade would trigger on a 1% price move. If your stake amount (own capital) was 100$ - this trade would be 1000$ at 10x (after leverage). If price moves 1% - you've lost 10$ of your own capital - therefore stoploss will trigger in this case.

    Make sure to be aware of this, and avoid using too tight stoploss (at 10x leverage, 10% risk may be too little to allow the trade to \"breath\" a little).

    "},{"location":"stoploss/#changing-stoploss-on-open-trades","title":"Changing stoploss on open trades","text":"

    A stoploss on an open trade can be changed by changing the value in the configuration or strategy and use the /reload_config command (alternatively, completely stopping and restarting the bot also works).

    The new stoploss value will be applied to open trades (and corresponding log-messages will be generated).

    "},{"location":"stoploss/#limitations","title":"Limitations","text":"

    Stoploss values cannot be changed if trailing_stop is enabled and the stoploss has already been adjusted, or if Edge is enabled (since Edge would recalculate stoploss based on the current market situation).

    "},{"location":"strategy-advanced/","title":"Advanced Strategies","text":"

    This page explains some advanced concepts available for strategies. If you're just getting started, please familiarize yourself with the Freqtrade basics and methods described in Strategy Customization first.

    The call sequence of the methods described here is covered under bot execution logic. Those docs are also helpful in deciding which method is most suitable for your customisation needs.

    Note

    Callback methods should only be implemented if a strategy uses them.

    Tip

    Start off with a strategy template containing all available callback methods by running freqtrade new-strategy --strategy MyAwesomeStrategy --template advanced

    "},{"location":"strategy-advanced/#storing-information-persistent","title":"Storing information (Persistent)","text":"

    Freqtrade allows storing/retrieving user custom information associated with a specific trade in the database.

    Using a trade object, information can be stored using trade.set_custom_data(key='my_key', value=my_value) and retrieved using trade.get_custom_data(key='my_key'). Each data entry is associated with a trade and a user supplied key (of type string). This means that this can only be used in callbacks that also provide a trade object.

    For the data to be able to be stored within the database, freqtrade must serialized the data. This is done by converting the data to a JSON formatted string. Freqtrade will attempt to reverse this action on retrieval, so from a strategy perspective, this should not be relevant.

    from freqtrade.persistence import Trade\nfrom datetime import timedelta\n\nclass AwesomeStrategy(IStrategy):\n\n    def bot_loop_start(self, **kwargs) -> None:\n        for trade in Trade.get_open_order_trades():\n            fills = trade.select_filled_orders(trade.entry_side)\n            if trade.pair == 'ETH/USDT':\n                trade_entry_type = trade.get_custom_data(key='entry_type')\n                if trade_entry_type is None:\n                    trade_entry_type = 'breakout' if 'entry_1' in trade.enter_tag else 'dip'\n                elif fills > 1:\n                    trade_entry_type = 'buy_up'\n                trade.set_custom_data(key='entry_type', value=trade_entry_type)\n        return super().bot_loop_start(**kwargs)\n\n    def adjust_entry_price(self, trade: Trade, order: Optional[Order], pair: str,\n                           current_time: datetime, proposed_rate: float, current_order_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n        # Limit orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair.\n        if (\n            pair == 'BTC/USDT' \n            and entry_tag == 'long_sma200' \n            and side == 'long' \n            and (current_time - timedelta(minutes=10)) > trade.open_date_utc \n            and order.filled == 0.0\n        ):\n            dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)\n            current_candle = dataframe.iloc[-1].squeeze()\n            # store information about entry adjustment\n            existing_count = trade.get_custom_data('num_entry_adjustments', default=0)\n            if not existing_count:\n                existing_count = 1\n            else:\n                existing_count += 1\n            trade.set_custom_data(key='num_entry_adjustments', value=existing_count)\n\n            # adjust order price\n            return current_candle['sma_200']\n\n        # default: maintain existing order\n        return current_order_rate\n\n    def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, **kwargs):\n\n        entry_adjustment_count = trade.get_custom_data(key='num_entry_adjustments')\n        trade_entry_type = trade.get_custom_data(key='entry_type')\n        if entry_adjustment_count is None:\n            if current_profit > 0.01 and (current_time - timedelta(minutes=100) > trade.open_date_utc):\n                return True, 'exit_1'\n        else\n            if entry_adjustment_count > 0 and if current_profit > 0.05:\n                return True, 'exit_2'\n            if trade_entry_type == 'breakout' and current_profit > 0.1:\n                return True, 'exit_3\n\n        return False, None\n

    The above is a simple example - there are simpler ways to retrieve trade data like entry-adjustments.

    Note

    It is recommended that simple data types are used [bool, int, float, str] to ensure no issues when serializing the data that needs to be stored. Storing big junks of data may lead to unintended side-effects, like a database becoming big (and as a consequence, also slow).

    Non-serializable data

    If supplied data cannot be serialized a warning is logged and the entry for the specified key will contain None as data.

    All attributes

    custom-data has the following accessors through the Trade object (assumed as trade below):

    • trade.get_custom_data(key='something', default=0) - Returns the actual value given in the type provided.
    • trade.get_custom_data_entry(key='something') - Returns the entry - including metadata. The value is accessible via .value property.
    • trade.set_custom_data(key='something', value={'some': 'value'}) - set or update the corresponding key for this trade. Value must be serializable - and we recommend to keep the stored data relatively small.

    \"value\" can be any type (both in setting and receiving) - but must be json serializable.

    "},{"location":"strategy-advanced/#storing-information-non-persistent","title":"Storing information (Non-Persistent)","text":"

    Deprecated

    This method of storing information is deprecated and we do advise against using non-persistent storage. Please use Persistent Storage instead.

    It's content has therefore been collapsed.

    Storing information

    Storing information can be accomplished by creating a new dictionary within the strategy class.

    The name of the variable can be chosen at will, but should be prefixed with custom_ to avoid naming collisions with predefined strategy variables.

    class AwesomeStrategy(IStrategy):\n    # Create custom dictionary\n    custom_info = {}\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # Check if the entry already exists\n        if not metadata[\"pair\"] in self.custom_info:\n            # Create empty entry for this pair\n            self.custom_info[metadata[\"pair\"]] = {}\n\n        if \"crosstime\" in self.custom_info[metadata[\"pair\"]]:\n            self.custom_info[metadata[\"pair\"]][\"crosstime\"] += 1\n        else:\n            self.custom_info[metadata[\"pair\"]][\"crosstime\"] = 1\n

    Warning

    The data is not persisted after a bot-restart (or config-reload). Also, the amount of data should be kept smallish (no DataFrames and such), otherwise the bot will start to consume a lot of memory and eventually run out of memory and crash.

    Note

    If the data is pair-specific, make sure to use pair as one of the keys in the dictionary.

    "},{"location":"strategy-advanced/#dataframe-access","title":"Dataframe access","text":"

    You may access dataframe in various strategy functions by querying it from dataprovider.

    from freqtrade.exchange import timeframe_to_prev_date\n\nclass AwesomeStrategy(IStrategy):\n    def confirm_trade_exit(self, pair: str, trade: 'Trade', order_type: str, amount: float,\n                           rate: float, time_in_force: str, exit_reason: str,\n                           current_time: 'datetime', **kwargs) -> bool:\n        # Obtain pair dataframe.\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n\n        # Obtain last available candle. Do not use current_time to look up latest candle, because \n        # current_time points to current incomplete candle whose data is not available.\n        last_candle = dataframe.iloc[-1].squeeze()\n        # <...>\n\n        # In dry/live runs trade open date will not match candle open date therefore it must be \n        # rounded.\n        trade_date = timeframe_to_prev_date(self.timeframe, trade.open_date_utc)\n        # Look up trade candle.\n        trade_candle = dataframe.loc[dataframe['date'] == trade_date]\n        # trade_candle may be empty for trades that just opened as it is still incomplete.\n        if not trade_candle.empty:\n            trade_candle = trade_candle.squeeze()\n            # <...>\n

    Using .iloc[-1]

    You can use .iloc[-1] here because get_analyzed_dataframe() only returns candles that backtesting is allowed to see. This will not work in populate_* methods, so make sure to not use .iloc[] in that area. Also, this will only work starting with version 2021.5.

    "},{"location":"strategy-advanced/#enter-tag","title":"Enter Tag","text":"

    When your strategy has multiple buy signals, you can name the signal that triggered. Then you can access your buy signal on custom_exit

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (dataframe['rsi'] < 35) &\n            (dataframe['volume'] > 0)\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'buy_signal_rsi')\n\n    return dataframe\n\ndef custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,\n                current_profit: float, **kwargs):\n    dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n    last_candle = dataframe.iloc[-1].squeeze()\n    if trade.enter_tag == 'buy_signal_rsi' and last_candle['rsi'] > 80:\n        return 'sell_signal_rsi'\n    return None\n

    Note

    enter_tag is limited to 100 characters, remaining data will be truncated.

    Warning

    There is only one enter_tag column, which is used for both long and short trades. As a consequence, this column must be treated as \"last write wins\" (it's just a dataframe column after all). In fancy situations, where multiple signals collide (or if signals are deactivated again based on different conditions), this can lead to odd results with the wrong tag applied to an entry signal. These results are a consequence of the strategy overwriting prior tags - where the last tag will \"stick\" and will be the one freqtrade will use.

    "},{"location":"strategy-advanced/#exit-tag","title":"Exit tag","text":"

    Similar to Entry Tagging, you can also specify an exit tag.

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (dataframe['rsi'] > 70) &\n            (dataframe['volume'] > 0)\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'exit_rsi')\n\n    return dataframe\n

    The provided exit-tag is then used as sell-reason - and shown as such in backtest results.

    Note

    exit_reason is limited to 100 characters, remaining data will be truncated.

    "},{"location":"strategy-advanced/#strategy-version","title":"Strategy version","text":"

    You can implement custom strategy versioning by using the \"version\" method, and returning the version you would like this strategy to have.

    def version(self) -> str:\n    \"\"\"\n    Returns version of the strategy.\n    \"\"\"\n    return \"1.1\"\n

    Note

    You should make sure to implement proper version control (like a git repository) alongside this, as freqtrade will not keep historic versions of your strategy, so it's up to the user to be able to eventually roll back to a prior version of the strategy.

    "},{"location":"strategy-advanced/#derived-strategies","title":"Derived strategies","text":"

    The strategies can be derived from other strategies. This avoids duplication of your custom strategy code. You can use this technique to override small parts of your main strategy, leaving the rest untouched:

    user_data/strategies/myawesomestrategy.py
    class MyAwesomeStrategy(IStrategy):\n    ...\n    stoploss = 0.13\n    trailing_stop = False\n    # All other attributes and methods are here as they\n    # should be in any custom strategy...\n    ...\n
    user_data/strategies/MyAwesomeStrategy2.py
    from myawesomestrategy import MyAwesomeStrategy\nclass MyAwesomeStrategy2(MyAwesomeStrategy):\n    # Override something\n    stoploss = 0.08\n    trailing_stop = True\n

    Both attributes and methods may be overridden, altering behavior of the original strategy in a way you need.

    While keeping the subclass in the same file is technically possible, it can lead to some problems with hyperopt parameter files, we therefore recommend to use separate strategy files, and import the parent strategy as shown above.

    "},{"location":"strategy-advanced/#embedding-strategies","title":"Embedding Strategies","text":"

    Freqtrade provides you with an easy way to embed the strategy into your configuration file. This is done by utilizing BASE64 encoding and providing this string at the strategy configuration field, in your chosen config file.

    "},{"location":"strategy-advanced/#encoding-a-string-as-base64","title":"Encoding a string as BASE64","text":"

    This is a quick example, how to generate the BASE64 string in python

    from base64 import urlsafe_b64encode\n\nwith open(file, 'r') as f:\n    content = f.read()\ncontent = urlsafe_b64encode(content.encode('utf-8'))\n

    The variable 'content', will contain the strategy file in a BASE64 encoded form. Which can now be set in your configurations file as following

    \"strategy\": \"NameOfStrategy:BASE64String\"\n

    Please ensure that 'NameOfStrategy' is identical to the strategy name!

    "},{"location":"strategy-advanced/#performance-warning","title":"Performance warning","text":"

    When executing a strategy, one can sometimes be greeted by the following in the logs

    PerformanceWarning: DataFrame is highly fragmented.

    This is a warning from pandas and as the warning continues to say: use pd.concat(axis=1). This can have slight performance implications, which are usually only visible during hyperopt (when optimizing an indicator).

    For example:

    for val in self.buy_ema_short.range:\n    dataframe[f'ema_short_{val}'] = ta.EMA(dataframe, timeperiod=val)\n

    should be rewritten to

    frames = [dataframe]\nfor val in self.buy_ema_short.range:\n    frames.append(DataFrame({\n        f'ema_short_{val}': ta.EMA(dataframe, timeperiod=val)\n    }))\n\n# Combine all dataframes, and reassign the original dataframe column\ndataframe = pd.concat(frames, axis=1)\n

    Freqtrade does however also counter this by running dataframe.copy() on the dataframe right after the populate_indicators() method - so performance implications of this should be low to non-existent.

    "},{"location":"strategy-callbacks/","title":"Strategy Callbacks","text":"

    While the main strategy functions (populate_indicators(), populate_entry_trend(), populate_exit_trend()) should be used in a vectorized way, and are only called once during backtesting, callbacks are called \"whenever needed\".

    As such, you should avoid doing heavy calculations in callbacks to avoid delays during operations. Depending on the callback used, they may be called when entering / exiting a trade, or throughout the duration of a trade.

    Currently available callbacks:

    • bot_start()
    • bot_loop_start()
    • custom_stake_amount()
    • custom_exit()
    • custom_stoploss()
    • custom_entry_price() and custom_exit_price()
    • check_entry_timeout() and check_exit_timeout()
    • confirm_trade_entry()
    • confirm_trade_exit()
    • adjust_trade_position()
    • adjust_entry_price()
    • leverage()
    • order_filled()

    Callback calling sequence

    You can find the callback calling sequence in bot-basics

    "},{"location":"strategy-callbacks/#imports-necessary-for-a-strategy","title":"Imports necessary for a strategy","text":"

    When creating a strategy, you will need to import the necessary modules and classes. The following imports are required for a strategy:

    By default, we recommend the following imports as a base line for your strategy: This will cover all imports necessary for freqtrade functions to work. Obviously you can add more imports as needed for your strategy.

    # flake8: noqa: F401\n# isort: skip_file\n# --- Do not remove these imports ---\nimport numpy as np\nimport pandas as pd\nfrom datetime import datetime, timedelta, timezone\nfrom pandas import DataFrame\nfrom typing import Dict, Optional, Union, Tuple\n\nfrom freqtrade.strategy import (\n    IStrategy,\n    Trade, \n    Order,\n    PairLocks,\n    informative,  # @informative decorator\n    # Hyperopt Parameters\n    BooleanParameter,\n    CategoricalParameter,\n    DecimalParameter,\n    IntParameter,\n    RealParameter,\n    # timeframe helpers\n    timeframe_to_minutes,\n    timeframe_to_next_date,\n    timeframe_to_prev_date,\n    # Strategy helper functions\n    merge_informative_pair,\n    stoploss_from_absolute,\n    stoploss_from_open,\n)\n\n# --------------------------------\n# Add your lib to import here\nimport talib.abstract as ta\nfrom technical import qtpylib\n
    "},{"location":"strategy-callbacks/#bot-start","title":"Bot start","text":"

    A simple callback which is called once when the strategy is loaded. This can be used to perform actions that must only be performed once and runs after dataprovider and wallet are set

    import requests\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def bot_start(self, **kwargs) -> None:\n        \"\"\"\n        Called only once after bot instantiation.\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        \"\"\"\n        if self.config[\"runmode\"].value in (\"live\", \"dry_run\"):\n            # Assign this to the class by using self.*\n            # can then be used by populate_* methods\n            self.custom_remote_data = requests.get(\"https://some_remote_source.example.com\")\n

    During hyperopt, this runs only once at startup.

    "},{"location":"strategy-callbacks/#bot-loop-start","title":"Bot loop start","text":"

    A simple callback which is called once at the start of every bot throttling iteration in dry/live mode (roughly every 5 seconds, unless configured differently) or once per candle in backtest/hyperopt mode. This can be used to perform calculations which are pair independent (apply to all pairs), loading of external data, etc.

    # Default imports\nimport requests\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def bot_loop_start(self, current_time: datetime, **kwargs) -> None:\n        \"\"\"\n        Called at the start of the bot iteration (one loop).\n        Might be used to perform pair-independent tasks\n        (e.g. gather some remote resource for comparison)\n        :param current_time: datetime object, containing the current datetime\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        \"\"\"\n        if self.config[\"runmode\"].value in (\"live\", \"dry_run\"):\n            # Assign this to the class by using self.*\n            # can then be used by populate_* methods\n            self.remote_data = requests.get(\"https://some_remote_source.example.com\")\n
    "},{"location":"strategy-callbacks/#stake-size-management","title":"Stake size management","text":"

    Called before entering a trade, makes it possible to manage your position size when placing a new trade.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            leverage: float, entry_tag: Optional[str], side: str,\n                            **kwargs) -> float:\n\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)\n        current_candle = dataframe.iloc[-1].squeeze()\n\n        if current_candle[\"fastk_rsi_1h\"] > current_candle[\"fastd_rsi_1h\"]:\n            if self.config[\"stake_amount\"] == \"unlimited\":\n                # Use entire available wallet during favorable conditions when in compounding mode.\n                return max_stake\n            else:\n                # Compound profits during favorable conditions instead of using a static stake.\n                return self.wallets.get_total_stake_amount() / self.config[\"max_open_trades\"]\n\n        # Use default stake amount.\n        return proposed_stake\n

    Freqtrade will fall back to the proposed_stake value should your code raise an exception. The exception itself will be logged.

    Tip

    You do not have to ensure that min_stake <= returned_value <= max_stake. Trades will succeed as the returned value will be clamped to supported range and this action will be logged.

    Tip

    Returning 0 or None will prevent trades from being placed.

    "},{"location":"strategy-callbacks/#custom-exit-signal","title":"Custom exit signal","text":"

    Called for open trade every throttling iteration (roughly every 5 seconds) until a trade is closed.

    Allows to define custom exit signals, indicating that specified position should be sold. This is very useful when we need to customize exit conditions for each individual trade, or if you need trade data to make an exit decision.

    For example you could implement a 1:2 risk-reward ROI with custom_exit().

    Using custom_exit() signals in place of stoploss though is not recommended. It is a inferior method to using custom_stoploss() in this regard - which also allows you to keep the stoploss on exchange.

    Note

    Returning a (none-empty) string or True from this method is equal to setting exit signal on a candle at specified time. This method is not called when exit signal is set already, or if exit signals are disabled (use_exit_signal=False). string max length is 64 characters. Exceeding this limit will cause the message to be truncated to 64 characters. custom_exit() will ignore exit_profit_only, and will always be called unless use_exit_signal=False, even if there is a new enter signal.

    An example of how we can use different indicators depending on the current profit and also exit trades that were open longer than one day:

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def custom_exit(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,\n                    current_profit: float, **kwargs):\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n\n        # Above 20% profit, sell when rsi < 80\n        if current_profit > 0.2:\n            if last_candle[\"rsi\"] < 80:\n                return \"rsi_below_80\"\n\n        # Between 2% and 10%, sell if EMA-long above EMA-short\n        if 0.02 < current_profit < 0.1:\n            if last_candle[\"emalong\"] > last_candle[\"emashort\"]:\n                return \"ema_long_below_80\"\n\n        # Sell any positions at a loss if they are held for more than one day.\n        if current_profit < 0.0 and (current_time - trade.open_date_utc).days >= 1:\n            return \"unclog\"\n

    See Dataframe access for more information about dataframe use in strategy callbacks.

    "},{"location":"strategy-callbacks/#custom-stoploss","title":"Custom stoploss","text":"

    Called for open trade every iteration (roughly every 5 seconds) until a trade is closed.

    The usage of the custom stoploss method must be enabled by setting use_custom_stoploss=True on the strategy object.

    The stoploss price can only ever move upwards - if the stoploss value returned from custom_stoploss would result in a lower stoploss price than was previously set, it will be ignored. The traditional stoploss value serves as an absolute lower level and will be instated as the initial stoploss (before this method is called for the first time for a trade), and is still mandatory.

    The method must return a stoploss value (float / number) as a percentage of the current price. E.g. If the current_rate is 200 USD, then returning 0.02 will set the stoploss price 2% lower, at 196 USD. During backtesting, current_rate (and current_profit) are provided against the candle's high (or low for short trades) - while the resulting stoploss is evaluated against the candle's low (or high for short trades).

    The absolute value of the return value is used (the sign is ignored), so returning 0.05 or -0.05 have the same result, a stoploss 5% below the current price. Returning None will be interpreted as \"no desire to change\", and is the only safe way to return when you'd like to not modify the stoploss. NaN and inf values are considered invalid and will be ignored (identical to None).

    Stoploss on exchange works similar to trailing_stop, and the stoploss on exchange is updated as configured in stoploss_on_exchange_interval (More details about stoploss on exchange).

    Use of dates

    All time-based calculations should be done based on current_time - using datetime.now() or datetime.utcnow() is discouraged, as this will break backtesting support.

    Trailing stoploss

    It's recommended to disable trailing_stop when using custom stoploss values. Both can work in tandem, but you might encounter the trailing stop to move the price higher while your custom function would not want this, causing conflicting behavior.

    "},{"location":"strategy-callbacks/#adjust-stoploss-after-position-adjustments","title":"Adjust stoploss after position adjustments","text":"

    Depending on your strategy, you may encounter the need to adjust the stoploss in both directions after a position adjustment. For this, freqtrade will make an additional call with after_fill=True after an order fills, which will allow the strategy to move the stoploss in any direction (also widening the gap between stoploss and current price, which is otherwise forbidden).

    backwards compatibility

    This call will only be made if the after_fill parameter is part of the function definition of your custom_stoploss function. As such, this will not impact (and with that, surprise) existing, running strategies.

    "},{"location":"strategy-callbacks/#custom-stoploss-examples","title":"Custom stoploss examples","text":"

    The next section will show some examples on what's possible with the custom stoploss function. Of course, many more things are possible, and all examples can be combined at will.

    "},{"location":"strategy-callbacks/#trailing-stop-via-custom-stoploss","title":"Trailing stop via custom stoploss","text":"

    To simulate a regular trailing stoploss of 4% (trailing 4% behind the maximum reached price) you would use the following very simple method:

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n        \"\"\"\n        Custom stoploss logic, returning the new distance relative to current_rate (as ratio).\n        e.g. returning -0.05 would create a stoploss 5% below current_rate.\n        The custom stoploss can never be below self.stoploss, which serves as a hard maximum loss.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns the initial stoploss value.\n        Only called when use_custom_stoploss is set to True.\n\n        :param pair: Pair that's currently analyzed\n        :param trade: trade object.\n        :param current_time: datetime object, containing the current datetime\n        :param current_rate: Rate, calculated based on pricing settings in exit_pricing.\n        :param current_profit: Current profit (as ratio), calculated based on current_rate.\n        :param after_fill: True if the stoploss is called after the order was filled.\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return float: New stoploss value, relative to the current_rate\n        \"\"\"\n        return -0.04\n
    "},{"location":"strategy-callbacks/#time-based-trailing-stop","title":"Time based trailing stop","text":"

    Use the initial stoploss for the first 60 minutes, after this change to 10% trailing stoploss, and after 2 hours (120 minutes) we use a 5% trailing stoploss.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n\n        # Make sure you have the longest interval first - these conditions are evaluated from top to bottom.\n        if current_time - timedelta(minutes=120) > trade.open_date_utc:\n            return -0.05\n        elif current_time - timedelta(minutes=60) > trade.open_date_utc:\n            return -0.10\n        return None\n
    "},{"location":"strategy-callbacks/#time-based-trailing-stop-with-after-fill-adjustments","title":"Time based trailing stop with after-fill adjustments","text":"

    Use the initial stoploss for the first 60 minutes, after this change to 10% trailing stoploss, and after 2 hours (120 minutes) we use a 5% trailing stoploss. If an additional order fills, set stoploss to -10% below the new open_rate (Averaged across all entries).

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n\n        if after_fill: \n            # After an additional order, start with a stoploss of 10% below the new open rate\n            return stoploss_from_open(0.10, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n        # Make sure you have the longest interval first - these conditions are evaluated from top to bottom.\n        if current_time - timedelta(minutes=120) > trade.open_date_utc:\n            return -0.05\n        elif current_time - timedelta(minutes=60) > trade.open_date_utc:\n            return -0.10\n        return None\n
    "},{"location":"strategy-callbacks/#different-stoploss-per-pair","title":"Different stoploss per pair","text":"

    Use a different stoploss depending on the pair. In this example, we'll trail the highest price with 10% trailing stoploss for ETH/BTC and XRP/BTC, with 5% trailing stoploss for LTC/BTC and with 15% for all other pairs.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        if pair in (\"ETH/BTC\", \"XRP/BTC\"):\n            return -0.10\n        elif pair in (\"LTC/BTC\"):\n            return -0.05\n        return -0.15\n
    "},{"location":"strategy-callbacks/#trailing-stoploss-with-positive-offset","title":"Trailing stoploss with positive offset","text":"

    Use the initial stoploss until the profit is above 4%, then use a trailing stoploss of 50% of the current profit with a minimum of 2.5% and a maximum of 5%.

    Please note that the stoploss can only increase, values lower than the current stoploss are ignored.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        if current_profit < 0.04:\n            return None # return None to keep using the initial stoploss\n\n        # After reaching the desired offset, allow the stoploss to trail by half the profit\n        desired_stoploss = current_profit / 2\n\n        # Use a minimum of 2.5% and a maximum of 5%\n        return max(min(desired_stoploss, 0.05), 0.025)\n
    "},{"location":"strategy-callbacks/#stepped-stoploss","title":"Stepped stoploss","text":"

    Instead of continuously trailing behind the current price, this example sets fixed stoploss price levels based on the current profit.

    • Use the regular stoploss until 20% profit is reached
    • Once profit is > 20% - set stoploss to 7% above open price.
    • Once profit is > 25% - set stoploss to 15% above open price.
    • Once profit is > 40% - set stoploss to 25% above open price.
    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        # evaluate highest to lowest, so that highest possible stop is used\n        if current_profit > 0.40:\n            return stoploss_from_open(0.25, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n        elif current_profit > 0.25:\n            return stoploss_from_open(0.15, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n        elif current_profit > 0.20:\n            return stoploss_from_open(0.07, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n\n        # return maximum stoploss value, keeping current stoploss price unchanged\n        return None\n
    "},{"location":"strategy-callbacks/#custom-stoploss-using-an-indicator-from-dataframe-example","title":"Custom stoploss using an indicator from dataframe example","text":"

    Absolute stoploss value may be derived from indicators stored in dataframe. Example uses parabolic SAR below the price as stoploss.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # <...>\n        dataframe[\"sar\"] = ta.SAR(dataframe)\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n\n        # Use parabolic sar as absolute stoploss price\n        stoploss_price = last_candle[\"sar\"]\n\n        # Convert absolute price to percentage relative to current_rate\n        if stoploss_price < current_rate:\n            return stoploss_from_absolute(stoploss_price, current_rate, is_short=trade.is_short)\n\n        # return maximum stoploss value, keeping current stoploss price unchanged\n        return None\n

    See Dataframe access for more information about dataframe use in strategy callbacks.

    "},{"location":"strategy-callbacks/#common-helpers-for-stoploss-calculations","title":"Common helpers for stoploss calculations","text":""},{"location":"strategy-callbacks/#stoploss-relative-to-open-price","title":"Stoploss relative to open price","text":"

    Stoploss values returned from custom_stoploss() must specify a percentage relative to current_rate, but sometimes you may want to specify a stoploss relative to the entry price instead. stoploss_from_open() is a helper function to calculate a stoploss value that can be returned from custom_stoploss which will be equivalent to the desired trade profit above the entry point.

    Returning a stoploss relative to the open price from the custom stoploss function

    Say the open price was $100, and current_price is $121 (current_profit will be 0.21).

    If we want a stop price at 7% above the open price we can call stoploss_from_open(0.07, current_profit, False) which will return 0.1157024793. 11.57% below $121 is $107, which is the same as 7% above $100.

    This function will consider leverage - so at 10x leverage, the actual stoploss would be 0.7% above $100 (0.7% * 10x = 7%).

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    use_custom_stoploss = True\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n\n        # once the profit has risen above 10%, keep the stoploss at 7% above the open price\n        if current_profit > 0.10:\n            return stoploss_from_open(0.07, current_profit, is_short=trade.is_short, leverage=trade.leverage)\n\n        return 1\n

    Full examples can be found in the Custom stoploss section of the Documentation.

    Note

    Providing invalid input to stoploss_from_open() may produce \"CustomStoploss function did not return valid stoploss\" warnings. This may happen if current_profit parameter is below specified open_relative_stop. Such situations may arise when closing trade is blocked by confirm_trade_exit() method. Warnings can be solved by never blocking stop loss sells by checking exit_reason in confirm_trade_exit(), or by using return stoploss_from_open(...) or 1 idiom, which will request to not change stop loss when current_profit < open_relative_stop.

    "},{"location":"strategy-callbacks/#stoploss-percentage-from-absolute-price","title":"Stoploss percentage from absolute price","text":"

    Stoploss values returned from custom_stoploss() always specify a percentage relative to current_rate. In order to set a stoploss at specified absolute price level, we need to use stop_rate to calculate what percentage relative to the current_rate will give you the same result as if the percentage was specified from the open price.

    The helper function stoploss_from_absolute() can be used to convert from an absolute price, to a current price relative stop which can be returned from custom_stoploss().

    Returning a stoploss using absolute price from the custom stoploss function

    If we want to trail a stop price at 2xATR below current price we can call stoploss_from_absolute(current_rate + (side * candle[\"atr\"] * 2), current_rate=current_rate, is_short=trade.is_short, leverage=trade.leverage). For futures, we need to adjust the direction (up or down), as well as adjust for leverage, since the custom_stoploss callback returns the \"risk for this trade\" - not the relative price movement.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    use_custom_stoploss = True\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe[\"atr\"] = ta.ATR(dataframe, timeperiod=14)\n        return dataframe\n\n    def custom_stoploss(self, pair: str, trade: Trade, current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool,\n                        **kwargs) -> Optional[float]:\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        trade_date = timeframe_to_prev_date(self.timeframe, trade.open_date_utc)\n        candle = dataframe.iloc[-1].squeeze()\n        side = 1 if trade.is_short else -1\n        return stoploss_from_absolute(current_rate + (side * candle[\"atr\"] * 2), \n                                      current_rate=current_rate, \n                                      is_short=trade.is_short,\n                                      leverage=trade.leverage)\n
    "},{"location":"strategy-callbacks/#custom-order-price-rules","title":"Custom order price rules","text":"

    By default, freqtrade use the orderbook to automatically set an order price(Relevant documentation), you also have the option to create custom order prices based on your strategy.

    You can use this feature by creating a custom_entry_price() function in your strategy file to customize entry prices and custom_exit_price() for exits.

    Each of these methods are called right before placing an order on the exchange.

    Note

    If your custom pricing function return None or an invalid value, price will fall back to proposed_rate, which is based on the regular pricing configuration.

    Note

    Using custom_entry_price, the Trade object will be available as soon as the first entry order associated with the trade is created, for the first entry, trade parameter value will be None.

    "},{"location":"strategy-callbacks/#custom-order-entry-and-exit-price-example","title":"Custom order entry and exit price example","text":"
    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def custom_entry_price(self, pair: str, trade: Optional[Trade], current_time: datetime, proposed_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n\n        dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair,\n                                                                timeframe=self.timeframe)\n        new_entryprice = dataframe[\"bollinger_10_lowerband\"].iat[-1]\n\n        return new_entryprice\n\n    def custom_exit_price(self, pair: str, trade: Trade,\n                          current_time: datetime, proposed_rate: float,\n                          current_profit: float, exit_tag: Optional[str], **kwargs) -> float:\n\n        dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair,\n                                                                timeframe=self.timeframe)\n        new_exitprice = dataframe[\"bollinger_10_upperband\"].iat[-1]\n\n        return new_exitprice\n

    Warning

    Modifying entry and exit prices will only work for limit orders. Depending on the price chosen, this can result in a lot of unfilled orders. By default the maximum allowed distance between the current price and the custom price is 2%, this value can be changed in config with the custom_price_max_distance_ratio parameter. Example: If the new_entryprice is 97, the proposed_rate is 100 and the custom_price_max_distance_ratio is set to 2%, The retained valid custom entry price will be 98, which is 2% below the current (proposed) rate.

    Backtesting

    Custom prices are supported in backtesting (starting with 2021.12), and orders will fill if the price falls within the candle's low/high range. Orders that don't fill immediately are subject to regular timeout handling, which happens once per (detail) candle. custom_exit_price() is only called for sells of type exit_signal, Custom exit and partial exits. All other exit-types will use regular backtesting prices.

    "},{"location":"strategy-callbacks/#custom-order-timeout-rules","title":"Custom order timeout rules","text":"

    Simple, time-based order-timeouts can be configured either via strategy or in the configuration in the unfilledtimeout section.

    However, freqtrade also offers a custom callback for both order types, which allows you to decide based on custom criteria if an order did time out or not.

    Note

    Backtesting fills orders if their price falls within the candle's low/high range. The below callbacks will be called once per (detail) candle for orders that don't fill immediately (which use custom pricing).

    "},{"location":"strategy-callbacks/#custom-order-timeout-example","title":"Custom order timeout example","text":"

    Called for every open order until that order is either filled or cancelled. check_entry_timeout() is called for trade entries, while check_exit_timeout() is called for trade exit orders.

    A simple example, which applies different unfilled-timeouts depending on the price of the asset can be seen below. It applies a tight timeout for higher priced assets, while allowing more time to fill on cheap coins.

    The function must return either True (cancel order) or False (keep order alive).

        # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    # Set unfilledtimeout to 25 hours, since the maximum timeout from below is 24 hours.\n    unfilledtimeout = {\n        \"entry\": 60 * 25,\n        \"exit\": 60 * 25\n    }\n\n    def check_entry_timeout(self, pair: str, trade: Trade, order: Order,\n                            current_time: datetime, **kwargs) -> bool:\n        if trade.open_rate > 100 and trade.open_date_utc < current_time - timedelta(minutes=5):\n            return True\n        elif trade.open_rate > 10 and trade.open_date_utc < current_time - timedelta(minutes=3):\n            return True\n        elif trade.open_rate < 1 and trade.open_date_utc < current_time - timedelta(hours=24):\n           return True\n        return False\n\n\n    def check_exit_timeout(self, pair: str, trade: Trade, order: Order,\n                           current_time: datetime, **kwargs) -> bool:\n        if trade.open_rate > 100 and trade.open_date_utc < current_time - timedelta(minutes=5):\n            return True\n        elif trade.open_rate > 10 and trade.open_date_utc < current_time - timedelta(minutes=3):\n            return True\n        elif trade.open_rate < 1 and trade.open_date_utc < current_time - timedelta(hours=24):\n           return True\n        return False\n

    Note

    For the above example, unfilledtimeout must be set to something bigger than 24h, otherwise that type of timeout will apply first.

    "},{"location":"strategy-callbacks/#custom-order-timeout-example-using-additional-data","title":"Custom order timeout example (using additional data)","text":"
        # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    # Set unfilledtimeout to 25 hours, since the maximum timeout from below is 24 hours.\n    unfilledtimeout = {\n        \"entry\": 60 * 25,\n        \"exit\": 60 * 25\n    }\n\n    def check_entry_timeout(self, pair: str, trade: Trade, order: Order,\n                            current_time: datetime, **kwargs) -> bool:\n        ob = self.dp.orderbook(pair, 1)\n        current_price = ob[\"bids\"][0][0]\n        # Cancel buy order if price is more than 2% above the order.\n        if current_price > order.price * 1.02:\n            return True\n        return False\n\n\n    def check_exit_timeout(self, pair: str, trade: Trade, order: Order,\n                           current_time: datetime, **kwargs) -> bool:\n        ob = self.dp.orderbook(pair, 1)\n        current_price = ob[\"asks\"][0][0]\n        # Cancel sell order if price is more than 2% below the order.\n        if current_price < order.price * 0.98:\n            return True\n        return False\n
    "},{"location":"strategy-callbacks/#bot-order-confirmation","title":"Bot order confirmation","text":"

    Confirm trade entry / exits. This are the last methods that will be called before an order is placed.

    "},{"location":"strategy-callbacks/#trade-entry-buy-order-confirmation","title":"Trade entry (buy order) confirmation","text":"

    confirm_trade_entry() can be used to abort a trade entry at the latest second (maybe because the price is not what we expect).

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,\n                            time_in_force: str, current_time: datetime, entry_tag: Optional[str],\n                            side: str, **kwargs) -> bool:\n        \"\"\"\n        Called right before placing a entry order.\n        Timing for this function is critical, so avoid doing heavy computations or\n        network requests in this method.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns True (always confirming).\n\n        :param pair: Pair that's about to be bought/shorted.\n        :param order_type: Order type (as configured in order_types). usually limit or market.\n        :param amount: Amount in target (base) currency that's going to be traded.\n        :param rate: Rate that's going to be used when using limit orders \n                     or current rate for market orders.\n        :param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).\n        :param current_time: datetime object, containing the current datetime\n        :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.\n        :param side: \"long\" or \"short\" - indicating the direction of the proposed trade\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return bool: When True is returned, then the buy-order is placed on the exchange.\n            False aborts the process\n        \"\"\"\n        return True\n
    "},{"location":"strategy-callbacks/#trade-exit-sell-order-confirmation","title":"Trade exit (sell order) confirmation","text":"

    confirm_trade_exit() can be used to abort a trade exit (sell) at the latest second (maybe because the price is not what we expect).

    confirm_trade_exit() may be called multiple times within one iteration for the same trade if different exit-reasons apply. The exit-reasons (if applicable) will be in the following sequence:

    • exit_signal / custom_exit
    • stop_loss
    • roi
    • trailing_stop_loss
    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,\n                           rate: float, time_in_force: str, exit_reason: str,\n                           current_time: datetime, **kwargs) -> bool:\n        \"\"\"\n        Called right before placing a regular exit order.\n        Timing for this function is critical, so avoid doing heavy computations or\n        network requests in this method.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns True (always confirming).\n\n        :param pair: Pair for trade that's about to be exited.\n        :param trade: trade object.\n        :param order_type: Order type (as configured in order_types). usually limit or market.\n        :param amount: Amount in base currency.\n        :param rate: Rate that's going to be used when using limit orders\n                     or current rate for market orders.\n        :param time_in_force: Time in force. Defaults to GTC (Good-til-cancelled).\n        :param exit_reason: Exit reason.\n            Can be any of [\"roi\", \"stop_loss\", \"stoploss_on_exchange\", \"trailing_stop_loss\",\n                           \"exit_signal\", \"force_exit\", \"emergency_exit\"]\n        :param current_time: datetime object, containing the current datetime\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return bool: When True, then the exit-order is placed on the exchange.\n            False aborts the process\n        \"\"\"\n        if exit_reason == \"force_exit\" and trade.calc_profit_ratio(rate) < 0:\n            # Reject force-sells with negative profit\n            # This is just a sample, please adjust to your needs\n            # (this does not necessarily make sense, assuming you know when you're force-selling)\n            return False\n        return True\n

    Warning

    confirm_trade_exit() can prevent stoploss exits, causing significant losses as this would ignore stoploss exits. confirm_trade_exit() will not be called for Liquidations - as liquidations are forced by the exchange, and therefore cannot be rejected.

    "},{"location":"strategy-callbacks/#adjust-trade-position","title":"Adjust trade position","text":"

    The position_adjustment_enable strategy property enables the usage of adjust_trade_position() callback in the strategy. For performance reasons, it's disabled by default and freqtrade will show a warning message on startup if enabled. adjust_trade_position() can be used to perform additional orders, for example to manage risk with DCA (Dollar Cost Averaging) or to increase or decrease positions.

    Additional orders also result in additional fees and those orders don't count towards max_open_trades.

    This callback is not called when there is an open order (either buy or sell) waiting for execution.

    adjust_trade_position() is called very frequently for the duration of a trade, so you must keep your implementation as performant as possible.

    Position adjustments will always be applied in the direction of the trade, so a positive value will always increase your position (negative values will decrease your position), no matter if it's a long or short trade. Adjustment orders can be assigned with a tag by returning a 2 element Tuple, with the first element being the adjustment amount, and the 2nd element the tag (e.g. return 250, \"increase_favorable_conditions\").

    Modifications to leverage are not possible, and the stake-amount returned is assumed to be before applying leverage.

    "},{"location":"strategy-callbacks/#increase-position","title":"Increase position","text":"

    The strategy is expected to return a positive stake_amount (in stake currency) between min_stake and max_stake if and when an additional entry order should be made (position is increased -> buy order for long trades, sell order for short trades).

    If there are not enough funds in the wallet (the return value is above max_stake) then the signal will be ignored. max_entry_position_adjustment property is used to limit the number of additional entries per trade (on top of the first entry order) that the bot can execute. By default, the value is -1 which means the bot have no limit on number of adjustment entries.

    Additional entries are ignored once you have reached the maximum amount of extra entries that you have set on max_entry_position_adjustment, but the callback is called anyway looking for partial exits.

    "},{"location":"strategy-callbacks/#decrease-position","title":"Decrease position","text":"

    The strategy is expected to return a negative stake_amount (in stake currency) for a partial exit. Returning the full owned stake at that point (-trade.stake_amount) results in a full exit. Returning a value more than the above (so remaining stake_amount would become negative) will result in the bot ignoring the signal.

    About stake size

    Using fixed stake size means it will be the amount used for the first order, just like without position adjustment. If you wish to buy additional orders with DCA, then make sure to leave enough funds in the wallet for that. Using \"unlimited\" stake amount with DCA orders requires you to also implement the custom_stake_amount() callback to avoid allocating all funds to the initial order.

    Stoploss calculation

    Stoploss is still calculated from the initial opening price, not averaged price. Regular stoploss rules still apply (cannot move down).

    While /stopentry command stops the bot from entering new trades, the position adjustment feature will continue buying new orders on existing trades.

    Backtesting

    During backtesting this callback is called for each candle in timeframe or timeframe_detail, so run-time performance will be affected. This can also cause deviating results between live and backtesting, since backtesting can adjust the trade only once per candle, whereas live could adjust the trade multiple times per candle.

    Performance with many position adjustments

    Position adjustments can be a good approach to increase a strategy's output - but it can also have drawbacks if using this feature extensively. Each of the orders will be attached to the trade object for the duration of the trade - hence increasing memory usage. Trades with long duration and 10s or even 100ds of position adjustments are therefore not recommended, and should be closed at regular intervals to not affect performance.

    # Default imports\n\nclass DigDeeperStrategy(IStrategy):\n\n    position_adjustment_enable = True\n\n    # Attempts to handle large drops with DCA. High stoploss is required.\n    stoploss = -0.30\n\n    # ... populate_* methods\n\n    # Example specific variables\n    max_entry_position_adjustment = 3\n    # This number is explained a bit further down\n    max_dca_multiplier = 5.5\n\n    # This is called when placing the initial order (opening trade)\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            leverage: float, entry_tag: Optional[str], side: str,\n                            **kwargs) -> float:\n\n        # We need to leave most of the funds for possible further DCA orders\n        # This also applies to fixed stakes\n        return proposed_stake / self.max_dca_multiplier\n\n    def adjust_trade_position(self, trade: Trade, current_time: datetime,\n                              current_rate: float, current_profit: float,\n                              min_stake: Optional[float], max_stake: float,\n                              current_entry_rate: float, current_exit_rate: float,\n                              current_entry_profit: float, current_exit_profit: float,\n                              **kwargs\n                              ) -> Union[Optional[float], Tuple[Optional[float], Optional[str]]]:\n        \"\"\"\n        Custom trade adjustment logic, returning the stake amount that a trade should be\n        increased or decreased.\n        This means extra entry or exit orders with additional fees.\n        Only called when `position_adjustment_enable` is set to True.\n\n        For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/\n\n        When not implemented by a strategy, returns None\n\n        :param trade: trade object.\n        :param current_time: datetime object, containing the current datetime\n        :param current_rate: Current entry rate (same as current_entry_profit)\n        :param current_profit: Current profit (as ratio), calculated based on current_rate \n                               (same as current_entry_profit).\n        :param min_stake: Minimal stake size allowed by exchange (for both entries and exits)\n        :param max_stake: Maximum stake allowed (either through balance, or by exchange limits).\n        :param current_entry_rate: Current rate using entry pricing.\n        :param current_exit_rate: Current rate using exit pricing.\n        :param current_entry_profit: Current profit using entry pricing.\n        :param current_exit_profit: Current profit using exit pricing.\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return float: Stake amount to adjust your trade,\n                       Positive values to increase position, Negative values to decrease position.\n                       Return None for no action.\n                       Optionally, return a tuple with a 2nd element with an order reason\n        \"\"\"\n\n        if current_profit > 0.05 and trade.nr_of_successful_exits == 0:\n            # Take half of the profit at +5%\n            return -(trade.stake_amount / 2), \"half_profit_5%\"\n\n        if current_profit > -0.05:\n            return None\n\n        # Obtain pair dataframe (just to show how to access it)\n        dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)\n        # Only buy when not actively falling price.\n        last_candle = dataframe.iloc[-1].squeeze()\n        previous_candle = dataframe.iloc[-2].squeeze()\n        if last_candle[\"close\"] < previous_candle[\"close\"]:\n            return None\n\n        filled_entries = trade.select_filled_orders(trade.entry_side)\n        count_of_entries = trade.nr_of_successful_entries\n        # Allow up to 3 additional increasingly larger buys (4 in total)\n        # Initial buy is 1x\n        # If that falls to -5% profit, we buy 1.25x more, average profit should increase to roughly -2.2%\n        # If that falls down to -5% again, we buy 1.5x more\n        # If that falls once again down to -5%, we buy 1.75x more\n        # Total stake for this trade would be 1 + 1.25 + 1.5 + 1.75 = 5.5x of the initial allowed stake.\n        # That is why max_dca_multiplier is 5.5\n        # Hope you have a deep wallet!\n        try:\n            # This returns first order stake size\n            stake_amount = filled_entries[0].stake_amount\n            # This then calculates current safety order size\n            stake_amount = stake_amount * (1 + (count_of_entries * 0.25))\n            return stake_amount, \"1/3rd_increase\"\n        except Exception as exception:\n            return None\n\n        return None\n
    "},{"location":"strategy-callbacks/#position-adjust-calculations","title":"Position adjust calculations","text":"
    • Entry rates are calculated using weighted averages.
    • Exits will not influence the average entry rate.
    • Partial exit relative profit is relative to the average entry price at this point.
    • Final exit relative profit is calculated based on the total invested capital. (See example below)
    Calculation example

    This example assumes 0 fees for simplicity, and a long position on an imaginary coin.

    • Buy 100@8$
    • Buy 100@9$ -> Avg price: 8.5$
    • Sell 100@10$ -> Avg price: 8.5$, realized profit 150$, 17.65%
    • Buy 150@11$ -> Avg price: 10$, realized profit 150$, 17.65%
    • Sell 100@12$ -> Avg price: 10$, total realized profit 350$, 20%
    • Sell 150@14$ -> Avg price: 10$, total realized profit 950$, 40% <- This will be the last \"Exit\" message

    The total profit for this trade was 950$ on a 3350$ investment (100@8$ + 100@9$ + 150@11$). As such - the final relative profit is 28.35% (950 / 3350).

    "},{"location":"strategy-callbacks/#adjust-entry-price","title":"Adjust Entry Price","text":"

    The adjust_entry_price() callback may be used by strategy developer to refresh/replace limit orders upon arrival of new candles. Be aware that custom_entry_price() is still the one dictating initial entry limit order price target at the time of entry trigger.

    Orders can be cancelled out of this callback by returning None.

    Returning current_order_rate will keep the order on the exchange \"as is\". Returning any other price will cancel the existing order, and replace it with a new order.

    The trade open-date (trade.open_date_utc) will remain at the time of the very first order placed. Please make sure to be aware of this - and eventually adjust your logic in other callbacks to account for this, and use the date of the first filled order instead.

    If the cancellation of the original order fails, then the order will not be replaced - though the order will most likely have been canceled on exchange. Having this happen on initial entries will result in the deletion of the order, while on position adjustment orders, it'll result in the trade size remaining as is.

    Regular timeout

    Entry unfilledtimeout mechanism (as well as check_entry_timeout()) takes precedence over this. Entry Orders that are cancelled via the above methods will not have this callback called. Be sure to update timeout values to match your expectations.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n\n    # ... populate_* methods\n\n    def adjust_entry_price(self, trade: Trade, order: Optional[Order], pair: str,\n                           current_time: datetime, proposed_rate: float, current_order_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n        \"\"\"\n        Entry price re-adjustment logic, returning the user desired limit price.\n        This only executes when a order was already placed, still open (unfilled fully or partially)\n        and not timed out on subsequent candles after entry trigger.\n\n        When not implemented by a strategy, returns current_order_rate as default.\n        If current_order_rate is returned then the existing order is maintained.\n        If None is returned then order gets canceled but not replaced by a new one.\n\n        :param pair: Pair that's currently analyzed\n        :param trade: Trade object.\n        :param order: Order object\n        :param current_time: datetime object, containing the current datetime\n        :param proposed_rate: Rate, calculated based on pricing settings in entry_pricing.\n        :param current_order_rate: Rate of the existing order in place.\n        :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.\n        :param side: \"long\" or \"short\" - indicating the direction of the proposed trade\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        :return float: New entry price value if provided\n\n        \"\"\"\n        # Limit orders to use and follow SMA200 as price target for the first 10 minutes since entry trigger for BTC/USDT pair.\n        if (\n            pair == \"BTC/USDT\" \n            and entry_tag == \"long_sma200\" \n            and side == \"long\" \n            and (current_time - timedelta(minutes=10)) > trade.open_date_utc\n        ):\n            # just cancel the order if it has been filled more than half of the amount\n            if order.filled > order.remaining:\n                return None\n            else:\n                dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)\n                current_candle = dataframe.iloc[-1].squeeze()\n                # desired price\n                return current_candle[\"sma_200\"]\n        # default: maintain existing order\n        return current_order_rate\n
    "},{"location":"strategy-callbacks/#leverage-callback","title":"Leverage Callback","text":"

    When trading in markets that allow leverage, this method must return the desired Leverage (Defaults to 1 -> No leverage).

    Assuming a capital of 500USDT, a trade with leverage=3 would result in a position with 500 x 3 = 1500 USDT.

    Values that are above max_leverage will be adjusted to max_leverage. For markets / exchanges that don't support leverage, this method is ignored.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def leverage(self, pair: str, current_time: datetime, current_rate: float,\n                 proposed_leverage: float, max_leverage: float, entry_tag: Optional[str], side: str,\n                 **kwargs) -> float:\n        \"\"\"\n        Customize leverage for each new trade. This method is only called in futures mode.\n\n        :param pair: Pair that's currently analyzed\n        :param current_time: datetime object, containing the current datetime\n        :param current_rate: Rate, calculated based on pricing settings in exit_pricing.\n        :param proposed_leverage: A leverage proposed by the bot.\n        :param max_leverage: Max leverage allowed on this pair\n        :param entry_tag: Optional entry_tag (buy_tag) if provided with the buy signal.\n        :param side: \"long\" or \"short\" - indicating the direction of the proposed trade\n        :return: A leverage amount, which is between 1.0 and max_leverage.\n        \"\"\"\n        return 1.0\n

    All profit calculations include leverage. Stoploss / ROI also include leverage in their calculation. Defining a stoploss of 10% at 10x leverage would trigger the stoploss with a 1% move to the downside.

    "},{"location":"strategy-callbacks/#order-filled-callback","title":"Order filled Callback","text":"

    The order_filled() callback may be used to perform specific actions based on the current trade state after an order is filled. It will be called independent of the order type (entry, exit, stoploss or position adjustment).

    Assuming that your strategy needs to store the high value of the candle at trade entry, this is possible with this callback as the following example show.

    # Default imports\n\nclass AwesomeStrategy(IStrategy):\n    def order_filled(self, pair: str, trade: Trade, order: Order, current_time: datetime, **kwargs) -> None:\n        \"\"\"\n        Called right after an order fills. \n        Will be called for all order types (entry, exit, stoploss, position adjustment).\n        :param pair: Pair for trade\n        :param trade: trade object.\n        :param order: Order object.\n        :param current_time: datetime object, containing the current datetime\n        :param **kwargs: Ensure to keep this here so updates to this won't break your strategy.\n        \"\"\"\n        # Obtain pair dataframe (just to show how to access it)\n        dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n\n        if (trade.nr_of_successful_entries == 1) and (order.ft_order_side == trade.entry_side):\n            trade.set_custom_data(key=\"entry_candle_high\", value=last_candle[\"high\"])\n\n        return None\n
    "},{"location":"strategy-customization/","title":"Strategy Customization","text":"

    This page explains how to customize your strategies, add new indicators and set up trading rules.

    Please familiarize yourself with Freqtrade basics first, which provides overall info on how the bot operates.

    "},{"location":"strategy-customization/#develop-your-own-strategy","title":"Develop your own strategy","text":"

    The bot includes a default strategy file. Also, several other strategies are available in the strategy repository.

    You will however most likely have your own idea for a strategy. This document intends to help you convert your strategy idea into your own strategy.

    To get started, use freqtrade new-strategy --strategy AwesomeStrategy (you can obviously use your own naming for your strategy). This will create a new strategy file from a template, which will be located under user_data/strategies/AwesomeStrategy.py.

    Note

    This is just a template file, which will most likely not be profitable out of the box.

    Different template levels

    freqtrade new-strategy has an additional parameter, --template, which controls the amount of pre-build information you get in the created strategy. Use --template minimal to get an empty strategy without any indicator examples, or --template advanced to get a template with most callbacks defined.

    "},{"location":"strategy-customization/#anatomy-of-a-strategy","title":"Anatomy of a strategy","text":"

    A strategy file contains all the information needed to build a good strategy:

    • Indicators
    • Entry strategy rules
    • Exit strategy rules
    • Minimal ROI recommended
    • Stoploss strongly recommended

    The bot also include a sample strategy called SampleStrategy you can update: user_data/strategies/sample_strategy.py. You can test it with the parameter: --strategy SampleStrategy

    Additionally, there is an attribute called INTERFACE_VERSION, which defines the version of the strategy interface the bot should use. The current version is 3 - which is also the default when it's not set explicitly in the strategy.

    Future versions will require this to be set.

    freqtrade trade --strategy AwesomeStrategy\n

    For the following section we will use the user_data/strategies/sample_strategy.py file as reference.

    Strategies and Backtesting

    To avoid problems and unexpected differences between Backtesting and dry/live modes, please be aware that during backtesting the full time range is passed to the populate_*() methods at once. It is therefore best to use vectorized operations (across the whole dataframe, not loops) and avoid index referencing (df.iloc[-1]), but instead use df.shift() to get to the previous candle.

    Warning: Using future data

    Since backtesting passes the full time range to the populate_*() methods, the strategy author needs to take care to avoid having the strategy utilize data from the future. Some common patterns for this are listed in the Common Mistakes section of this document.

    "},{"location":"strategy-customization/#dataframe","title":"Dataframe","text":"

    Freqtrade uses pandas to store/provide the candlestick (OHLCV) data. Pandas is a great library developed for processing large amounts of data.

    Each row in a dataframe corresponds to one candle on a chart, with the latest candle always being the last in the dataframe (sorted by date).

    > dataframe.head()\n                       date      open      high       low     close     volume\n0 2021-11-09 23:25:00+00:00  67279.67  67321.84  67255.01  67300.97   44.62253\n1 2021-11-09 23:30:00+00:00  67300.97  67301.34  67183.03  67187.01   61.38076\n2 2021-11-09 23:35:00+00:00  67187.02  67187.02  67031.93  67123.81  113.42728\n3 2021-11-09 23:40:00+00:00  67123.80  67222.40  67080.33  67160.48   78.96008\n4 2021-11-09 23:45:00+00:00  67160.48  67160.48  66901.26  66943.37  111.39292\n

    Pandas provides fast ways to calculate metrics. To benefit from this speed, it's advised to not use loops, but use vectorized methods instead.

    Vectorized operations perform calculations across the whole range of data and are therefore, compared to looping through each row, a lot faster when calculating indicators.

    As a dataframe is a table, simple python comparisons like the following will not work

        if dataframe['rsi'] > 30:\n        dataframe['enter_long'] = 1\n

    The above section will fail with The truth value of a Series is ambiguous. [...].

    This must instead be written in a pandas-compatible way, so the operation is performed across the whole dataframe.

        dataframe.loc[\n        (dataframe['rsi'] > 30)\n    , 'enter_long'] = 1\n

    With this section, you have a new column in your dataframe, which has 1 assigned whenever RSI is above 30.

    "},{"location":"strategy-customization/#customize-indicators","title":"Customize Indicators","text":"

    Buy and sell signals need indicators. You can add more indicators by extending the list contained in the method populate_indicators() from your strategy file.

    You should only add the indicators used in either populate_entry_trend(), populate_exit_trend(), or to populate another indicator, otherwise performance may suffer.

    It's important to always return the dataframe without removing/modifying the columns \"open\", \"high\", \"low\", \"close\", \"volume\", otherwise these fields would contain something unexpected.

    Sample:

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    \"\"\"\n    Adds several different TA indicators to the given DataFrame\n\n    Performance Note: For the best performance be frugal on the number of indicators\n    you are using. Let uncomment only the indicator you are using in your strategies\n    or your hyperopt configuration, otherwise you will waste your memory and CPU usage.\n    :param dataframe: Dataframe with data from the exchange\n    :param metadata: Additional information, like the currently traded pair\n    :return: a Dataframe with all mandatory indicators for the strategies\n    \"\"\"\n    dataframe['sar'] = ta.SAR(dataframe)\n    dataframe['adx'] = ta.ADX(dataframe)\n    stoch = ta.STOCHF(dataframe)\n    dataframe['fastd'] = stoch['fastd']\n    dataframe['fastk'] = stoch['fastk']\n    dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband']\n    dataframe['sma'] = ta.SMA(dataframe, timeperiod=40)\n    dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)\n    dataframe['mfi'] = ta.MFI(dataframe)\n    dataframe['rsi'] = ta.RSI(dataframe)\n    dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)\n    dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)\n    dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)\n    dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)\n    dataframe['ao'] = awesome_oscillator(dataframe)\n    macd = ta.MACD(dataframe)\n    dataframe['macd'] = macd['macd']\n    dataframe['macdsignal'] = macd['macdsignal']\n    dataframe['macdhist'] = macd['macdhist']\n    hilbert = ta.HT_SINE(dataframe)\n    dataframe['htsine'] = hilbert['sine']\n    dataframe['htleadsine'] = hilbert['leadsine']\n    dataframe['plus_dm'] = ta.PLUS_DM(dataframe)\n    dataframe['plus_di'] = ta.PLUS_DI(dataframe)\n    dataframe['minus_dm'] = ta.MINUS_DM(dataframe)\n    dataframe['minus_di'] = ta.MINUS_DI(dataframe)\n    return dataframe\n

    Want more indicator examples?

    Look into the user_data/strategies/sample_strategy.py. Then uncomment indicators you need.

    "},{"location":"strategy-customization/#indicator-libraries","title":"Indicator libraries","text":"

    Out of the box, freqtrade installs the following technical libraries:

    • ta-lib
    • pandas-ta
    • technical

    Additional technical libraries can be installed as necessary, or custom indicators may be written / invented by the strategy author.

    "},{"location":"strategy-customization/#strategy-startup-period","title":"Strategy startup period","text":"

    Most indicators have an instable startup period, in which they are either not available (NaN), or the calculation is incorrect. This can lead to inconsistencies, since Freqtrade does not know how long this instable period should be. To account for this, the strategy can be assigned the startup_candle_count attribute. This should be set to the maximum number of candles that the strategy requires to calculate stable indicators. In the case where a user includes higher timeframes with informative pairs, the startup_candle_count does not necessarily change. The value is the maximum period (in candles) that any of the informatives timeframes need to compute stable indicators.

    You can use recursive-analysis to check and find the correct startup_candle_count to be used.

    In this example strategy, this should be set to 400 (startup_candle_count = 400), since the minimum needed history for ema100 calculation to make sure the value is correct is 400 candles.

        dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)\n

    By letting the bot know how much history is needed, backtest trades can start at the specified timerange during backtesting and hyperopt.

    Using x calls to get OHLCV

    If you receive a warning like WARNING - Using 3 calls to get OHLCV. This can result in slower operations for the bot. Please check if you really need 1500 candles for your strategy - you should consider if you really need this much historic data for your signals. Having this will cause Freqtrade to make multiple calls for the same pair, which will obviously be slower than one network request. As a consequence, Freqtrade will take longer to refresh candles - and should therefore be avoided if possible. This is capped to 5 total calls to avoid overloading the exchange, or make freqtrade too slow.

    Warning

    startup_candle_count should be below ohlcv_candle_limit * 5 (which is 500 * 5 for most exchanges) - since only this amount of candles will be available during Dry-Run/Live Trade operations.

    "},{"location":"strategy-customization/#example","title":"Example","text":"

    Let's try to backtest 1 month (January 2019) of 5m candles using an example strategy with EMA100, as above.

    freqtrade backtesting --timerange 20190101-20190201 --timeframe 5m\n

    Assuming startup_candle_count is set to 400, backtesting knows it needs 400 candles to generate valid buy signals. It will load data from 20190101 - (400 * 5m) - which is ~2018-12-30 11:40:00. If this data is available, indicators will be calculated with this extended timerange. The instable startup period (up to 2019-01-01 00:00:00) will then be removed before starting backtesting.

    Note

    If data for the startup period is not available, then the timerange will be adjusted to account for this startup period - so Backtesting would start at 2019-01-02 09:20:00.

    "},{"location":"strategy-customization/#entry-signal-rules","title":"Entry signal rules","text":"

    Edit the method populate_entry_trend() in your strategy file to update your entry strategy.

    It's important to always return the dataframe without removing/modifying the columns \"open\", \"high\", \"low\", \"close\", \"volume\", otherwise these fields would contain something unexpected.

    This method will also define a new column, \"enter_long\" (\"enter_short\" for shorts), which needs to contain 1 for entries, and 0 for \"no action\". enter_long is a mandatory column that must be set even if the strategy is shorting only.

    Sample from user_data/strategies/sample_strategy.py:

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    \"\"\"\n    Based on TA indicators, populates the buy signal for the given dataframe\n    :param dataframe: DataFrame populated with indicators\n    :param metadata: Additional information, like the currently traded pair\n    :return: DataFrame with buy column\n    \"\"\"\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n
    Enter short trades

    Short-entries can be created by setting enter_short (corresponds to enter_long for long trades). The enter_tag column remains identical. Short-trades need to be supported by your exchange and market configuration! Please make sure to set can_short appropriately on your strategy if you intend to short.

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n\n    dataframe.loc[\n        (\n            (qtpylib.crossed_below(dataframe['rsi'], 70)) &  # Signal: RSI crosses below 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_short', 'enter_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n

    Note

    Buying requires sellers to buy from - therefore volume needs to be > 0 (dataframe['volume'] > 0) to make sure that the bot does not buy/sell in no-activity periods.

    "},{"location":"strategy-customization/#exit-signal-rules","title":"Exit signal rules","text":"

    Edit the method populate_exit_trend() into your strategy file to update your exit strategy. The exit-signal can be suppressed by setting use_exit_signal to false in the configuration or strategy. use_exit_signal will not influence signal collision rules - which will still apply and can prevent entries.

    It's important to always return the dataframe without removing/modifying the columns \"open\", \"high\", \"low\", \"close\", \"volume\", otherwise these fields would contain something unexpected.

    This method will also define a new column, \"exit_long\" (\"exit_short\" for shorts), which needs to contain 1 for exits, and 0 for \"no action\".

    Sample from user_data/strategies/sample_strategy.py:

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    \"\"\"\n    Based on TA indicators, populates the exit signal for the given dataframe\n    :param dataframe: DataFrame populated with indicators\n    :param metadata: Additional information, like the currently traded pair\n    :return: DataFrame with buy column\n    \"\"\"\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'rsi_too_high')\n    return dataframe\n
    Exit short trades

    Short-exits can be created by setting exit_short (corresponds to exit_long). The exit_tag column remains identical. Short-trades need to be supported by your exchange and market configuration!

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'rsi_too_high')\n    dataframe.loc[\n        (\n            (qtpylib.crossed_below(dataframe['rsi'], 30)) &  # Signal: RSI crosses below 30\n            (dataframe['tema'] < dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_short', 'exit_tag']] = (1, 'rsi_too_low')\n    return dataframe\n
    "},{"location":"strategy-customization/#minimal-roi","title":"Minimal ROI","text":"

    This dict defines the minimal Return On Investment (ROI) a trade should reach before exiting, independent from the exit signal.

    It is of the following format, with the dict key (left side of the colon) being the minutes passed since the trade opened, and the value (right side of the colon) being the percentage.

    minimal_roi = {\n    \"40\": 0.0,\n    \"30\": 0.01,\n    \"20\": 0.02,\n    \"0\": 0.04\n}\n

    The above configuration would therefore mean:

    • Exit whenever 4% profit was reached
    • Exit when 2% profit was reached (in effect after 20 minutes)
    • Exit when 1% profit was reached (in effect after 30 minutes)
    • Exit when trade is non-loosing (in effect after 40 minutes)

    The calculation does include fees.

    To disable ROI completely, set it to an empty dictionary:

    minimal_roi = {}\n

    To use times based on candle duration (timeframe), the following snippet can be handy. This will allow you to change the timeframe for the strategy, and ROI times will still be set as candles (e.g. after 3 candles ...)

    from freqtrade.exchange import timeframe_to_minutes\n\nclass AwesomeStrategy(IStrategy):\n\n    timeframe = \"1d\"\n    timeframe_mins = timeframe_to_minutes(timeframe)\n    minimal_roi = {\n        \"0\": 0.05,                      # 5% for the first 3 candles\n        str(timeframe_mins * 3): 0.02,  # 2% after 3 candles\n        str(timeframe_mins * 6): 0.01,  # 1% After 6 candles\n    }\n
    Orders that don't fill immediately

    minimal_roi will take the trade.open_date as reference, which is the time the trade was initialized / the first order for this trade was placed. This will also hold true for limit orders that don't fill immediately (usually in combination with \"off-spot\" prices through custom_entry_price()), as well as for cases where the initial order is replaced through adjust_entry_price(). The time used will still be from the initial trade.open_date (when the initial order was first placed), not from the newly placed order date.

    "},{"location":"strategy-customization/#stoploss","title":"Stoploss","text":"

    Setting a stoploss is highly recommended to protect your capital from strong moves against you.

    Sample of setting a 10% stoploss:

    stoploss = -0.10\n

    For the full documentation on stoploss features, look at the dedicated stoploss page.

    "},{"location":"strategy-customization/#timeframe","title":"Timeframe","text":"

    This is the set of candles the bot should download and use for the analysis. Common values are \"1m\", \"5m\", \"15m\", \"1h\", however all values supported by your exchange should work.

    Please note that the same entry/exit signals may work well with one timeframe, but not with the others.

    This setting is accessible within the strategy methods as the self.timeframe attribute.

    "},{"location":"strategy-customization/#can-short","title":"Can short","text":"

    To use short signals in futures markets, you will have to let us know to do so by setting can_short=True. Strategies which enable this will fail to load on spot markets. Disabling of this will have short signals ignored (also in futures markets).

    "},{"location":"strategy-customization/#metadata-dict","title":"Metadata dict","text":"

    The metadata-dict (available for populate_entry_trend, populate_exit_trend, populate_indicators) contains additional information. Currently this is pair, which can be accessed using metadata['pair'] - and will return a pair in the format XRP/BTC.

    The Metadata-dict should not be modified and does not persist information across multiple calls. Instead, have a look at the Storing information section.

    "},{"location":"strategy-customization/#imports-necessary-for-a-strategy","title":"Imports necessary for a strategy","text":"

    When creating a strategy, you will need to import the necessary modules and classes. The following imports are required for a strategy:

    By default, we recommend the following imports as a base line for your strategy: This will cover all imports necessary for freqtrade functions to work. Obviously you can add more imports as needed for your strategy.

    # flake8: noqa: F401\n# isort: skip_file\n# --- Do not remove these imports ---\nimport numpy as np\nimport pandas as pd\nfrom datetime import datetime, timedelta, timezone\nfrom pandas import DataFrame\nfrom typing import Dict, Optional, Union, Tuple\n\nfrom freqtrade.strategy import (\n    IStrategy,\n    Trade, \n    Order,\n    PairLocks,\n    informative,  # @informative decorator\n    # Hyperopt Parameters\n    BooleanParameter,\n    CategoricalParameter,\n    DecimalParameter,\n    IntParameter,\n    RealParameter,\n    # timeframe helpers\n    timeframe_to_minutes,\n    timeframe_to_next_date,\n    timeframe_to_prev_date,\n    # Strategy helper functions\n    merge_informative_pair,\n    stoploss_from_absolute,\n    stoploss_from_open,\n)\n\n# --------------------------------\n# Add your lib to import here\nimport talib.abstract as ta\nfrom technical import qtpylib\n
    "},{"location":"strategy-customization/#strategy-file-loading","title":"Strategy file loading","text":"

    By default, freqtrade will attempt to load strategies from all .py files within user_data/strategies.

    Assuming your strategy is called AwesomeStrategy, stored in the file user_data/strategies/AwesomeStrategy.py, then you can start freqtrade with freqtrade trade --strategy AwesomeStrategy. Note that we're using the class-name, not the file name.

    You can use freqtrade list-strategies to see a list of all strategies Freqtrade is able to load (all strategies in the correct folder). It will also include a \"status\" field, highlighting potential problems.

    Customize strategy directory

    You can use a different directory by using --strategy-path user_data/otherPath. This parameter is available to all commands that require a strategy.

    "},{"location":"strategy-customization/#informative-pairs","title":"Informative Pairs","text":""},{"location":"strategy-customization/#get-data-for-non-tradeable-pairs","title":"Get data for non-tradeable pairs","text":"

    Data for additional, informative pairs (reference pairs) can be beneficial for some strategies. OHLCV data for these pairs will be downloaded as part of the regular whitelist refresh process and is available via DataProvider just as other pairs (see below). These parts will not be traded unless they are also specified in the pair whitelist, or have been selected by Dynamic Whitelisting.

    The pairs need to be specified as tuples in the format (\"pair\", \"timeframe\"), with pair as the first and timeframe as the second argument.

    Sample:

    def informative_pairs(self):\n    return [(\"ETH/USDT\", \"5m\"),\n            (\"BTC/TUSD\", \"15m\"),\n            ]\n

    A full sample can be found in the DataProvider section.

    Warning

    As these pairs will be refreshed as part of the regular whitelist refresh, it's best to keep this list short. All timeframes and all pairs can be specified as long as they are available (and active) on the used exchange. It is however better to use resampling to longer timeframes whenever possible to avoid hammering the exchange with too many requests and risk being blocked.

    Alternative candle types

    Informative_pairs can also provide a 3rd tuple element defining the candle type explicitly. Availability of alternative candle-types will depend on the trading-mode and the exchange. In general, spot pairs cannot be used in futures markets, and futures candles can't be used as informative pairs for spot bots. Details about this may vary, if they do, this can be found in the exchange documentation.

    def informative_pairs(self):\n    return [\n        (\"ETH/USDT\", \"5m\", \"\"),   # Uses default candletype, depends on trading_mode (recommended)\n        (\"ETH/USDT\", \"5m\", \"spot\"),   # Forces usage of spot candles (only valid for bots running on spot markets).\n        (\"BTC/TUSD\", \"15m\", \"futures\"),  # Uses futures candles (only bots with `trading_mode=futures`)\n        (\"BTC/TUSD\", \"15m\", \"mark\"),  # Uses mark candles (only bots with `trading_mode=futures`)\n    ]\n
    "},{"location":"strategy-customization/#informative-pairs-decorator-informative","title":"Informative pairs decorator (@informative())","text":"

    In most common case it is possible to easily define informative pairs by using a decorator. All decorated populate_indicators_* methods run in isolation, not having access to data from other informative pairs, in the end all informative dataframes are merged and passed to main populate_indicators() method. When hyperopting, use of hyperoptable parameter .value attribute is not supported. Please use .range attribute. See optimizing an indicator parameter for more information.

    Full documentation
    def informative(timeframe: str, asset: str = '',\n                fmt: Optional[Union[str, Callable[[KwArg(str)], str]]] = None,\n                *,\n                candle_type: Optional[CandleType] = None,\n                ffill: bool = True) -> Callable[[PopulateIndicators], PopulateIndicators]:\n    \"\"\"\n    A decorator for populate_indicators_Nn(self, dataframe, metadata), allowing these functions to\n    define informative indicators.\n\n    Example usage:\n\n        @informative('1h')\n        def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n            dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n            return dataframe\n\n    :param timeframe: Informative timeframe. Must always be equal or higher than strategy timeframe.\n    :param asset: Informative asset, for example BTC, BTC/USDT, ETH/BTC. Do not specify to use\n                current pair. Also supports limited pair format strings (see below)\n    :param fmt: Column format (str) or column formatter (callable(name, asset, timeframe)). When not\n    specified, defaults to:\n    * {base}_{quote}_{column}_{timeframe} if asset is specified.\n    * {column}_{timeframe} if asset is not specified.\n    Pair format supports these format variables:\n    * {base} - base currency in lower case, for example 'eth'.\n    * {BASE} - same as {base}, except in upper case.\n    * {quote} - quote currency in lower case, for example 'usdt'.\n    * {QUOTE} - same as {quote}, except in upper case.\n    Format string additionally supports this variables.\n    * {asset} - full name of the asset, for example 'BTC/USDT'.\n    * {column} - name of dataframe column.\n    * {timeframe} - timeframe of informative dataframe.\n    :param ffill: ffill dataframe after merging informative pair.\n    :param candle_type: '', mark, index, premiumIndex, or funding_rate\n    \"\"\"\n
    Fast and easy way to define informative pairs

    Most of the time we do not need power and flexibility offered by merge_informative_pair(), therefore we can use a decorator to quickly define informative pairs.

    from datetime import datetime\nfrom freqtrade.persistence import Trade\nfrom freqtrade.strategy import IStrategy, informative\n\nclass AwesomeStrategy(IStrategy):\n\n    # This method is not required. \n    # def informative_pairs(self): ...\n\n    # Define informative upper timeframe for each pair. Decorators can be stacked on same \n    # method. Available in populate_indicators as 'rsi_30m' and 'rsi_1h'.\n    @informative('30m')\n    @informative('1h')\n    def populate_indicators_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    # Define BTC/STAKE informative pair. Available in populate_indicators and other methods as\n    # 'btc_rsi_1h'. Current stake currency should be specified as {stake} format variable \n    # instead of hard-coding actual stake currency. Available in populate_indicators and other \n    # methods as 'btc_usdt_rsi_1h' (when stake currency is USDT).\n    @informative('1h', 'BTC/{stake}')\n    def populate_indicators_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    # Define BTC/ETH informative pair. You must specify quote currency if it is different from\n    # stake currency. Available in populate_indicators and other methods as 'eth_btc_rsi_1h'.\n    @informative('1h', 'ETH/BTC')\n    def populate_indicators_eth_btc_1h(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    # Define BTC/STAKE informative pair. A custom formatter may be specified for formatting\n    # column names. A callable `fmt(**kwargs) -> str` may be specified, to implement custom\n    # formatting. Available in populate_indicators and other methods as 'rsi_upper_1h'.\n    @informative('1h', 'BTC/{stake}', '{column}_{timeframe}')\n    def populate_indicators_btc_1h_2(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        dataframe['rsi_upper'] = ta.RSI(dataframe, timeperiod=14)\n        return dataframe\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        # Strategy timeframe indicators for current pair.\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n        # Informative pairs are available in this method.\n        dataframe['rsi_less'] = dataframe['rsi'] < dataframe['rsi_1h']\n        return dataframe\n

    Note

    Do not use @informative decorator if you need to use data of one informative pair when generating another informative pair. Instead, define informative pairs manually as described in the DataProvider section.

    Note

    Use string formatting when accessing informative dataframes of other pairs. This will allow easily changing stake currency in config without having to adjust strategy code.

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    stake = self.config['stake_currency']\n    dataframe.loc[\n        (\n            (dataframe[f'btc_{stake}_rsi_1h'] < 35)\n            &\n            (dataframe['volume'] > 0)\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'buy_signal_rsi')\n\n    return dataframe\n

    Alternatively column renaming may be used to remove stake currency from column names: @informative('1h', 'BTC/{stake}', fmt='{base}_{column}_{timeframe}').

    Duplicate method names

    Methods tagged with @informative() decorator must always have unique names! Re-using same name (for example when copy-pasting already defined informative method) will overwrite previously defined method and not produce any errors due to limitations of Python programming language. In such cases you will find that indicators created in earlier-defined methods are not available in the dataframe. Carefully review method names and make sure they are unique!

    "},{"location":"strategy-customization/#merge_informative_pair","title":"merge_informative_pair()","text":"

    This method helps you merge an informative pair to a regular dataframe without lookahead bias. It's there to help you merge the dataframe in a safe and consistent way.

    Options:

    • Rename the columns for you to create unique columns
    • Merge the dataframe without lookahead bias
    • Forward-fill (optional)

    For a full sample, please refer to the complete data provider example below.

    All columns of the informative dataframe will be available on the returning dataframe in a renamed fashion:

    Column renaming

    Assuming inf_tf = '1d' the resulting columns will be:

    'date', 'open', 'high', 'low', 'close', 'rsi'                     # from the original dataframe\n'date_1d', 'open_1d', 'high_1d', 'low_1d', 'close_1d', 'rsi_1d'   # from the informative dataframe\n
    Column renaming - 1h

    Assuming inf_tf = '1h' the resulting columns will be:

    'date', 'open', 'high', 'low', 'close', 'rsi'                     # from the original dataframe\n'date_1h', 'open_1h', 'high_1h', 'low_1h', 'close_1h', 'rsi_1h'   # from the informative dataframe\n
    Custom implementation

    A custom implementation for this is possible, and can be done as follows:

    # Shift date by 1 candle\n# This is necessary since the data is always the \"open date\"\n# and a 15m candle starting at 12:15 should not know the close of the 1h candle from 12:00 to 13:00\nminutes = timeframe_to_minutes(inf_tf)\n# Only do this if the timeframes are different:\ninformative['date_merge'] = informative[\"date\"] + pd.to_timedelta(minutes, 'm')\n\n# Rename columns to be unique\ninformative.columns = [f\"{col}_{inf_tf}\" for col in informative.columns]\n# Assuming inf_tf = '1d' - then the columns will now be:\n# date_1d, open_1d, high_1d, low_1d, close_1d, rsi_1d\n\n# Combine the 2 dataframes\n# all indicators on the informative sample MUST be calculated before this point\ndataframe = pd.merge(dataframe, informative, left_on='date', right_on=f'date_merge_{inf_tf}', how='left')\n# FFill to have the 1d value available in every row throughout the day.\n# Without this, comparisons would only work once per day.\ndataframe = dataframe.ffill()\n

    Informative timeframe < timeframe

    Using informative timeframes smaller than the dataframe timeframe is not recommended with this method, as it will not use any of the additional information this would provide. To use the more detailed information properly, more advanced methods should be applied (which are out of scope for freqtrade documentation, as it'll depend on the respective need).

    "},{"location":"strategy-customization/#additional-data-dataprovider","title":"Additional data (DataProvider)","text":"

    The strategy provides access to the DataProvider. This allows you to get additional data to use in your strategy.

    All methods return None in case of failure (do not raise an exception).

    Please always check the mode of operation to select the correct method to get data (samples see below).

    Hyperopt

    Dataprovider is available during hyperopt, however it can only be used in populate_indicators() within a strategy. It is not available in populate_buy() and populate_sell() methods, nor in populate_indicators(), if this method located in the hyperopt file.

    "},{"location":"strategy-customization/#possible-options-for-dataprovider","title":"Possible options for DataProvider","text":"
    • available_pairs - Property with tuples listing cached pairs with their timeframe (pair, timeframe).
    • current_whitelist() - Returns a current list of whitelisted pairs. Useful for accessing dynamic whitelists (i.e. VolumePairlist)
    • get_pair_dataframe(pair, timeframe) - This is a universal method, which returns either historical data (for backtesting) or cached live data (for the Dry-Run and Live-Run modes).
    • get_analyzed_dataframe(pair, timeframe) - Returns the analyzed dataframe (after calling populate_indicators(), populate_buy(), populate_sell()) and the time of the latest analysis.
    • historic_ohlcv(pair, timeframe) - Returns historical data stored on disk.
    • market(pair) - Returns market data for the pair: fees, limits, precisions, activity flag, etc. See ccxt documentation for more details on the Market data structure.
    • ohlcv(pair, timeframe) - Currently cached candle (OHLCV) data for the pair, returns DataFrame or empty DataFrame.
    • orderbook(pair, maximum) - Returns latest orderbook data for the pair, a dict with bids/asks with a total of maximum entries.
    • ticker(pair) - Returns current ticker data for the pair. See ccxt documentation for more details on the Ticker data structure.
    • runmode - Property containing the current runmode.
    "},{"location":"strategy-customization/#example-usages","title":"Example Usages","text":""},{"location":"strategy-customization/#available_pairs","title":"available_pairs","text":"
    for pair, timeframe in self.dp.available_pairs:\n    print(f\"available {pair}, {timeframe}\")\n
    "},{"location":"strategy-customization/#current_whitelist","title":"current_whitelist()","text":"

    Imagine you've developed a strategy that trades the 5m timeframe using signals generated from a 1d timeframe on the top 10 volume pairs by volume.

    The strategy might look something like this:

    Scan through the top 10 pairs by volume using the VolumePairList every 5 minutes and use a 14 day RSI to buy and sell.

    Due to the limited available data, it's very difficult to resample 5m candles into daily candles for use in a 14 day RSI. Most exchanges limit us to just 500-1000 candles which effectively gives us around 1.74 daily candles. We need 14 days at least!

    Since we can't resample the data we will have to use an informative pair; and since the whitelist will be dynamic we don't know which pair(s) to use.

    This is where calling self.dp.current_whitelist() comes in handy.

        def informative_pairs(self):\n\n        # get access to all pairs available in whitelist.\n        pairs = self.dp.current_whitelist()\n        # Assign tf to each pair so they can be downloaded and cached for strategy.\n        informative_pairs = [(pair, '1d') for pair in pairs]\n        return informative_pairs\n
    Plotting with current_whitelist

    Current whitelist is not supported for plot-dataframe, as this command is usually used by providing an explicit pairlist - and would therefore make the return values of this method misleading. It's also not supported for freqUI visualization in webserver mode - as the configuration for webserver mode doesn't require a pairlist to be set.

    "},{"location":"strategy-customization/#get_pair_dataframepair-timeframe","title":"get_pair_dataframe(pair, timeframe)","text":"
    # fetch live / historical candle (OHLCV) data for the first informative pair\ninf_pair, inf_timeframe = self.informative_pairs()[0]\ninformative = self.dp.get_pair_dataframe(pair=inf_pair,\n                                         timeframe=inf_timeframe)\n

    Warning about backtesting

    In backtesting, dp.get_pair_dataframe() behavior differs depending on where it's called. Within populate_*() methods, dp.get_pair_dataframe() returns the full timerange. Please make sure to not \"look into the future\" to avoid surprises when running in dry/live mode. Within callbacks, you'll get the full timerange up to the current (simulated) candle.

    "},{"location":"strategy-customization/#get_analyzed_dataframepair-timeframe","title":"get_analyzed_dataframe(pair, timeframe)","text":"

    This method is used by freqtrade internally to determine the last signal. It can also be used in specific callbacks to get the signal that caused the action (see Advanced Strategy Documentation for more details on available callbacks).

    # fetch current dataframe\ndataframe, last_updated = self.dp.get_analyzed_dataframe(pair=metadata['pair'],\n                                                         timeframe=self.timeframe)\n

    No data available

    Returns an empty dataframe if the requested pair was not cached. You can check for this with if dataframe.empty: and handle this case accordingly. This should not happen when using whitelisted pairs.

    "},{"location":"strategy-customization/#orderbookpair-maximum","title":"orderbook(pair, maximum)","text":"
    if self.dp.runmode.value in ('live', 'dry_run'):\n    ob = self.dp.orderbook(metadata['pair'], 1)\n    dataframe['best_bid'] = ob['bids'][0][0]\n    dataframe['best_ask'] = ob['asks'][0][0]\n

    The orderbook structure is aligned with the order structure from ccxt, so the result will look as follows:

    {\n    'bids': [\n        [ price, amount ], // [ float, float ]\n        [ price, amount ],\n        ...\n    ],\n    'asks': [\n        [ price, amount ],\n        [ price, amount ],\n        //...\n    ],\n    //...\n}\n

    Therefore, using ob['bids'][0][0] as demonstrated above will result in using the best bid price. ob['bids'][0][1] would look at the amount at this orderbook position.

    Warning about backtesting

    The order book is not part of the historic data which means backtesting and hyperopt will not work correctly if this method is used, as the method will return up-to-date values.

    "},{"location":"strategy-customization/#tickerpair","title":"ticker(pair)","text":"
    if self.dp.runmode.value in ('live', 'dry_run'):\n    ticker = self.dp.ticker(metadata['pair'])\n    dataframe['last_price'] = ticker['last']\n    dataframe['volume24h'] = ticker['quoteVolume']\n    dataframe['vwap'] = ticker['vwap']\n

    Warning

    Although the ticker data structure is a part of the ccxt Unified Interface, the values returned by this method can vary for different exchanges. For instance, many exchanges do not return vwap values, some exchanges does not always fills in the last field (so it can be None), etc. So you need to carefully verify the ticker data returned from the exchange and add appropriate error handling / defaults.

    Warning about backtesting

    This method will always return up-to-date values - so usage during backtesting / hyperopt without runmode checks will lead to wrong results.

    "},{"location":"strategy-customization/#send-notification","title":"Send Notification","text":"

    The dataprovider .send_msg() function allows you to send custom notifications from your strategy. Identical notifications will only be sent once per candle, unless the 2nd argument (always_send) is set to True.

        self.dp.send_msg(f\"{metadata['pair']} just got hot!\")\n\n    # Force send this notification, avoid caching (Please read warning below!)\n    self.dp.send_msg(f\"{metadata['pair']} just got hot!\", always_send=True)\n

    Notifications will only be sent in trading modes (Live/Dry-run) - so this method can be called without conditions for backtesting.

    Spamming

    You can spam yourself pretty good by setting always_send=True in this method. Use this with great care and only in conditions you know will not happen throughout a candle to avoid a message every 5 seconds.

    "},{"location":"strategy-customization/#complete-data-provider-sample","title":"Complete Data-provider sample","text":"
    from freqtrade.strategy import IStrategy, merge_informative_pair\nfrom pandas import DataFrame\n\nclass SampleStrategy(IStrategy):\n    # strategy init stuff...\n\n    timeframe = '5m'\n\n    # more strategy init stuff..\n\n    def informative_pairs(self):\n\n        # get access to all pairs available in whitelist.\n        pairs = self.dp.current_whitelist()\n        # Assign tf to each pair so they can be downloaded and cached for strategy.\n        informative_pairs = [(pair, '1d') for pair in pairs]\n        # Optionally Add additional \"static\" pairs\n        informative_pairs += [(\"ETH/USDT\", \"5m\"),\n                              (\"BTC/TUSD\", \"15m\"),\n                            ]\n        return informative_pairs\n\n    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n        if not self.dp:\n            # Don't do anything if DataProvider is not available.\n            return dataframe\n\n        inf_tf = '1d'\n        # Get the informative pair\n        informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=inf_tf)\n        # Get the 14 day rsi\n        informative['rsi'] = ta.RSI(informative, timeperiod=14)\n\n        # Use the helper function merge_informative_pair to safely merge the pair\n        # Automatically renames the columns and merges a shorter timeframe dataframe and a longer timeframe informative pair\n        # use ffill to have the 1d value available in every row throughout the day.\n        # Without this, comparisons between columns of the original and the informative pair would only work once per day.\n        # Full documentation of this method, see below\n        dataframe = merge_informative_pair(dataframe, informative, self.timeframe, inf_tf, ffill=True)\n\n        # Calculate rsi of the original dataframe (5m timeframe)\n        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)\n\n        # Do other stuff\n        # ...\n\n        return dataframe\n\n    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n\n        dataframe.loc[\n            (\n                (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n                (dataframe['rsi_1d'] < 30) &                     # Ensure daily RSI is < 30\n                (dataframe['volume'] > 0)                        # Ensure this candle had volume (important for backtesting)\n            ),\n            ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n
    "},{"location":"strategy-customization/#additional-data-wallets","title":"Additional data (Wallets)","text":"

    The strategy provides access to the wallets object. This contains the current balances on the exchange.

    Backtesting / Hyperopt

    Wallets behaves differently depending on the function it's called. Within populate_*() methods, it'll return the full wallet as configured. Within callbacks, you'll get the wallet state corresponding to the actual simulated wallet at that point in the simulation process.

    Please always check if wallets is available to avoid failures during backtesting.

    if self.wallets:\n    free_eth = self.wallets.get_free('ETH')\n    used_eth = self.wallets.get_used('ETH')\n    total_eth = self.wallets.get_total('ETH')\n
    "},{"location":"strategy-customization/#possible-options-for-wallets","title":"Possible options for Wallets","text":"
    • get_free(asset) - currently available balance to trade
    • get_used(asset) - currently tied up balance (open orders)
    • get_total(asset) - total available balance - sum of the 2 above
    "},{"location":"strategy-customization/#additional-data-trades","title":"Additional data (Trades)","text":"

    A history of Trades can be retrieved in the strategy by querying the database.

    At the top of the file, import Trade.

    from freqtrade.persistence import Trade\n

    The following example queries for the current pair and trades from today, however other filters can easily be added.

    trades = Trade.get_trades_proxy(pair=metadata['pair'],\n                                open_date=datetime.now(timezone.utc) - timedelta(days=1),\n                                is_open=False,\n            ]).order_by(Trade.close_date).all()\n# Summarize profit for this pair.\ncurdayprofit = sum(trade.close_profit for trade in trades)\n

    For a full list of available methods, please consult the Trade object documentation.

    Warning

    Trade history is not available in populate_* methods during backtesting or hyperopt, and will result in empty results.

    "},{"location":"strategy-customization/#prevent-trades-from-happening-for-a-specific-pair","title":"Prevent trades from happening for a specific pair","text":"

    Freqtrade locks pairs automatically for the current candle (until that candle is over) when a pair is sold, preventing an immediate re-buy of that pair.

    Locked pairs will show the message Pair <pair> is currently locked..

    "},{"location":"strategy-customization/#locking-pairs-from-within-the-strategy","title":"Locking pairs from within the strategy","text":"

    Sometimes it may be desired to lock a pair after certain events happen (e.g. multiple losing trades in a row).

    Freqtrade has an easy method to do this from within the strategy, by calling self.lock_pair(pair, until, [reason]). until must be a datetime object in the future, after which trading will be re-enabled for that pair, while reason is an optional string detailing why the pair was locked.

    Locks can also be lifted manually, by calling self.unlock_pair(pair) or self.unlock_reason(<reason>) - providing reason the pair was locked with. self.unlock_reason(<reason>) will unlock all pairs currently locked with the provided reason.

    To verify if a pair is currently locked, use self.is_pair_locked(pair).

    Note

    Locked pairs will always be rounded up to the next candle. So assuming a 5m timeframe, a lock with until set to 10:18 will lock the pair until the candle from 10:15-10:20 will be finished.

    Warning

    Manually locking pairs is not available during backtesting, only locks via Protections are allowed.

    "},{"location":"strategy-customization/#pair-locking-example","title":"Pair locking example","text":"
    from freqtrade.persistence import Trade\nfrom datetime import timedelta, datetime, timezone\n# Put the above lines a the top of the strategy file, next to all the other imports\n# --------\n\n# Within populate indicators (or populate_buy):\nif self.config['runmode'].value in ('live', 'dry_run'):\n    # fetch closed trades for the last 2 days\n    trades = Trade.get_trades_proxy(\n        pair=metadata['pair'], is_open=False, \n        open_date=datetime.now(timezone.utc) - timedelta(days=2))\n    # Analyze the conditions you'd like to lock the pair .... will probably be different for every strategy\n    sumprofit = sum(trade.close_profit for trade in trades)\n    if sumprofit < 0:\n        # Lock pair for 12 hours\n        self.lock_pair(metadata['pair'], until=datetime.now(timezone.utc) + timedelta(hours=12))\n
    "},{"location":"strategy-customization/#print-created-dataframe","title":"Print created dataframe","text":"

    To inspect the created dataframe, you can issue a print-statement in either populate_entry_trend() or populate_exit_trend(). You may also want to print the pair so it's clear what data is currently shown.

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            #>> whatever condition<<<\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'somestring')\n\n    # Print the Analyzed pair\n    print(f\"result for {metadata['pair']}\")\n\n    # Inspect the last 5 rows\n    print(dataframe.tail())\n\n    return dataframe\n

    Printing more than a few rows is also possible (simply use print(dataframe) instead of print(dataframe.tail())), however not recommended, as that will be very verbose (~500 lines per pair every 5 seconds).

    "},{"location":"strategy-customization/#common-mistakes-when-developing-strategies","title":"Common mistakes when developing strategies","text":""},{"location":"strategy-customization/#peeking-into-the-future-while-backtesting","title":"Peeking into the future while backtesting","text":"

    Backtesting analyzes the whole time-range at once for performance reasons. Because of this, strategy authors need to make sure that strategies do not look-ahead into the future. This is a common pain-point, which can cause huge differences between backtesting and dry/live run methods, since they all use data which is not available during dry/live runs, so these strategies will perform well during backtesting, but will fail / perform badly in real conditions.

    The following lists some common patterns which should be avoided to prevent frustration:

    • don't use shift(-1) or other negative values. This uses data from the future in backtesting, which is not available in dry or live modes.
    • don't use .iloc[-1] or any other absolute position in the dataframe within populate_ functions, as this will be different between dry-run and backtesting. Absolute iloc indexing is safe to use in callbacks however - see Strategy Callbacks.
    • don't use dataframe['volume'].mean(). This uses the full DataFrame for backtesting, including data from the future. Use dataframe['volume'].rolling(<window>).mean() instead
    • don't use .resample('1h'). This uses the left border of the interval, so moves data from an hour to the start of the hour. Use .resample('1h', label='right') instead.

    Identifying problems

    You may also want to check the 2 helper commands lookahead-analysis and recursive-analysis, which can each help you figure out problems with your strategy in different ways. Please treat them as what they are - helpers to identify most common problems. A negative result of each does not guarantee that there's none of the above errors included.

    "},{"location":"strategy-customization/#colliding-signals","title":"Colliding signals","text":"

    When conflicting signals collide (e.g. both 'enter_long' and 'exit_long' are 1), freqtrade will do nothing and ignore the entry signal. This will avoid trades that enter, and exit immediately. Obviously, this can potentially lead to missed entries.

    The following rules apply, and entry signals will be ignored if more than one of the 3 signals is set:

    • enter_long -> exit_long, enter_short
    • enter_short -> exit_short, enter_long
    "},{"location":"strategy-customization/#further-strategy-ideas","title":"Further strategy ideas","text":"

    To get additional Ideas for strategies, head over to the strategy repository. Feel free to use them as they are - but results will depend on the current market situation, pairs used etc. - therefore please backtest the strategy for your exchange/desired pairs first, evaluate carefully, use at your own risk. Feel free to use any of them as inspiration for your own strategies. We're happy to accept Pull Requests containing new Strategies to that repo.

    "},{"location":"strategy-customization/#next-step","title":"Next step","text":"

    Now you have a perfect strategy you probably want to backtest it. Your next step is to learn How to use the Backtesting.

    "},{"location":"strategy_analysis_example/","title":"Strategy analysis example","text":"

    Debugging a strategy can be time-consuming. Freqtrade offers helper functions to visualize raw data. The following assumes you work with SampleStrategy, data for 5m timeframe from Binance and have downloaded them into the data directory in the default location. Please follow the documentation for more details.

    "},{"location":"strategy_analysis_example/#setup","title":"Setup","text":""},{"location":"strategy_analysis_example/#change-working-directory-to-repository-root","title":"Change Working directory to repository root","text":"
    import os\nfrom pathlib import Path\n\n\n# Change directory\n# Modify this cell to insure that the output shows the correct path.\n# Define all paths relative to the project root shown in the cell output\nproject_root = \"somedir/freqtrade\"\ni = 0\ntry:\n    os.chdir(project_root)\n    if not Path(\"LICENSE\").is_file():\n        i = 0\n        while i < 4 and (not Path(\"LICENSE\").is_file()):\n            os.chdir(Path(Path.cwd(), \"../\"))\n            i += 1\n        project_root = Path.cwd()\nexcept FileNotFoundError:\n    print(\"Please define the project root relative to the current directory\")\nprint(Path.cwd())\n
    "},{"location":"strategy_analysis_example/#configure-freqtrade-environment","title":"Configure Freqtrade environment","text":"
    from freqtrade.configuration import Configuration\n\n\n# Customize these according to your needs.\n\n# Initialize empty configuration object\nconfig = Configuration.from_files([])\n# Optionally (recommended), use existing configuration file\n# config = Configuration.from_files([\"user_data/config.json\"])\n\n# Define some constants\nconfig[\"timeframe\"] = \"5m\"\n# Name of the strategy class\nconfig[\"strategy\"] = \"SampleStrategy\"\n# Location of the data\ndata_location = config[\"datadir\"]\n# Pair to analyze - Only use one pair here\npair = \"BTC/USDT\"\n
    # Load data using values set above\nfrom freqtrade.data.history import load_pair_history\nfrom freqtrade.enums import CandleType\n\n\ncandles = load_pair_history(\n    datadir=data_location,\n    timeframe=config[\"timeframe\"],\n    pair=pair,\n    data_format=\"json\",  # Make sure to update this to your data\n    candle_type=CandleType.SPOT,\n)\n\n# Confirm success\nprint(f\"Loaded {len(candles)} rows of data for {pair} from {data_location}\")\ncandles.head()\n
    "},{"location":"strategy_analysis_example/#load-and-run-strategy","title":"Load and run strategy","text":"
    • Rerun each time the strategy file is changed
    # Load strategy using values set above\nfrom freqtrade.data.dataprovider import DataProvider\nfrom freqtrade.resolvers import StrategyResolver\n\n\nstrategy = StrategyResolver.load_strategy(config)\nstrategy.dp = DataProvider(config, None, None)\nstrategy.ft_bot_start()\n\n# Generate buy/sell signals using strategy\ndf = strategy.analyze_ticker(candles, {\"pair\": pair})\ndf.tail()\n
    "},{"location":"strategy_analysis_example/#display-the-trade-details","title":"Display the trade details","text":"
    • Note that using data.head() would also work, however most indicators have some \"startup\" data at the top of the dataframe.
    • Some possible problems * Columns with NaN values at the end of the dataframe * Columns used in crossed*() functions with completely different units
    • Comparison with full backtest * having 200 buy signals as output for one pair from analyze_ticker() does not necessarily mean that 200 trades will be made during backtesting. * Assuming you use only one condition such as, df['rsi'] < 30 as buy condition, this will generate multiple \"buy\" signals for each pair in sequence (until rsi returns > 29). The bot will only buy on the first of these signals (and also only if a trade-slot (\"max_open_trades\") is still available), or on one of the middle signals, as soon as a \"slot\" becomes available.
    # Report results\nprint(f\"Generated {df['enter_long'].sum()} entry signals\")\ndata = df.set_index(\"date\", drop=False)\ndata.tail()\n
    "},{"location":"strategy_analysis_example/#load-existing-objects-into-a-jupyter-notebook","title":"Load existing objects into a Jupyter notebook","text":"

    The following cells assume that you have already generated data using the cli. They will allow you to drill deeper into your results, and perform analysis which otherwise would make the output very difficult to digest due to information overload.

    "},{"location":"strategy_analysis_example/#load-backtest-results-to-pandas-dataframe","title":"Load backtest results to pandas dataframe","text":"

    Analyze a trades dataframe (also used below for plotting)

    from freqtrade.data.btanalysis import load_backtest_data, load_backtest_stats\n\n\n# if backtest_dir points to a directory, it'll automatically load the last backtest file.\nbacktest_dir = config[\"user_data_dir\"] / \"backtest_results\"\n# backtest_dir can also point to a specific file\n# backtest_dir = (\n#   config[\"user_data_dir\"] / \"backtest_results/backtest-result-2020-07-01_20-04-22.json\"\n# )\n
    # You can get the full backtest statistics by using the following command.\n# This contains all information used to generate the backtest result.\nstats = load_backtest_stats(backtest_dir)\n\nstrategy = \"SampleStrategy\"\n# All statistics are available per strategy, so if `--strategy-list` was used during backtest,\n# this will be reflected here as well.\n# Example usages:\nprint(stats[\"strategy\"][strategy][\"results_per_pair\"])\n# Get pairlist used for this backtest\nprint(stats[\"strategy\"][strategy][\"pairlist\"])\n# Get market change (average change of all pairs from start to end of the backtest period)\nprint(stats[\"strategy\"][strategy][\"market_change\"])\n# Maximum drawdown ()\nprint(stats[\"strategy\"][strategy][\"max_drawdown\"])\n# Maximum drawdown start and end\nprint(stats[\"strategy\"][strategy][\"drawdown_start\"])\nprint(stats[\"strategy\"][strategy][\"drawdown_end\"])\n\n\n# Get strategy comparison (only relevant if multiple strategies were compared)\nprint(stats[\"strategy_comparison\"])\n
    # Load backtested trades as dataframe\ntrades = load_backtest_data(backtest_dir)\n\n# Show value-counts per pair\ntrades.groupby(\"pair\")[\"exit_reason\"].value_counts()\n
    "},{"location":"strategy_analysis_example/#plotting-daily-profit-equity-line","title":"Plotting daily profit / equity line","text":"
    # Plotting equity line (starting with 0 on day 1 and adding daily profit for each backtested day)\n\nimport pandas as pd\nimport plotly.express as px\n\nfrom freqtrade.configuration import Configuration\nfrom freqtrade.data.btanalysis import load_backtest_stats\n\n\n# strategy = 'SampleStrategy'\n# config = Configuration.from_files([\"user_data/config.json\"])\n# backtest_dir = config[\"user_data_dir\"] / \"backtest_results\"\n\nstats = load_backtest_stats(backtest_dir)\nstrategy_stats = stats[\"strategy\"][strategy]\n\ndf = pd.DataFrame(columns=[\"dates\", \"equity\"], data=strategy_stats[\"daily_profit\"])\ndf[\"equity_daily\"] = df[\"equity\"].cumsum()\n\nfig = px.line(df, x=\"dates\", y=\"equity_daily\")\nfig.show()\n
    "},{"location":"strategy_analysis_example/#load-live-trading-results-into-a-pandas-dataframe","title":"Load live trading results into a pandas dataframe","text":"

    In case you did already some trading and want to analyze your performance

    from freqtrade.data.btanalysis import load_trades_from_db\n\n\n# Fetch trades from database\ntrades = load_trades_from_db(\"sqlite:///tradesv3.sqlite\")\n\n# Display results\ntrades.groupby(\"pair\")[\"exit_reason\"].value_counts()\n
    "},{"location":"strategy_analysis_example/#analyze-the-loaded-trades-for-trade-parallelism","title":"Analyze the loaded trades for trade parallelism","text":"

    This can be useful to find the best max_open_trades parameter, when used with backtesting in conjunction with --disable-max-market-positions.

    analyze_trade_parallelism() returns a timeseries dataframe with an \"open_trades\" column, specifying the number of open trades for each candle.

    from freqtrade.data.btanalysis import analyze_trade_parallelism\n\n\n# Analyze the above\nparallel_trades = analyze_trade_parallelism(trades, \"5m\")\n\nparallel_trades.plot()\n
    "},{"location":"strategy_analysis_example/#plot-results","title":"Plot results","text":"

    Freqtrade offers interactive plotting capabilities based on plotly.

    from freqtrade.plot.plotting import generate_candlestick_graph\n\n\n# Limit graph period to keep plotly quick and reactive\n\n# Filter trades to one pair\ntrades_red = trades.loc[trades[\"pair\"] == pair]\n\ndata_red = data[\"2019-06-01\":\"2019-06-10\"]\n# Generate candlestick graph\ngraph = generate_candlestick_graph(\n    pair=pair,\n    data=data_red,\n    trades=trades_red,\n    indicators1=[\"sma20\", \"ema50\", \"ema55\"],\n    indicators2=[\"rsi\", \"macd\", \"macdsignal\", \"macdhist\"],\n)\n
    # Show graph inline\n# graph.show()\n\n# Render graph in a separate window\ngraph.show(renderer=\"browser\")\n
    "},{"location":"strategy_analysis_example/#plot-average-profit-per-trade-as-distribution-graph","title":"Plot average profit per trade as distribution graph","text":"
    import plotly.figure_factory as ff\n\n\nhist_data = [trades.profit_ratio]\ngroup_labels = [\"profit_ratio\"]  # name of the dataset\n\nfig = ff.create_distplot(hist_data, group_labels, bin_size=0.01)\nfig.show()\n

    Feel free to submit an issue or Pull Request enhancing this document if you would like to share ideas on how to best analyze the data.

    "},{"location":"strategy_migration/","title":"Strategy Migration between V2 and V3","text":"

    To support new markets and trade-types (namely short trades / trades with leverage), some things had to change in the interface. If you intend on using markets other than spot markets, please migrate your strategy to the new format.

    We have put a great effort into keeping compatibility with existing strategies, so if you just want to continue using freqtrade in spot markets, there should be no changes necessary for now.

    You can use the quick summary as checklist. Please refer to the detailed sections below for full migration details.

    "},{"location":"strategy_migration/#quick-summary-migration-checklist","title":"Quick summary / migration checklist","text":"

    Note : forcesell, forcebuy, emergencysell are changed to force_exit, force_enter, emergency_exit respectively.

    • Strategy methods:
      • populate_buy_trend() -> populate_entry_trend()
      • populate_sell_trend() -> populate_exit_trend()
      • custom_sell() -> custom_exit()
      • check_buy_timeout() -> check_entry_timeout()
      • check_sell_timeout() -> check_exit_timeout()
      • New side argument to callbacks without trade object
        • custom_stake_amount
        • confirm_trade_entry
        • custom_entry_price
      • Changed argument name in confirm_trade_exit
    • Dataframe columns:
      • buy -> enter_long
      • sell -> exit_long
      • buy_tag -> enter_tag (used for both long and short trades)
      • New column enter_short and corresponding new column exit_short
    • trade-object now has the following new properties:
      • is_short
      • entry_side
      • exit_side
      • trade_direction
      • renamed: sell_reason -> exit_reason
    • Renamed trade.nr_of_successful_buys to trade.nr_of_successful_entries (mostly relevant for adjust_trade_position())
    • Introduced new leverage callback.
    • Informative pairs can now pass a 3rd element in the Tuple, defining the candle type.
    • @informative decorator now takes an optional candle_type argument.
    • helper methods stoploss_from_open and stoploss_from_absolute now take is_short as additional argument.
    • INTERFACE_VERSION should be set to 3.
    • Strategy/Configuration settings.
      • order_time_in_force buy -> entry, sell -> exit.
      • order_types buy -> entry, sell -> exit.
      • unfilledtimeout buy -> entry, sell -> exit.
      • ignore_buying_expired_candle_after -> moved to root level instead of \"ask_strategy/exit_pricing\"
    • Terminology changes
      • Sell reasons changed to reflect the new naming of \"exit\" instead of sells. Be careful in your strategy if you're using exit_reason checks and eventually update your strategy.
        • sell_signal -> exit_signal
        • custom_sell -> custom_exit
        • force_sell -> force_exit
        • emergency_sell -> emergency_exit
      • Order pricing
        • bid_strategy -> entry_pricing
        • ask_strategy -> exit_pricing
        • ask_last_balance -> price_last_balance
        • bid_last_balance -> price_last_balance
      • Webhook terminology changed from \"sell\" to \"exit\", and from \"buy\" to entry
        • webhookbuy -> entry
        • webhookbuyfill -> entry_fill
        • webhookbuycancel -> entry_cancel
        • webhooksell -> exit
        • webhooksellfill -> exit_fill
        • webhooksellcancel -> exit_cancel
      • Telegram notification settings
        • buy -> entry
        • buy_fill -> entry_fill
        • buy_cancel -> entry_cancel
        • sell -> exit
        • sell_fill -> exit_fill
        • sell_cancel -> exit_cancel
      • Strategy/config settings:
        • use_sell_signal -> use_exit_signal
        • sell_profit_only -> exit_profit_only
        • sell_profit_offset -> exit_profit_offset
        • ignore_roi_if_buy_signal -> ignore_roi_if_entry_signal
        • forcebuy_enable -> force_entry_enable
    "},{"location":"strategy_migration/#extensive-explanation","title":"Extensive explanation","text":""},{"location":"strategy_migration/#populate_buy_trend","title":"populate_buy_trend","text":"

    In populate_buy_trend() - you will want to change the columns you assign from 'buy' to 'enter_long', as well as the method name from populate_buy_trend to populate_entry_trend.

    def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['buy', 'buy_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n

    After:

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 30)) &  # Signal: RSI crosses above 30\n            (dataframe['tema'] <= dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] > dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['enter_long', 'enter_tag']] = (1, 'rsi_cross')\n\n    return dataframe\n

    Please refer to the Strategy documentation on how to enter and exit short trades.

    "},{"location":"strategy_migration/#populate_sell_trend","title":"populate_sell_trend","text":"

    Similar to populate_buy_trend, populate_sell_trend() will be renamed to populate_exit_trend(). We'll also change the column from 'sell' to 'exit_long'.

    def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['sell', 'exit_tag']] = (1, 'some_exit_tag')\n    return dataframe\n

    After

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:\n    dataframe.loc[\n        (\n            (qtpylib.crossed_above(dataframe['rsi'], 70)) &  # Signal: RSI crosses above 70\n            (dataframe['tema'] > dataframe['bb_middleband']) &  # Guard\n            (dataframe['tema'] < dataframe['tema'].shift(1)) &  # Guard\n            (dataframe['volume'] > 0)  # Make sure Volume is not 0\n        ),\n        ['exit_long', 'exit_tag']] = (1, 'some_exit_tag')\n    return dataframe\n

    Please refer to the Strategy documentation on how to enter and exit short trades.

    "},{"location":"strategy_migration/#custom_sell","title":"custom_sell","text":"

    custom_sell has been renamed to custom_exit. It's now also being called for every iteration, independent of current profit and exit_profit_only settings.

    class AwesomeStrategy(IStrategy):\n    def custom_sell(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,\n                    current_profit: float, **kwargs):\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n        # ...\n
    class AwesomeStrategy(IStrategy):\n    def custom_exit(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,\n                    current_profit: float, **kwargs):\n        dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)\n        last_candle = dataframe.iloc[-1].squeeze()\n        # ...\n
    "},{"location":"strategy_migration/#custom_entry_timeout","title":"custom_entry_timeout","text":"

    check_buy_timeout() has been renamed to check_entry_timeout(), and check_sell_timeout() has been renamed to check_exit_timeout().

    class AwesomeStrategy(IStrategy):\n    def check_buy_timeout(self, pair: str, trade: 'Trade', order: dict, \n                            current_time: datetime, **kwargs) -> bool:\n        return False\n\n    def check_sell_timeout(self, pair: str, trade: 'Trade', order: dict, \n                            current_time: datetime, **kwargs) -> bool:\n        return False \n
    class AwesomeStrategy(IStrategy):\n    def check_entry_timeout(self, pair: str, trade: 'Trade', order: 'Order', \n                            current_time: datetime, **kwargs) -> bool:\n        return False\n\n    def check_exit_timeout(self, pair: str, trade: 'Trade', order: 'Order', \n                            current_time: datetime, **kwargs) -> bool:\n        return False \n
    "},{"location":"strategy_migration/#custom_stake_amount","title":"custom_stake_amount","text":"

    New string argument side - which can be either \"long\" or \"short\".

    class AwesomeStrategy(IStrategy):\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            entry_tag: Optional[str], **kwargs) -> float:\n        # ... \n        return proposed_stake\n
    class AwesomeStrategy(IStrategy):\n    def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,\n                            proposed_stake: float, min_stake: Optional[float], max_stake: float,\n                            entry_tag: Optional[str], side: str, **kwargs) -> float:\n        # ... \n        return proposed_stake\n
    "},{"location":"strategy_migration/#confirm_trade_entry","title":"confirm_trade_entry","text":"

    New string argument side - which can be either \"long\" or \"short\".

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,\n                            time_in_force: str, current_time: datetime, entry_tag: Optional[str], \n                            **kwargs) -> bool:\n      return True\n

    After:

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_entry(self, pair: str, order_type: str, amount: float, rate: float,\n                            time_in_force: str, current_time: datetime, entry_tag: Optional[str], \n                            side: str, **kwargs) -> bool:\n      return True\n
    "},{"location":"strategy_migration/#confirm_trade_exit","title":"confirm_trade_exit","text":"

    Changed argument sell_reason to exit_reason. For compatibility, sell_reason will still be provided for a limited time.

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,\n                           rate: float, time_in_force: str, sell_reason: str,\n                           current_time: datetime, **kwargs) -> bool:\n    return True\n

    After:

    class AwesomeStrategy(IStrategy):\n    def confirm_trade_exit(self, pair: str, trade: Trade, order_type: str, amount: float,\n                           rate: float, time_in_force: str, exit_reason: str,\n                           current_time: datetime, **kwargs) -> bool:\n    return True\n
    "},{"location":"strategy_migration/#custom_entry_price","title":"custom_entry_price","text":"

    New string argument side - which can be either \"long\" or \"short\".

    class AwesomeStrategy(IStrategy):\n    def custom_entry_price(self, pair: str, current_time: datetime, proposed_rate: float,\n                           entry_tag: Optional[str], **kwargs) -> float:\n      return proposed_rate\n

    After:

    class AwesomeStrategy(IStrategy):\n    def custom_entry_price(self, pair: str, trade: Optional[Trade], current_time: datetime, proposed_rate: float,\n                           entry_tag: Optional[str], side: str, **kwargs) -> float:\n      return proposed_rate\n
    "},{"location":"strategy_migration/#adjust-trade-position-changes","title":"Adjust trade position changes","text":"

    While adjust-trade-position itself did not change, you should no longer use trade.nr_of_successful_buys - and instead use trade.nr_of_successful_entries, which will also include short entries.

    "},{"location":"strategy_migration/#helper-methods","title":"Helper methods","text":"

    Added argument \"is_short\" to stoploss_from_open and stoploss_from_absolute. This should be given the value of trade.is_short.

        def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,\n                        current_rate: float, current_profit: float, **kwargs) -> float:\n        # once the profit has risen above 10%, keep the stoploss at 7% above the open price\n        if current_profit > 0.10:\n            return stoploss_from_open(0.07, current_profit)\n\n        return stoploss_from_absolute(current_rate - (candle['atr'] * 2), current_rate)\n\n        return 1\n

    After:

        def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime,\n                        current_rate: float, current_profit: float, after_fill: bool, \n                        **kwargs) -> Optional[float]:\n        # once the profit has risen above 10%, keep the stoploss at 7% above the open price\n        if current_profit > 0.10:\n            return stoploss_from_open(0.07, current_profit, is_short=trade.is_short)\n\n        return stoploss_from_absolute(current_rate - (candle['atr'] * 2), current_rate, is_short=trade.is_short, leverage=trade.leverage)\n
    "},{"location":"strategy_migration/#strategyconfiguration-settings","title":"Strategy/Configuration settings","text":""},{"location":"strategy_migration/#order_time_in_force","title":"order_time_in_force","text":"

    order_time_in_force attributes changed from \"buy\" to \"entry\" and \"sell\" to \"exit\".

        order_time_in_force: Dict = {\n        \"buy\": \"gtc\",\n        \"sell\": \"gtc\",\n    }\n

    After:

        order_time_in_force: Dict = {\n        \"entry\": \"GTC\",\n        \"exit\": \"GTC\",\n    }\n
    "},{"location":"strategy_migration/#order_types","title":"order_types","text":"

    order_types have changed all wordings from buy to entry - and sell to exit. And two words are joined with _.

        order_types = {\n        \"buy\": \"limit\",\n        \"sell\": \"limit\",\n        \"emergencysell\": \"market\",\n        \"forcesell\": \"market\",\n        \"forcebuy\": \"market\",\n        \"stoploss\": \"market\",\n        \"stoploss_on_exchange\": false,\n        \"stoploss_on_exchange_interval\": 60\n    }\n

    After:

        order_types = {\n        \"entry\": \"limit\",\n        \"exit\": \"limit\",\n        \"emergency_exit\": \"market\",\n        \"force_exit\": \"market\",\n        \"force_entry\": \"market\",\n        \"stoploss\": \"market\",\n        \"stoploss_on_exchange\": false,\n        \"stoploss_on_exchange_interval\": 60\n    }\n
    "},{"location":"strategy_migration/#strategy-level-settings","title":"Strategy level settings","text":"
    • use_sell_signal -> use_exit_signal
    • sell_profit_only -> exit_profit_only
    • sell_profit_offset -> exit_profit_offset
    • ignore_roi_if_buy_signal -> ignore_roi_if_entry_signal
        # These values can be overridden in the config.\n    use_sell_signal = True\n    sell_profit_only = True\n    sell_profit_offset: 0.01\n    ignore_roi_if_buy_signal = False\n

    After:

        # These values can be overridden in the config.\n    use_exit_signal = True\n    exit_profit_only = True\n    exit_profit_offset: 0.01\n    ignore_roi_if_entry_signal = False\n
    "},{"location":"strategy_migration/#unfilledtimeout","title":"unfilledtimeout","text":"

    unfilledtimeout have changed all wordings from buy to entry - and sell to exit.

    unfilledtimeout = {\n        \"buy\": 10,\n        \"sell\": 10,\n        \"exit_timeout_count\": 0,\n        \"unit\": \"minutes\"\n    }\n

    After:

    unfilledtimeout = {\n        \"entry\": 10,\n        \"exit\": 10,\n        \"exit_timeout_count\": 0,\n        \"unit\": \"minutes\"\n    }\n
    "},{"location":"strategy_migration/#order-pricing","title":"order pricing","text":"

    Order pricing changed in 2 ways. bid_strategy was renamed to entry_pricing and ask_strategy was renamed to exit_pricing. The attributes ask_last_balance -> price_last_balance and bid_last_balance -> price_last_balance were renamed as well. Also, price-side can now be defined as ask, bid, same or other. Please refer to the pricing documentation for more information.

    {\n    \"bid_strategy\": {\n        \"price_side\": \"bid\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"ask_last_balance\": 0.0,\n        \"check_depth_of_market\": {\n            \"enabled\": false,\n            \"bids_to_ask_delta\": 1\n        }\n    },\n    \"ask_strategy\":{\n        \"price_side\": \"ask\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"bid_last_balance\": 0.0\n        \"ignore_buying_expired_candle_after\": 120\n    }\n}\n

    after:

    {\n    \"entry_pricing\": {\n        \"price_side\": \"same\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"price_last_balance\": 0.0,\n        \"check_depth_of_market\": {\n            \"enabled\": false,\n            \"bids_to_ask_delta\": 1\n        }\n    },\n    \"exit_pricing\":{\n        \"price_side\": \"same\",\n        \"use_order_book\": true,\n        \"order_book_top\": 1,\n        \"price_last_balance\": 0.0\n    },\n    \"ignore_buying_expired_candle_after\": 120\n}\n
    "},{"location":"strategy_migration/#freqai-strategy","title":"FreqAI strategy","text":"

    The populate_any_indicators() method has been split into feature_engineering_expand_all(), feature_engineering_expand_basic(), feature_engineering_standard() andset_freqai_targets().

    For each new function, the pair (and timeframe where necessary) will be automatically added to the column. As such, the definition of features becomes much simpler with the new logic.

    For a full explanation of each method, please go to the corresponding freqAI documentation page

    def populate_any_indicators(\n        self, pair, df, tf, informative=None, set_generalized_indicators=False\n    ):\n\n        if informative is None:\n            informative = self.dp.get_pair_dataframe(pair, tf)\n\n        # first loop is automatically duplicating indicators for time periods\n        for t in self.freqai_info[\"feature_parameters\"][\"indicator_periods_candles\"]:\n\n            t = int(t)\n            informative[f\"%-{pair}rsi-period_{t}\"] = ta.RSI(informative, timeperiod=t)\n            informative[f\"%-{pair}mfi-period_{t}\"] = ta.MFI(informative, timeperiod=t)\n            informative[f\"%-{pair}adx-period_{t}\"] = ta.ADX(informative, timeperiod=t)\n            informative[f\"%-{pair}sma-period_{t}\"] = ta.SMA(informative, timeperiod=t)\n            informative[f\"%-{pair}ema-period_{t}\"] = ta.EMA(informative, timeperiod=t)\n\n            bollinger = qtpylib.bollinger_bands(\n                qtpylib.typical_price(informative), window=t, stds=2.2\n            )\n            informative[f\"{pair}bb_lowerband-period_{t}\"] = bollinger[\"lower\"]\n            informative[f\"{pair}bb_middleband-period_{t}\"] = bollinger[\"mid\"]\n            informative[f\"{pair}bb_upperband-period_{t}\"] = bollinger[\"upper\"]\n\n            informative[f\"%-{pair}bb_width-period_{t}\"] = (\n                informative[f\"{pair}bb_upperband-period_{t}\"]\n                - informative[f\"{pair}bb_lowerband-period_{t}\"]\n            ) / informative[f\"{pair}bb_middleband-period_{t}\"]\n            informative[f\"%-{pair}close-bb_lower-period_{t}\"] = (\n                informative[\"close\"] / informative[f\"{pair}bb_lowerband-period_{t}\"]\n            )\n\n            informative[f\"%-{pair}roc-period_{t}\"] = ta.ROC(informative, timeperiod=t)\n\n            informative[f\"%-{pair}relative_volume-period_{t}\"] = (\n                informative[\"volume\"] / informative[\"volume\"].rolling(t).mean()\n            ) # (1)\n\n        informative[f\"%-{pair}pct-change\"] = informative[\"close\"].pct_change()\n        informative[f\"%-{pair}raw_volume\"] = informative[\"volume\"]\n        informative[f\"%-{pair}raw_price\"] = informative[\"close\"]\n        # (2)\n\n        indicators = [col for col in informative if col.startswith(\"%\")]\n        # This loop duplicates and shifts all indicators to add a sense of recency to data\n        for n in range(self.freqai_info[\"feature_parameters\"][\"include_shifted_candles\"] + 1):\n            if n == 0:\n                continue\n            informative_shift = informative[indicators].shift(n)\n            informative_shift = informative_shift.add_suffix(\"_shift-\" + str(n))\n            informative = pd.concat((informative, informative_shift), axis=1)\n\n        df = merge_informative_pair(df, informative, self.config[\"timeframe\"], tf, ffill=True)\n        skip_columns = [\n            (s + \"_\" + tf) for s in [\"date\", \"open\", \"high\", \"low\", \"close\", \"volume\"]\n        ]\n        df = df.drop(columns=skip_columns)\n\n        # Add generalized indicators here (because in live, it will call this\n        # function to populate indicators during training). Notice how we ensure not to\n        # add them multiple times\n        if set_generalized_indicators:\n            df[\"%-day_of_week\"] = (df[\"date\"].dt.dayofweek + 1) / 7\n            df[\"%-hour_of_day\"] = (df[\"date\"].dt.hour + 1) / 25\n            # (3)\n\n            # user adds targets here by prepending them with &- (see convention below)\n            df[\"&-s_close\"] = (\n                df[\"close\"]\n                .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n                .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n                .mean()\n                / df[\"close\"]\n                - 1\n            )  # (4)\n\n        return df\n
    1. Features - Move to feature_engineering_expand_all
    2. Basic features, not expanded across indicator_periods_candles - move tofeature_engineering_expand_basic().
    3. Standard features which should not be expanded - move to feature_engineering_standard().
    4. Targets - Move this part to set_freqai_targets().
    "},{"location":"strategy_migration/#freqai-feature-engineering-expand-all","title":"freqai - feature engineering expand all","text":"

    Features will now expand automatically. As such, the expansion loops, as well as the {pair} / {timeframe} parts will need to be removed.

        def feature_engineering_expand_all(self, dataframe, period, **kwargs) -> DataFrame::\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `indicator_periods_candles`, `include_timeframes`, `include_shifted_candles`, and\n        `include_corr_pairs`. In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `indicator_periods_candles` * `include_timeframes` * `include_shifted_candles` *\n        `include_corr_pairs` numbers of features added to the model.\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        More details on how these config defined parameters accelerate feature engineering\n        in the documentation at:\n\n        https://www.freqtrade.io/en/latest/freqai-parameter-table/#feature-parameters\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features\n\n        :param df: strategy dataframe which will receive the features\n        :param period: period of the indicator - usage example:\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n        \"\"\"\n\n        dataframe[\"%-rsi-period\"] = ta.RSI(dataframe, timeperiod=period)\n        dataframe[\"%-mfi-period\"] = ta.MFI(dataframe, timeperiod=period)\n        dataframe[\"%-adx-period\"] = ta.ADX(dataframe, timeperiod=period)\n        dataframe[\"%-sma-period\"] = ta.SMA(dataframe, timeperiod=period)\n        dataframe[\"%-ema-period\"] = ta.EMA(dataframe, timeperiod=period)\n\n        bollinger = qtpylib.bollinger_bands(\n            qtpylib.typical_price(dataframe), window=period, stds=2.2\n        )\n        dataframe[\"bb_lowerband-period\"] = bollinger[\"lower\"]\n        dataframe[\"bb_middleband-period\"] = bollinger[\"mid\"]\n        dataframe[\"bb_upperband-period\"] = bollinger[\"upper\"]\n\n        dataframe[\"%-bb_width-period\"] = (\n            dataframe[\"bb_upperband-period\"]\n            - dataframe[\"bb_lowerband-period\"]\n        ) / dataframe[\"bb_middleband-period\"]\n        dataframe[\"%-close-bb_lower-period\"] = (\n            dataframe[\"close\"] / dataframe[\"bb_lowerband-period\"]\n        )\n\n        dataframe[\"%-roc-period\"] = ta.ROC(dataframe, timeperiod=period)\n\n        dataframe[\"%-relative_volume-period\"] = (\n            dataframe[\"volume\"] / dataframe[\"volume\"].rolling(period).mean()\n        )\n\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-feature-engineering-basic","title":"Freqai - feature engineering basic","text":"

    Basic features. Make sure to remove the {pair} part from your features.

        def feature_engineering_expand_basic(self, dataframe: DataFrame, **kwargs) -> DataFrame::\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This function will automatically expand the defined features on the config defined\n        `include_timeframes`, `include_shifted_candles`, and `include_corr_pairs`.\n        In other words, a single feature defined in this function\n        will automatically expand to a total of\n        `include_timeframes` * `include_shifted_candles` * `include_corr_pairs`\n        numbers of features added to the model.\n\n        Features defined here will *not* be automatically duplicated on user defined\n        `indicator_periods_candles`\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        More details on how these config defined parameters accelerate feature engineering\n        in the documentation at:\n\n        https://www.freqtrade.io/en/latest/freqai-parameter-table/#feature-parameters\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering/#defining-the-features\n\n        :param df: strategy dataframe which will receive the features\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-ema-200\"] = ta.EMA(dataframe, timeperiod=200)\n        \"\"\"\n        dataframe[\"%-pct-change\"] = dataframe[\"close\"].pct_change()\n        dataframe[\"%-raw_volume\"] = dataframe[\"volume\"]\n        dataframe[\"%-raw_price\"] = dataframe[\"close\"]\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-feature-engineering-standard","title":"FreqAI - feature engineering standard","text":"
        def feature_engineering_standard(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        This optional function will be called once with the dataframe of the base timeframe.\n        This is the final function to be called, which means that the dataframe entering this\n        function will contain all the features and columns created by all other\n        freqai_feature_engineering_* functions.\n\n        This function is a good place to do custom exotic feature extractions (e.g. tsfresh).\n        This function is a good place for any feature that should not be auto-expanded upon\n        (e.g. day of the week).\n\n        All features must be prepended with `%` to be recognized by FreqAI internals.\n\n        More details about feature engineering available:\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering\n\n        :param df: strategy dataframe which will receive the features\n        usage example: dataframe[\"%-day_of_week\"] = (dataframe[\"date\"].dt.dayofweek + 1) / 7\n        \"\"\"\n        dataframe[\"%-day_of_week\"] = dataframe[\"date\"].dt.dayofweek\n        dataframe[\"%-hour_of_day\"] = dataframe[\"date\"].dt.hour\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-set-targets","title":"FreqAI - set Targets","text":"

    Targets now get their own, dedicated method.

        def set_freqai_targets(self, dataframe: DataFrame, **kwargs) -> DataFrame:\n        \"\"\"\n        *Only functional with FreqAI enabled strategies*\n        Required function to set the targets for the model.\n        All targets must be prepended with `&` to be recognized by the FreqAI internals.\n\n        More details about feature engineering available:\n\n        https://www.freqtrade.io/en/latest/freqai-feature-engineering\n\n        :param df: strategy dataframe which will receive the targets\n        usage example: dataframe[\"&-target\"] = dataframe[\"close\"].shift(-1) / dataframe[\"close\"]\n        \"\"\"\n        dataframe[\"&-s_close\"] = (\n            dataframe[\"close\"]\n            .shift(-self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .rolling(self.freqai_info[\"feature_parameters\"][\"label_period_candles\"])\n            .mean()\n            / dataframe[\"close\"]\n            - 1\n            )\n\n        return dataframe\n
    "},{"location":"strategy_migration/#freqai-new-data-pipeline","title":"FreqAI - New data Pipeline","text":"

    If you have created your own custom IFreqaiModel with a custom train()/predict() function, and you still rely on data_cleaning_train/predict(), then you will need to migrate to the new pipeline. If your model does not rely on data_cleaning_train/predict(), then you do not need to worry about this migration. That means that this migration guide is relevant for a very small percentage of power-users. If you stumbled upon this guide by mistake, feel free to inquire in depth about your problem in the Freqtrade discord server.

    The conversion involves first removing data_cleaning_train/predict() and replacing them with a define_data_pipeline() and define_label_pipeline() function to your IFreqaiModel class:

    class MyCoolFreqaiModel(BaseRegressionModel):\n    \"\"\"\n    Some cool custom IFreqaiModel you made before Freqtrade version 2023.6\n    \"\"\"\n    def train(\n        self, unfiltered_df: DataFrame, pair: str, dk: FreqaiDataKitchen, **kwargs\n    ) -> Any:\n\n        # ... your custom stuff\n\n        # Remove these lines\n        # data_dictionary = dk.make_train_test_datasets(features_filtered, labels_filtered)\n        # self.data_cleaning_train(dk)\n        # data_dictionary = dk.normalize_data(data_dictionary)\n        # (1)\n\n        # Add these lines. Now we control the pipeline fit/transform ourselves\n        dd = dk.make_train_test_datasets(features_filtered, labels_filtered)\n        dk.feature_pipeline = self.define_data_pipeline(threads=dk.thread_count)\n        dk.label_pipeline = self.define_label_pipeline(threads=dk.thread_count)\n\n        (dd[\"train_features\"],\n         dd[\"train_labels\"],\n         dd[\"train_weights\"]) = dk.feature_pipeline.fit_transform(dd[\"train_features\"],\n                                                                  dd[\"train_labels\"],\n                                                                  dd[\"train_weights\"])\n\n        (dd[\"test_features\"],\n         dd[\"test_labels\"],\n         dd[\"test_weights\"]) = dk.feature_pipeline.transform(dd[\"test_features\"],\n                                                             dd[\"test_labels\"],\n                                                             dd[\"test_weights\"])\n\n        dd[\"train_labels\"], _, _ = dk.label_pipeline.fit_transform(dd[\"train_labels\"])\n        dd[\"test_labels\"], _, _ = dk.label_pipeline.transform(dd[\"test_labels\"])\n\n        # ... your custom code\n\n        return model\n\n    def predict(\n        self, unfiltered_df: DataFrame, dk: FreqaiDataKitchen, **kwargs\n    ) -> Tuple[DataFrame, npt.NDArray[np.int_]]:\n\n        # ... your custom stuff\n\n        # Remove these lines:\n        # self.data_cleaning_predict(dk)\n        # (2)\n\n        # Add these lines:\n        dk.data_dictionary[\"prediction_features\"], outliers, _ = dk.feature_pipeline.transform(\n            dk.data_dictionary[\"prediction_features\"], outlier_check=True)\n\n        # Remove this line\n        # pred_df = dk.denormalize_labels_from_metadata(pred_df)\n        # (3)\n\n        # Replace with these lines\n        pred_df, _, _ = dk.label_pipeline.inverse_transform(pred_df)\n        if self.freqai_info.get(\"DI_threshold\", 0) > 0:\n            dk.DI_values = dk.feature_pipeline[\"di\"].di_values\n        else:\n            dk.DI_values = np.zeros(outliers.shape[0])\n        dk.do_predict = outliers\n\n        # ... your custom code\n        return (pred_df, dk.do_predict)\n
    1. Data normalization and cleaning is now homogenized with the new pipeline definition. This is created in the new define_data_pipeline() and define_label_pipeline() functions. The data_cleaning_train() and data_cleaning_predict() functions are no longer used. You can override define_data_pipeline() to create your own custom pipeline if you wish.
    2. Data normalization and cleaning is now homogenized with the new pipeline definition. This is created in the new define_data_pipeline() and define_label_pipeline() functions. The data_cleaning_train() and data_cleaning_predict() functions are no longer used. You can override define_data_pipeline() to create your own custom pipeline if you wish.
    3. Data denormalization is done with the new pipeline. Replace this with the lines below.
    "},{"location":"telegram-usage/","title":"Telegram usage","text":""},{"location":"telegram-usage/#setup-your-telegram-bot","title":"Setup your Telegram bot","text":"

    Below we explain how to create your Telegram Bot, and how to get your Telegram user id.

    "},{"location":"telegram-usage/#1-create-your-telegram-bot","title":"1. Create your Telegram bot","text":"

    Start a chat with the Telegram BotFather

    Send the message /newbot.

    BotFather response:

    Alright, a new bot. How are we going to call it? Please choose a name for your bot.

    Choose the public name of your bot (e.x. Freqtrade bot)

    BotFather response:

    Good. Now let's choose a username for your bot. It must end in bot. Like this, for example: TetrisBot or tetris_bot.

    Choose the name id of your bot and send it to the BotFather (e.g. \"My_own_freqtrade_bot\")

    BotFather response:

    Done! Congratulations on your new bot. You will find it at t.me/yourbots_name_bot. You can now add a description, about section and profile picture for your bot, see /help for a list of commands. By the way, when you've finished creating your cool bot, ping our Bot Support if you want a better username for it. Just make sure the bot is fully operational before you do this.

    Use this token to access the HTTP API: 22222222:APITOKEN

    For a description of the Bot API, see this page: https://core.telegram.org/bots/api Father bot will return you the token (API key)

    Copy the API Token (22222222:APITOKEN in the above example) and keep use it for the config parameter token.

    Don't forget to start the conversation with your bot, by clicking /START button

    "},{"location":"telegram-usage/#2-telegram-user_id","title":"2. Telegram user_id","text":""},{"location":"telegram-usage/#get-your-user-id","title":"Get your user id","text":"

    Talk to the userinfobot

    Get your \"Id\", you will use it for the config parameter chat_id.

    "},{"location":"telegram-usage/#use-group-id","title":"Use Group id","text":"

    You can use bots in telegram groups by just adding them to the group. You can find the group id by first adding a RawDataBot to your group. The Group id is shown as id in the \"chat\" section, which the RawDataBot will send to you:

    \"chat\":{\n   \"id\":-1001332619709\n}\n

    For the Freqtrade configuration, you can then use the full value (including - if it's there) as string:

       \"chat_id\": \"-1001332619709\"\n

    Using telegram groups

    When using telegram groups, you're giving every member of the telegram group access to your freqtrade bot and to all commands possible via telegram. Please make sure that you can trust everyone in the telegram group to avoid unpleasant surprises.

    "},{"location":"telegram-usage/#control-telegram-noise","title":"Control telegram noise","text":"

    Freqtrade provides means to control the verbosity of your telegram bot. Each setting has the following possible values:

    • on - Messages will be sent, and user will be notified.
    • silent - Message will be sent, Notification will be without sound / vibration.
    • off - Skip sending a message-type all together.

    Example configuration showing the different settings:

    \"telegram\": {\n    \"enabled\": true,\n    \"token\": \"your_telegram_token\",\n    \"chat_id\": \"your_telegram_chat_id\",\n    \"allow_custom_messages\": true,\n    \"notification_settings\": {\n        \"status\": \"silent\",\n        \"warning\": \"on\",\n        \"startup\": \"off\",\n        \"entry\": \"silent\",\n        \"entry_fill\": \"on\",\n        \"entry_cancel\": \"silent\",\n        \"exit\": {\n            \"roi\": \"silent\",\n            \"emergency_exit\": \"on\",\n            \"force_exit\": \"on\",\n            \"exit_signal\": \"silent\",\n            \"trailing_stop_loss\": \"on\",\n            \"stop_loss\": \"on\",\n            \"stoploss_on_exchange\": \"on\",\n            \"custom_exit\": \"silent\",\n            \"partial_exit\": \"on\"\n        },\n        \"exit_cancel\": \"on\",\n        \"exit_fill\": \"off\",\n        \"protection_trigger\": \"off\",\n        \"protection_trigger_global\": \"on\",\n        \"strategy_msg\": \"off\",\n        \"show_candle\": \"off\"\n    },\n    \"reload\": true,\n    \"balance_dust_level\": 0.01\n},\n

    entry notifications are sent when the order is placed, while entry_fill notifications are sent when the order is filled on the exchange. exit notifications are sent when the order is placed, while exit_fill notifications are sent when the order is filled on the exchange. *_fill notifications are off by default and must be explicitly enabled. protection_trigger notifications are sent when a protection triggers and protection_trigger_global notifications trigger when global protections are triggered. strategy_msg - Receive notifications from the strategy, sent via self.dp.send_msg() from the strategy more details. show_candle - show candle values as part of entry/exit messages. Only possible values are \"ohlc\" or \"off\".

    balance_dust_level will define what the /balance command takes as \"dust\" - Currencies with a balance below this will be shown. allow_custom_messages completely disable strategy messages. reload allows you to disable reload-buttons on selected messages.

    "},{"location":"telegram-usage/#create-a-custom-keyboard-command-shortcut-buttons","title":"Create a custom keyboard (command shortcut buttons)","text":"

    Telegram allows us to create a custom keyboard with buttons for commands. The default custom keyboard looks like this.

    [\n    [\"/daily\", \"/profit\", \"/balance\"], # row 1, 3 commands\n    [\"/status\", \"/status table\", \"/performance\"], # row 2, 3 commands\n    [\"/count\", \"/start\", \"/stop\", \"/help\"] # row 3, 4 commands\n]\n
    "},{"location":"telegram-usage/#usage","title":"Usage","text":"

    You can create your own keyboard in config.json:

    \"telegram\": {\n      \"enabled\": true,\n      \"token\": \"your_telegram_token\",\n      \"chat_id\": \"your_telegram_chat_id\",\n      \"keyboard\": [\n          [\"/daily\", \"/stats\", \"/balance\", \"/profit\"],\n          [\"/status table\", \"/performance\"],\n          [\"/reload_config\", \"/count\", \"/logs\"]\n      ]\n   },\n

    Supported Commands

    Only the following commands are allowed. Command arguments are not supported!

    /start, /stop, /status, /status table, /trades, /profit, /performance, /daily, /stats, /count, /locks, /balance, /stopentry, /reload_config, /show_config, /logs, /whitelist, /blacklist, /edge, /help, /version, /marketdir

    "},{"location":"telegram-usage/#telegram-commands","title":"Telegram commands","text":"

    Per default, the Telegram bot shows predefined commands. Some commands are only available by sending them to the bot. The table below list the official commands. You can ask at any moment for help with /help.

    Command Description System commands /start Starts the trader /stop Stops the trader /stopbuy | /stopentry Stops the trader from opening new trades. Gracefully closes open trades according to their rules. /reload_config Reloads the configuration file /show_config Shows part of the current configuration with relevant settings to operation /logs [limit] Show last log messages. /help Show help message /version Show version Status /status Lists all open trades /status <trade_id> Lists one or more specific trade. Separate multiple with a blank space. /status table List all open trades in a table format. Pending buy orders are marked with an asterisk () Pending sell orders are marked with a double asterisk (*) /order <trade_id> Lists orders of one or more specific trade. Separate multiple with a blank space. /trades [limit] List all recently closed trades in a table format. /count Displays number of trades used and available /locks Show currently locked pairs. /unlock <pair or lock_id> Remove the lock for this pair (or for this lock id). /marketdir [long | short | even | none] Updates the user managed variable that represents the current market direction. If no direction is provided, the currently set direction will be displayed. /list_custom_data <trade_id> [key] List custom_data for Trade ID & Key combination. If no Key is supplied it will list all key-value pairs found for that Trade ID. Modify Trade states /forceexit <trade_id> | /fx <tradeid> Instantly exits the given trade (Ignoring minimum_roi). /forceexit all | /fx all Instantly exits all open trades (Ignoring minimum_roi). /fx alias for /forceexit /forcelong <pair> [rate] Instantly buys the given pair. Rate is optional and only applies to limit orders. (force_entry_enable must be set to True) /forceshort <pair> [rate] Instantly shorts the given pair. Rate is optional and only applies to limit orders. This will only work on non-spot markets. (force_entry_enable must be set to True) /delete <trade_id> Delete a specific trade from the Database. Tries to close open orders. Requires manual handling of this trade on the exchange. /reload_trade <trade_id> Reload a trade from the Exchange. Only works in live, and can potentially help recover a trade that was manually sold on the exchange. /cancel_open_order <trade_id> | /coo <trade_id> Cancel an open order for a trade. Metrics /profit [<n>] Display a summary of your profit/loss from close trades and some stats about your performance, over the last n days (all trades by default) /performance Show performance of each finished trade grouped by pair /balance Show bot managed balance per currency /balance full Show account balance per currency /daily <n> Shows profit or loss per day, over the last n days (n defaults to 7) /weekly <n> Shows profit or loss per week, over the last n weeks (n defaults to 8) /monthly <n> Shows profit or loss per month, over the last n months (n defaults to 6) /stats Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells /exits Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells /entries Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells /whitelist [sorted] [baseonly] Show the current whitelist. Optionally display in alphabetical order and/or with just the base currency of each pairing. /blacklist [pair] Show the current blacklist, or adds a pair to the blacklist. /edge Show validated pairs by Edge if it is enabled."},{"location":"telegram-usage/#telegram-commands-in-action","title":"Telegram commands in action","text":"

    Below, example of Telegram message you will receive for each command.

    "},{"location":"telegram-usage/#start","title":"/start","text":"

    Status: running

    "},{"location":"telegram-usage/#stop","title":"/stop","text":"

    Stopping trader ... Status: stopped

    "},{"location":"telegram-usage/#stopbuy","title":"/stopbuy","text":"

    status: Setting max_open_trades to 0. Run /reload_config to reset.

    Prevents the bot from opening new trades by temporarily setting \"max_open_trades\" to 0. Open trades will be handled via their regular rules (ROI / Sell-signal, stoploss, ...).

    After this, give the bot time to close off open trades (can be checked via /status table). Once all positions are sold, run /stop to completely stop the bot.

    /reload_config resets \"max_open_trades\" to the value set in the configuration and resets this command.

    Warning

    The stop-buy signal is ONLY active while the bot is running, and is not persisted anyway, so restarting the bot will cause this to reset.

    "},{"location":"telegram-usage/#status","title":"/status","text":"

    For each open trade, the bot will send you the following message. Enter Tag is configurable via Strategy.

    Trade ID: 123 (since 1 days ago) Current Pair: CVC/BTC Direction: Long Leverage: 1.0 Amount: 26.64180098 Enter Tag: Awesome Long Signal Open Rate: 0.00007489 Current Rate: 0.00007489 Unrealized Profit: 12.95% Stoploss: 0.00007389 (-0.02%)

    "},{"location":"telegram-usage/#status-table","title":"/status table","text":"

    Return the status of all open trades in a table format.

    ID L/S    Pair     Since   Profit\n----    --------  -------  --------\n  67 L   SC/BTC    1 d      13.33%\n 123 S   CVC/BTC   1 h      12.95%\n
    "},{"location":"telegram-usage/#count","title":"/count","text":"

    Return the number of trades used and available.

    current    max\n---------  -----\n     2     10\n
    "},{"location":"telegram-usage/#profit","title":"/profit","text":"

    Return a summary of your profit/loss and performance.

    ROI: Close trades \u2219 0.00485701 BTC (2.2%) (15.2 \u03a3%) \u2219 62.968 USD ROI: All trades \u2219 0.00255280 BTC (1.5%) (6.43 \u03a3%) \u2219 33.095 EUR

    Total Trade Count: 138 Bot started: 2022-07-11 18:40:44 First Trade opened: 3 days ago Latest Trade opened: 2 minutes ago Avg. Duration: 2:33:45 Best Performing: PAY/BTC: 50.23% Trading volume: 0.5 BTC Profit factor: 1.04 Win / Loss: 102 / 36 Winrate: 73.91% Expectancy (Ratio): 4.87 (1.66) Max Drawdown: 9.23% (0.01255 BTC)

    The relative profit of 1.2% is the average profit per trade. The relative profit of 15.2 \u03a3% is be based on the starting capital - so in this case, the starting capital was 0.00485701 * 1.152 = 0.00738 BTC. Starting capital is either taken from the available_capital setting, or calculated by using current wallet size - profits. Profit Factor is calculated as gross profits / gross losses - and should serve as an overall metric for the strategy. Expectancy corresponds to the average return per currency unit at risk, i.e. the winrate and the risk-reward ratio (the average gain of winning trades compared to the average loss of losing trades). Expectancy Ratio is expected profit or loss of a subsequent trade based on the performance of all past trades. Max drawdown corresponds to the backtesting metric Absolute Drawdown (Account) - calculated as (Absolute Drawdown) / (DrawdownHigh + startingBalance). Bot started date will refer to the date the bot was first started. For older bots, this will default to the first trade's open date.

    "},{"location":"telegram-usage/#forceexit","title":"/forceexit

    BINANCE: Exiting BTC/LTC with limit 0.01650000 (profit: ~-4.07%, -0.00008168)

    Tip

    You can get a list of all open trades by calling /forceexit without parameter, which will show a list of buttons to simply exit a trade. This command has an alias in /fx - which has the same capabilities, but is faster to type in \"emergency\" situations.

    ","text":""},{"location":"telegram-usage/#forcelong-rate-forceshort-rate","title":"/forcelong [rate] | /forceshort [rate]

    /forcebuy <pair> [rate] is also supported for longs but should be considered deprecated.

    BINANCE: Long ETH/BTC with limit 0.03400000 (1.000000 ETH, 225.290 USD)

    Omitting the pair will open a query asking for the pair to trade (based on the current whitelist). Trades created through /forcelong will have the buy-tag of force_entry.

    Note that for this to work, force_entry_enable needs to be set to true.

    More details

    ","text":""},{"location":"telegram-usage/#performance","title":"/performance

    Return the performance of each crypto-currency the bot has sold.

    Performance: 1. RCN/BTC 0.003 BTC (57.77%) (1) 2. PAY/BTC 0.0012 BTC (56.91%) (1) 3. VIB/BTC 0.0011 BTC (47.07%) (1) 4. SALT/BTC 0.0010 BTC (30.24%) (1) 5. STORJ/BTC 0.0009 BTC (27.24%) (1) ...

    ","text":""},{"location":"telegram-usage/#balance","title":"/balance

    Return the balance of all crypto-currency your have on the exchange.

    Currency: BTC Available: 3.05890234 Balance: 3.05890234 Pending: 0.0

    Currency: CVC Available: 86.64180098 Balance: 86.64180098 Pending: 0.0

    ","text":""},{"location":"telegram-usage/#daily","title":"/daily

    Per default /daily will return the 7 last days. The example below if for /daily 3:

    Daily Profit over the last 3 days:

    Day (count)     USDT          USD         Profit %\n--------------  ------------  ----------  ----------\n2022-06-11 (1)  -0.746 USDT   -0.75 USD   -0.08%\n2022-06-10 (0)  0 USDT        0.00 USD    0.00%\n2022-06-09 (5)  20 USDT       20.10 USD   5.00%\n

    ","text":""},{"location":"telegram-usage/#weekly","title":"/weekly

    Per default /weekly will return the 8 last weeks, including the current week. Each week starts from Monday. The example below if for /weekly 3:

    Weekly Profit over the last 3 weeks (starting from Monday):

    Monday (count)  Profit BTC      Profit USD   Profit %\n-------------  --------------  ------------    ----------\n2018-01-03 (5)  0.00224175 BTC  29,142 USD   4.98%\n2017-12-27 (1)  0.00033131 BTC   4,307 USD   0.00%\n2017-12-20 (4)  0.00269130 BTC  34.986 USD   5.12%\n

    ","text":""},{"location":"telegram-usage/#monthly","title":"/monthly

    Per default /monthly will return the 6 last months, including the current month. The example below if for /monthly 3:

    Monthly Profit over the last 3 months:

    Month (count)  Profit BTC      Profit USD    Profit %\n-------------  --------------  ------------    ----------\n2018-01 (20)    0.00224175 BTC  29,142 USD  4.98%\n2017-12 (5)    0.00033131 BTC   4,307 USD   0.00%\n2017-11 (10)    0.00269130 BTC  34.986 USD  5.10%\n

    ","text":""},{"location":"telegram-usage/#whitelist","title":"/whitelist

    Shows the current whitelist

    Using whitelist StaticPairList with 22 pairs IOTA/BTC, NEO/BTC, TRX/BTC, VET/BTC, ADA/BTC, ETC/BTC, NCASH/BTC, DASH/BTC, XRP/BTC, XVG/BTC, EOS/BTC, LTC/BTC, OMG/BTC, BTG/BTC, LSK/BTC, ZEC/BTC, HOT/BTC, IOTX/BTC, XMR/BTC, AST/BTC, XLM/BTC, NANO/BTC

    ","text":""},{"location":"telegram-usage/#blacklist-pair","title":"/blacklist [pair]

    Shows the current blacklist. If Pair is set, then this pair will be added to the pairlist. Also supports multiple pairs, separated by a space. Use /reload_config to reset the blacklist.

    Using blacklist StaticPairList with 2 pairs DODGE/BTC, HOT/BTC.

    ","text":""},{"location":"telegram-usage/#edge","title":"/edge

    Shows pairs validated by Edge along with their corresponding win-rate, expectancy and stoploss values.

    Edge only validated following pairs:

    Pair        Winrate    Expectancy    Stoploss\n--------  ---------  ------------  ----------\nDOCK/ETH   0.522727      0.881821       -0.03\nPHX/ETH    0.677419      0.560488       -0.03\nHOT/ETH    0.733333      0.490492       -0.03\nHC/ETH     0.588235      0.280988       -0.02\nARDR/ETH   0.366667      0.143059       -0.01\n

    ","text":""},{"location":"telegram-usage/#version","title":"/version

    Version: 0.14.3

    ","text":""},{"location":"telegram-usage/#marketdir","title":"/marketdir

    If a market direction is provided the command updates the user managed variable that represents the current market direction. This variable is not set to any valid market direction on bot startup and must be set by the user. The example below is for /marketdir long:

    Successfully updated marketdirection from none to long.\n

    If no market direction is provided the command outputs the currently set market directions. The example below is for /marketdir:

    Currently set marketdirection: even\n

    You can use the market direction in your strategy via self.market_direction.

    Bot restarts

    Please note that the market direction is not persisted, and will be reset after a bot restart/reload.

    Backtesting

    As this value/variable is intended to be changed manually in dry/live trading. Strategies using market_direction will probably not produce reliable, reproducible results (changes to this variable will not be reflected for backtesting). Use at your own risk.

    ","text":""},{"location":"trade-object/","title":"Trade Object","text":""},{"location":"trade-object/#trade","title":"Trade","text":"

    A position freqtrade enters is stored in a Trade object - which is persisted to the database. It's a core concept of freqtrade - and something you'll come across in many sections of the documentation, which will most likely point you to this location.

    It will be passed to the strategy in many strategy callbacks. The object passed to the strategy cannot be modified directly. Indirect modifications may occur based on callback results.

    "},{"location":"trade-object/#trade-available-attributes","title":"Trade - Available attributes","text":"

    The following attributes / properties are available for each individual trade - and can be used with trade.<property> (e.g. trade.pair).

    Attribute DataType Description pair string Pair of this trade. is_open boolean Is the trade currently open, or has it been concluded. open_rate float Rate this trade was entered at (Avg. entry rate in case of trade-adjustments). close_rate float Close rate - only set when is_open = False. stake_amount float Amount in Stake (or Quote) currency. amount float Amount in Asset / Base currency that is currently owned. open_date datetime Timestamp when trade was opened use open_date_utc instead open_date_utc datetime Timestamp when trade was opened - in UTC. close_date datetime Timestamp when trade was closed use close_date_utc instead close_date_utc datetime Timestamp when trade was closed - in UTC. close_profit float Relative profit at the time of trade closure. 0.01 == 1% close_profit_abs float Absolute profit (in stake currency) at the time of trade closure. leverage float Leverage used for this trade - defaults to 1.0 in spot markets. enter_tag string Tag provided on entry via the enter_tag column in the dataframe. is_short boolean True for short trades, False otherwise. orders Order[] List of order objects attached to this trade (includes both filled and cancelled orders). date_last_filled_utc datetime Time of the last filled order. entry_side \"buy\" / \"sell\" Order Side the trade was entered. exit_side \"buy\" / \"sell\" Order Side that will result in a trade exit / position reduction. trade_direction \"long\" / \"short\" Trade direction in text - long or short. nr_of_successful_entries int Number of successful (filled) entry orders. nr_of_successful_exits int Number of successful (filled) exit orders."},{"location":"trade-object/#class-methods","title":"Class methods","text":"

    The following are class methods - which return generic information, and usually result in an explicit query against the database. They can be used as Trade.<method> - e.g. open_trades = Trade.get_open_trade_count()

    Backtesting/hyperopt

    Most methods will work in both backtesting / hyperopt and live/dry modes. During backtesting, it's limited to usage in strategy callbacks. Usage in populate_*() methods is not supported and will result in wrong results.

    "},{"location":"trade-object/#get_trades_proxy","title":"get_trades_proxy","text":"

    When your strategy needs some information on existing (open or close) trades - it's best to use Trade.get_trades_proxy().

    Usage:

    from freqtrade.persistence import Trade\nfrom datetime import timedelta\n\n# ...\ntrade_hist = Trade.get_trades_proxy(pair='ETH/USDT', is_open=False, open_date=current_date - timedelta(days=2))\n

    get_trades_proxy() supports the following keyword arguments. All arguments are optional - calling get_trades_proxy() without arguments will return a list of all trades in the database.

    • pair e.g. pair='ETH/USDT'
    • is_open e.g. is_open=False
    • open_date e.g. open_date=current_date - timedelta(days=2)
    • close_date e.g. close_date=current_date - timedelta(days=5)
    "},{"location":"trade-object/#get_open_trade_count","title":"get_open_trade_count","text":"

    Get the number of currently open trades

    from freqtrade.persistence import Trade\n# ...\nopen_trades = Trade.get_open_trade_count()\n
    "},{"location":"trade-object/#get_total_closed_profit","title":"get_total_closed_profit","text":"

    Retrieve the total profit the bot has generated so far. Aggregates close_profit_abs for all closed trades.

    from freqtrade.persistence import Trade\n\n# ...\nprofit = Trade.get_total_closed_profit()\n
    "},{"location":"trade-object/#total_open_trades_stakes","title":"total_open_trades_stakes","text":"

    Retrieve the total stake_amount that's currently in trades.

    from freqtrade.persistence import Trade\n\n# ...\nprofit = Trade.total_open_trades_stakes()\n
    "},{"location":"trade-object/#get_overall_performance","title":"get_overall_performance","text":"

    Retrieve the overall performance - similar to the /performance telegram command.

    from freqtrade.persistence import Trade\n\n# ...\nif self.config['runmode'].value in ('live', 'dry_run'):\n    performance = Trade.get_overall_performance()\n

    Sample return value: ETH/BTC had 5 trades, with a total profit of 1.5% (ratio of 0.015).

    {\"pair\": \"ETH/BTC\", \"profit\": 0.015, \"count\": 5}\n
    "},{"location":"trade-object/#order-object","title":"Order Object","text":"

    An Order object represents an order on the exchange (or a simulated order in dry-run mode). An Order object will always be tied to it's corresponding Trade, and only really makes sense in the context of a trade.

    "},{"location":"trade-object/#order-available-attributes","title":"Order - Available attributes","text":"

    an Order object is typically attached to a trade. Most properties here can be None as they are dependent on the exchange response.

    Attribute DataType Description trade Trade Trade object this order is attached to ft_pair string Pair this order is for ft_is_open boolean is the order filled? order_type string Order type as defined on the exchange - usually market, limit or stoploss status string Status as defined by ccxt. Usually open, closed, expired or canceled side string Buy or Sell price float Price the order was placed at average float Average price the order filled at amount float Amount in base currency filled float Filled amount (in base currency) remaining float Remaining amount cost float Cost of the order - usually average * filled (Exchange dependent on futures, may contain the cost with or without leverage and may be in contracts.) stake_amount float Stake amount used for this order. Added in 2023.7. order_date datetime Order creation date use order_date_utc instead order_date_utc datetime Order creation date (in UTC) order_fill_date datetime Order fill date use order_fill_utc instead order_fill_date_utc datetime Order fill date"},{"location":"updating/","title":"How to update","text":"

    To update your freqtrade installation, please use one of the below methods, corresponding to your installation method.

    Tracking changes

    Breaking changes / changed behavior will be documented in the changelog that is posted alongside every release. For the develop branch, please follow PR's to avoid being surprised by changes.

    "},{"location":"updating/#docker","title":"Docker","text":"

    Legacy installations using the master image

    We're switching from master to stable for the release Images - please adjust your docker-file and replace freqtradeorg/freqtrade:master with freqtradeorg/freqtrade:stable

    docker compose pull\ndocker compose up -d\n
    "},{"location":"updating/#installation-via-setup-script","title":"Installation via setup script","text":"
    ./setup.sh --update\n

    Note

    Make sure to run this command with your virtual environment disabled!

    "},{"location":"updating/#plain-native-installation","title":"Plain native installation","text":"

    Please ensure that you're also updating dependencies - otherwise things might break without you noticing.

    git pull\npip install -U -r requirements.txt\npip install -e .\n\n# Ensure freqUI is at the latest version\nfreqtrade install-ui \n
    "},{"location":"updating/#problems-updating","title":"Problems updating","text":"

    Update-problems usually come missing dependencies (you didn't follow the above instructions) - or from updated dependencies, which fail to install (for example TA-lib). Please refer to the corresponding installation sections (common problems linked below)

    Common problems and their solutions:

    • ta-lib update on windows
    "},{"location":"utils/","title":"Utility Subcommands","text":"

    Besides the Live-Trade and Dry-Run run modes, the backtesting, edge and hyperopt optimization subcommands, and the download-data subcommand which prepares historical data, the bot contains a number of utility subcommands. They are described in this section.

    "},{"location":"utils/#create-userdir","title":"Create userdir","text":"

    Creates the directory structure to hold your files for freqtrade. Will also create strategy and hyperopt examples for you to get started. Can be used multiple times - using --reset will reset the sample strategy and hyperopt files to their default state.

    usage: freqtrade create-userdir [-h] [--userdir PATH] [--reset]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  --reset               Reset sample files to their original state.\n

    Warning

    Using --reset may result in loss of data, since this will overwrite all sample files without asking again.

    \u251c\u2500\u2500 backtest_results\n\u251c\u2500\u2500 data\n\u251c\u2500\u2500 hyperopt_results\n\u251c\u2500\u2500 hyperopts\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 sample_hyperopt_loss.py\n\u251c\u2500\u2500 notebooks\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 strategy_analysis_example.ipynb\n\u251c\u2500\u2500 plot\n\u2514\u2500\u2500 strategies\n    \u2514\u2500\u2500 sample_strategy.py\n
    "},{"location":"utils/#create-new-config","title":"Create new config","text":"

    Creates a new configuration file, asking some questions which are important selections for a configuration.

    usage: freqtrade new-config [-h] [-c PATH]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default: `config.json`). Multiple --config options may be used. Can be set to `-`\n                        to read config from stdin.\n

    Warning

    Only vital questions are asked. Freqtrade offers a lot more configuration possibilities, which are listed in the Configuration documentation

    "},{"location":"utils/#create-config-examples","title":"Create config examples","text":"
    $ freqtrade new-config --config user_data/config_binance.json\n\n? Do you want to enable Dry-run (simulated trades)?  Yes\n? Please insert your stake currency: BTC\n? Please insert your stake amount: 0.05\n? Please insert max_open_trades (Integer or -1 for unlimited open trades): 3\n? Please insert your desired timeframe (e.g. 5m): 5m\n? Please insert your display Currency (for reporting): USD\n? Select exchange  binance\n? Do you want to enable Telegram?  No\n
    "},{"location":"utils/#show-config","title":"Show config","text":"

    Show configuration file (with sensitive values redacted by default). Especially useful with split configuration files or environment variables, where this command will show the merged configuration.

    usage: freqtrade show-config [-h] [--userdir PATH] [-c PATH]\n                             [--show-sensitive]\n\noptions:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  --show-sensitive      Show secrets in the output.\n
    Your combined configuration is:\n{\n  \"exit_pricing\": {\n    \"price_side\": \"other\",\n    \"use_order_book\": true,\n    \"order_book_top\": 1\n  },\n  \"stake_currency\": \"USDT\",\n  \"exchange\": {\n    \"name\": \"binance\",\n    \"key\": \"REDACTED\",\n    \"secret\": \"REDACTED\",\n    \"ccxt_config\": {},\n    \"ccxt_async_config\": {},\n  }\n  // ...\n}\n

    Sharing information provided by this command

    We try to remove all known sensitive information from the default output (without --show-sensitive). Yet, please do double-check for sensitive values in your output to make sure you're not accidentally exposing some private info.

    "},{"location":"utils/#create-new-strategy","title":"Create new strategy","text":"

    Creates a new strategy from a template similar to SampleStrategy. The file will be named inline with your class name, and will not overwrite existing files.

    Results will be located in user_data/strategies/<strategyclassname>.py.

    usage: freqtrade new-strategy [-h] [--userdir PATH] [-s NAME]\n                              [--template {full,minimal,advanced}]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  -s NAME, --strategy NAME\n                        Specify strategy class name which will be used by the\n                        bot.\n  --template {full,minimal,advanced}\n                        Use a template which is either `minimal`, `full`\n                        (containing multiple sample indicators) or `advanced`.\n                        Default: `full`.\n
    "},{"location":"utils/#sample-usage-of-new-strategy","title":"Sample usage of new-strategy","text":"
    freqtrade new-strategy --strategy AwesomeStrategy\n

    With custom user directory

    freqtrade new-strategy --userdir ~/.freqtrade/ --strategy AwesomeStrategy\n

    Using the advanced template (populates all optional functions and methods)

    freqtrade new-strategy --strategy AwesomeStrategy --template advanced\n
    "},{"location":"utils/#list-strategies","title":"List Strategies","text":"

    Use the list-strategies subcommand to see all strategies in one particular directory.

    This subcommand is useful for finding problems in your environment with loading strategies: modules with strategies that contain errors and failed to load are printed in red (LOAD FAILED), while strategies with duplicate names are printed in yellow (DUPLICATE NAME).

    usage: freqtrade list-strategies [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                 [-d PATH] [--userdir PATH]\n                                 [--strategy-path PATH] [-1] [--no-color]\n                                 [--recursive-strategy-search]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --strategy-path PATH  Specify additional strategy lookup path.\n  -1, --one-column      Print output in one column.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n  --recursive-strategy-search\n                        Recursively search for a strategy in the strategies\n                        folder.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Warning

    Using these commands will try to load all python files from a directory. This can be a security risk if untrusted files reside in this directory, since all module-level code is executed.

    Example: Search default strategies directories (within the default userdir).

    freqtrade list-strategies\n

    Example: Search strategies directory within the userdir.

    freqtrade list-strategies --userdir ~/.freqtrade/\n

    Example: Search dedicated strategy path.

    freqtrade list-strategies --strategy-path ~/.freqtrade/strategies/\n
    "},{"location":"utils/#list-freqai-models","title":"List freqAI models","text":"

    Use the list-freqaimodels subcommand to see all freqAI models available.

    This subcommand is useful for finding problems in your environment with loading freqAI models: modules with models that contain errors and failed to load are printed in red (LOAD FAILED), while models with duplicate names are printed in yellow (DUPLICATE NAME).

    usage: freqtrade list-freqaimodels [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                   [-d PATH] [--userdir PATH]\n                                   [--freqaimodel-path PATH] [-1] [--no-color]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --freqaimodel-path PATH\n                        Specify additional lookup path for freqaimodels.\n  -1, --one-column      Print output in one column.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#list-exchanges","title":"List Exchanges","text":"

    Use the list-exchanges subcommand to see the exchanges available for the bot.

    usage: freqtrade list-exchanges [-h] [-1] [-a]\n\noptional arguments:\n  -h, --help        show this help message and exit\n  -1, --one-column  Print output in one column.\n  -a, --all         Print all exchanges known to the ccxt library.\n

    Example: see exchanges available for the bot:

    $ freqtrade list-exchanges\nExchanges available for Freqtrade:\nExchange name       Supported    Markets                 Reason\n------------------  -----------  ----------------------  ------------------------------------------------------------------------\nbinance             Official     spot, isolated futures\nbitmart             Official     spot\nbybit                            spot, isolated futures\ngate                Official     spot, isolated futures\nhtx                 Official     spot\nhuobi                            spot\nkraken              Official     spot\nokx                 Official     spot, isolated futures\n

    Output reduced for clarity - supported and available exchanges may change over time.

    missing opt exchanges

    Values with \"missing opt:\" might need special configuration (e.g. using orderbook if fetchTickers is missing) - but should in theory work (although we cannot guarantee they will).

    Example: see all exchanges supported by the ccxt library (including 'bad' ones, i.e. those that are known to not work with Freqtrade)

    $ freqtrade list-exchanges -a\nAll exchanges supported by the ccxt library:\nExchange name       Valid    Supported    Markets                 Reason\n------------------  -------  -----------  ----------------------  ---------------------------------------------------------------------------------\nbinance             True     Official     spot, isolated futures\nbitflyer            False                 spot                    missing: fetchOrder. missing opt: fetchTickers.\nbitmart             True     Official     spot\nbybit               True                  spot, isolated futures\ngate                True     Official     spot, isolated futures\nhtx                 True     Official     spot\nkraken              True     Official     spot\nokx                 True     Official     spot, isolated futures\n

    Reduced output - supported and available exchanges may change over time.

    "},{"location":"utils/#list-timeframes","title":"List Timeframes","text":"

    Use the list-timeframes subcommand to see the list of timeframes available for the exchange.

    usage: freqtrade list-timeframes [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                 [-d PATH] [--userdir PATH]\n                                 [--exchange EXCHANGE] [-1]\n\noptions:\n  -h, --help            show this help message and exit\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  -1, --one-column      Print output in one column.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    • Example: see the timeframes for the 'binance' exchange, set in the configuration file:
    $ freqtrade list-timeframes -c config_binance.json\n...\nTimeframes available for the exchange `binance`: 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M\n
    • Example: enumerate exchanges available for Freqtrade and print timeframes supported by each of them:
      $ for i in `freqtrade list-exchanges -1`; do freqtrade list-timeframes --exchange $i; done\n
    "},{"location":"utils/#list-pairslist-markets","title":"List pairs/list markets","text":"

    The list-pairs and list-markets subcommands allow to see the pairs/markets available on exchange.

    Pairs are markets with the '/' character between the base currency part and the quote currency part in the market symbol. For example, in the 'ETH/BTC' pair 'ETH' is the base currency, while 'BTC' is the quote currency.

    For pairs traded by Freqtrade the pair quote currency is defined by the value of the stake_currency configuration setting.

    You can print info about any pair/market with these subcommands - and you can filter output by quote-currency using --quote BTC, or by base-currency using --base ETH options correspondingly.

    These subcommands have same usage and same set of available options:

    usage: freqtrade list-markets [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                              [-d PATH] [--userdir PATH] [--exchange EXCHANGE]\n                              [--print-list] [--print-json] [-1] [--print-csv]\n                              [--base BASE_CURRENCY [BASE_CURRENCY ...]]\n                              [--quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]]\n                              [-a] [--trading-mode {spot,margin,futures}]\nusage: freqtrade list-pairs [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                            [-d PATH] [--userdir PATH] [--exchange EXCHANGE]\n                            [--print-list] [--print-json] [-1] [--print-csv]\n                            [--base BASE_CURRENCY [BASE_CURRENCY ...]]\n                            [--quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]] [-a]\n                            [--trading-mode {spot,margin,futures}]\noptions:\n  -h, --help            show this help message and exit\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n  --print-list          Print list of pairs or market symbols. By default data\n                        is printed in the tabular format.\n  --print-json          Print list of pairs or market symbols in JSON format.\n  -1, --one-column      Print output in one column.\n  --print-csv           Print exchange pair or market data in the csv format.\n  --base BASE_CURRENCY [BASE_CURRENCY ...]\n                        Specify base currency(-ies). Space-separated list.\n  --quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]\n                        Specify quote currency(-ies). Space-separated list.\n  -a, --all             Print all pairs or market symbols. By default only\n                        active ones are shown.\n  --trading-mode {spot,margin,futures}, --tradingmode {spot,margin,futures}\n                        Select Trading mode\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    By default, only active pairs/markets are shown. Active pairs/markets are those that can currently be traded on the exchange. You can use the -a/-all option to see the list of all pairs/markets, including the inactive ones. Pairs may be listed as untradeable if the smallest tradeable price for the market is very small, i.e. less than 1e-11 (0.00000000001)

    Pairs/markets are sorted by its symbol string in the printed output.

    "},{"location":"utils/#examples","title":"Examples","text":"
    • Print the list of active pairs with quote currency USD on exchange, specified in the default configuration file (i.e. pairs on the \"Binance\" exchange) in JSON format:
    $ freqtrade list-pairs --quote USD --print-json\n
    • Print the list of all pairs on the exchange, specified in the config_binance.json configuration file (i.e. on the \"Binance\" exchange) with base currencies BTC or ETH and quote currencies USDT or USD, as the human-readable list with summary:
    $ freqtrade list-pairs -c config_binance.json --all --base BTC ETH --quote USDT USD --print-list\n
    • Print all markets on exchange \"Kraken\", in the tabular format:
    $ freqtrade list-markets --exchange kraken --all\n
    "},{"location":"utils/#test-pairlist","title":"Test pairlist","text":"

    Use the test-pairlist subcommand to test the configuration of dynamic pairlists.

    Requires a configuration with specified pairlists attribute. Can be used to generate static pairlists to be used during backtesting / hyperopt.

    usage: freqtrade test-pairlist [-h] [--userdir PATH] [-v] [-c PATH]\n                               [--quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]]\n                               [-1] [--print-json] [--exchange EXCHANGE]\n\noptions:\n  -h, --help            show this help message and exit\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  --quote QUOTE_CURRENCY [QUOTE_CURRENCY ...]\n                        Specify quote currency(-ies). Space-separated list.\n  -1, --one-column      Print output in one column.\n  --print-json          Print list of pairs or market symbols in JSON format.\n  --exchange EXCHANGE   Exchange name. Only valid if no config is provided.\n
    "},{"location":"utils/#examples_1","title":"Examples","text":"

    Show whitelist when using a dynamic pairlist.

    freqtrade test-pairlist --config config.json --quote USDT BTC\n
    "},{"location":"utils/#convert-database","title":"Convert database","text":"

    freqtrade convert-db can be used to convert your database from one system to another (sqlite -> postgres, postgres -> other postgres), migrating all trades, orders and Pairlocks.

    Please refer to the corresponding documentation to learn about requirements for different database systems.

    usage: freqtrade convert-db [-h] [--db-url PATH] [--db-url-from PATH]\n\noptional arguments:\n  -h, --help          show this help message and exit\n  --db-url PATH       Override trades database URL, this is useful in custom\n                      deployments (default: `sqlite:///tradesv3.sqlite` for\n                      Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                      Dry Run).\n  --db-url-from PATH  Source db url to use when migrating a database.\n

    Warning

    Please ensure to only use this on an empty target database. Freqtrade will perform a regular migration, but may fail if entries already existed.

    "},{"location":"utils/#webserver-mode","title":"Webserver mode","text":"

    Experimental

    Webserver mode is an experimental mode to increase backesting and strategy development productivity. There may still be bugs - so if you happen to stumble across these, please report them as github issues, thanks.

    Run freqtrade in webserver mode. Freqtrade will start the webserver and allow FreqUI to start and control backtesting processes. This has the advantage that data will not be reloaded between backtesting runs (as long as timeframe and timerange remain identical). FreqUI will also show the backtesting results.

    usage: freqtrade webserver [-h] [-v] [--logfile FILE] [-V] [-c PATH] [-d PATH]\n                           [--userdir PATH]\n\noptional arguments:\n  -h, --help            show this help message and exit\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#webserver-mode-docker","title":"Webserver mode - docker","text":"

    You can also use webserver mode via docker. Starting a one-off container requires the configuration of the port explicitly, as ports are not exposed by default. You can use docker compose run --rm -p 127.0.0.1:8080:8080 freqtrade webserver to start a one-off container that'll be removed once you stop it. This assumes that port 8080 is still available and no other bot is running on that port.

    Alternatively, you can reconfigure the docker-compose file to have the command updated:

        command: >\n      webserver\n      --config /freqtrade/user_data/config.json\n

    You can now use docker compose up to start the webserver. This assumes that the configuration has a webserver enabled and configured for docker (listening port = 0.0.0.0).

    Tip

    Don't forget to reset the command back to the trade command if you want to start a live or dry-run bot.

    "},{"location":"utils/#show-previous-backtest-results","title":"Show previous Backtest results","text":"

    Allows you to show previous backtest results. Adding --show-pair-list outputs a sorted pair list you can easily copy/paste into your configuration (omitting bad pairs).

    Strategy overfitting

    Only using winning pairs can lead to an overfitted strategy, which will not work well on future data. Make sure to extensively test your strategy in dry-run before risking real money.

    usage: freqtrade backtesting-show [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                  [-d PATH] [--userdir PATH]\n                                  [--export-filename PATH] [--show-pair-list]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --export-filename PATH\n                        Save backtest results to the file with this filename.\n                        Requires `--export` to be set as well. Example:\n                        `--export-filename=user_data/backtest_results/backtest\n                        _today.json`\n  --show-pair-list      Show backtesting pairlist sorted by profit.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#detailed-backtest-analysis","title":"Detailed backtest analysis","text":"

    Advanced backtest result analysis.

    More details in the Backtesting analysis Section.

    usage: freqtrade backtesting-analysis [-h] [-v] [--logfile FILE] [-V]\n                                      [-c PATH] [-d PATH] [--userdir PATH]\n                                      [--export-filename PATH]\n                                      [--analysis-groups {0,1,2,3,4} [{0,1,2,3,4} ...]]\n                                      [--enter-reason-list ENTER_REASON_LIST [ENTER_REASON_LIST ...]]\n                                      [--exit-reason-list EXIT_REASON_LIST [EXIT_REASON_LIST ...]]\n                                      [--indicator-list INDICATOR_LIST [INDICATOR_LIST ...]]\n                                      [--timerange YYYYMMDD-[YYYYMMDD]]\n                                      [--rejected]\n                                      [--analysis-to-csv]\n                                      [--analysis-csv-path PATH]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --export-filename PATH, --backtest-filename PATH\n                        Use this filename for backtest results.Requires\n                        `--export` to be set as well. Example: `--export-filen\n                        ame=user_data/backtest_results/backtest_today.json`\n  --analysis-groups {0,1,2,3,4} [{0,1,2,3,4} ...]\n                        grouping output - 0: simple wins/losses by enter tag,\n                        1: by enter_tag, 2: by enter_tag and exit_tag, 3: by\n                        pair and enter_tag, 4: by pair, enter_ and exit_tag\n                        (this can get quite large)\n  --enter-reason-list ENTER_REASON_LIST [ENTER_REASON_LIST ...]\n                        Space separated list of entry signals to analyse.\n                        Default: all. e.g. 'entry_tag_a entry_tag_b'\n  --exit-reason-list EXIT_REASON_LIST [EXIT_REASON_LIST ...]\n                        Space separated list of exit signals to analyse.\n                        Default: all. e.g.\n                        'exit_tag_a roi stop_loss trailing_stop_loss'\n  --indicator-list INDICATOR_LIST [INDICATOR_LIST ...]\n                        Space separated list of indicators to analyse. e.g.\n                        'close rsi bb_lowerband profit_abs'\n  --timerange YYYYMMDD-[YYYYMMDD]\n                        Timerange to filter trades for analysis, \n                        start inclusive, end exclusive. e.g.\n                        20220101-20220201\n  --rejected\n                        Print out rejected trades table\n  --analysis-to-csv\n                        Write out tables to individual CSVs, by default to \n                        'user_data/backtest_results' unless '--analysis-csv-path' is given.\n  --analysis-csv-path [PATH]\n                        Optional path where individual CSVs will be written. If not used,\n                        CSVs will be written to 'user_data/backtest_results'.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#list-hyperopt-results","title":"List Hyperopt results","text":"

    You can list the hyperoptimization epochs the Hyperopt module evaluated previously with the hyperopt-list sub-command.

    usage: freqtrade hyperopt-list [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                               [-d PATH] [--userdir PATH] [--best]\n                               [--profitable] [--min-trades INT]\n                               [--max-trades INT] [--min-avg-time FLOAT]\n                               [--max-avg-time FLOAT] [--min-avg-profit FLOAT]\n                               [--max-avg-profit FLOAT]\n                               [--min-total-profit FLOAT]\n                               [--max-total-profit FLOAT]\n                               [--min-objective FLOAT] [--max-objective FLOAT]\n                               [--no-color] [--print-json] [--no-details]\n                               [--hyperopt-filename PATH] [--export-csv FILE]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --best                Select only best epochs.\n  --profitable          Select only profitable epochs.\n  --min-trades INT      Select epochs with more than INT trades.\n  --max-trades INT      Select epochs with less than INT trades.\n  --min-avg-time FLOAT  Select epochs above average time.\n  --max-avg-time FLOAT  Select epochs below average time.\n  --min-avg-profit FLOAT\n                        Select epochs above average profit.\n  --max-avg-profit FLOAT\n                        Select epochs below average profit.\n  --min-total-profit FLOAT\n                        Select epochs above total profit.\n  --max-total-profit FLOAT\n                        Select epochs below total profit.\n  --min-objective FLOAT\n                        Select epochs above objective.\n  --max-objective FLOAT\n                        Select epochs below objective.\n  --no-color            Disable colorization of hyperopt results. May be\n                        useful if you are redirecting output to a file.\n  --print-json          Print output in JSON format.\n  --no-details          Do not print best epoch details.\n  --hyperopt-filename FILENAME\n                        Hyperopt result filename.Example: `--hyperopt-\n                        filename=hyperopt_results_2020-09-27_16-20-48.pickle`\n  --export-csv FILE     Export to CSV-File. This will disable table print.\n                        Example: --export-csv hyperopt.csv\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Note

    hyperopt-list will automatically use the latest available hyperopt results file. You can override this using the --hyperopt-filename argument, and specify another, available filename (without path!).

    "},{"location":"utils/#examples_2","title":"Examples","text":"

    List all results, print details of the best result at the end:

    freqtrade hyperopt-list\n

    List only epochs with positive profit. Do not print the details of the best epoch, so that the list can be iterated in a script:

    freqtrade hyperopt-list --profitable --no-details\n

    "},{"location":"utils/#show-details-of-hyperopt-results","title":"Show details of Hyperopt results","text":"

    You can show the details of any hyperoptimization epoch previously evaluated by the Hyperopt module with the hyperopt-show subcommand.

    usage: freqtrade hyperopt-show [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                               [-d PATH] [--userdir PATH] [--best]\n                               [--profitable] [-n INT] [--print-json]\n                               [--hyperopt-filename FILENAME] [--no-header]\n                               [--disable-param-export]\n                               [--breakdown {day,week,month} [{day,week,month} ...]]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --best                Select only best epochs.\n  --profitable          Select only profitable epochs.\n  -n INT, --index INT   Specify the index of the epoch to print details for.\n  --print-json          Print output in JSON format.\n  --hyperopt-filename FILENAME\n                        Hyperopt result filename.Example: `--hyperopt-\n                        filename=hyperopt_results_2020-09-27_16-20-48.pickle`\n  --no-header           Do not print epoch details header.\n  --disable-param-export\n                        Disable automatic hyperopt parameter export.\n  --breakdown {day,week,month} [{day,week,month} ...]\n                        Show backtesting breakdown per [day, week, month].\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n

    Note

    hyperopt-show will automatically use the latest available hyperopt results file. You can override this using the --hyperopt-filename argument, and specify another, available filename (without path!).

    "},{"location":"utils/#examples_3","title":"Examples","text":"

    Print details for the epoch 168 (the number of the epoch is shown by the hyperopt-list subcommand or by Hyperopt itself during hyperoptimization run):

    freqtrade hyperopt-show -n 168\n

    Prints JSON data with details for the last best epoch (i.e., the best of all epochs):

    freqtrade hyperopt-show --best -n -1 --print-json --no-header\n
    "},{"location":"utils/#show-trades","title":"Show trades","text":"

    Print selected (or all) trades from database to screen.

    usage: freqtrade show-trades [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                             [-d PATH] [--userdir PATH] [--db-url PATH]\n                             [--trade-ids TRADE_IDS [TRADE_IDS ...]]\n                             [--print-json]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --db-url PATH         Override trades database URL, this is useful in custom\n                        deployments (default: `sqlite:///tradesv3.sqlite` for\n                        Live Run mode, `sqlite:///tradesv3.dryrun.sqlite` for\n                        Dry Run).\n  --trade-ids TRADE_IDS [TRADE_IDS ...]\n                        Specify the list of trade ids.\n  --print-json          Print output in JSON format.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"utils/#examples_4","title":"Examples","text":"

    Print trades with id 2 and 3 as json

    freqtrade show-trades --db-url sqlite:///tradesv3.sqlite --trade-ids 2 3 --print-json\n
    "},{"location":"utils/#strategy-updater","title":"Strategy-Updater","text":"

    Updates listed strategies or all strategies within the strategies folder to be v3 compliant. If the command runs without --strategy-list then all strategies inside the strategies folder will be converted. Your original strategy will remain available in the user_data/strategies_orig_updater/ directory.

    Conversion results

    Strategy updater will work on a \"best effort\" approach. Please do your due diligence and verify the results of the conversion. We also recommend to run a python formatter (e.g. black) to format results in a sane manner.

    usage: freqtrade strategy-updater [-h] [-v] [--logfile FILE] [-V] [-c PATH]\n                                  [-d PATH] [--userdir PATH]\n                                  [--strategy-list STRATEGY_LIST [STRATEGY_LIST ...]]\n\noptions:\n  -h, --help            show this help message and exit\n  --strategy-list STRATEGY_LIST [STRATEGY_LIST ...]\n                        Provide a space-separated list of strategies to\n                        be converted.\n\nCommon arguments:\n  -v, --verbose         Verbose mode (-vv for more, -vvv to get all messages).\n  --logfile FILE, --log-file FILE\n                        Log to the file specified. Special values are:\n                        'syslog', 'journald'. See the documentation for more\n                        details.\n  -V, --version         show program's version number and exit\n  -c PATH, --config PATH\n                        Specify configuration file (default:\n                        `userdir/config.json` or `config.json` whichever\n                        exists). Multiple --config options may be used. Can be\n                        set to `-` to read config from stdin.\n  -d PATH, --datadir PATH, --data-dir PATH\n                        Path to directory with historical backtesting data.\n  --userdir PATH, --user-data-dir PATH\n                        Path to userdata directory.\n
    "},{"location":"webhook-config/","title":"Webhook usage","text":""},{"location":"webhook-config/#configuration","title":"Configuration","text":"

    Enable webhooks by adding a webhook-section to your configuration file, and setting webhook.enabled to true.

    Sample configuration (tested using IFTTT).

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://maker.ifttt.com/trigger/<YOUREVENT>/with/key/<YOURKEY>/\",\n        \"entry\": {\n            \"value1\": \"Buying {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"{stake_amount:8f} {stake_currency}\"\n        },\n        \"entry_cancel\": {\n            \"value1\": \"Cancelling Open Buy Order for {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"{stake_amount:8f} {stake_currency}\"\n        },\n         \"entry_fill\": {\n            \"value1\": \"Buy Order for {pair} filled\",\n            \"value2\": \"at {open_rate:8f}\",\n            \"value3\": \"\"\n        },\n        \"exit\": {\n            \"value1\": \"Exiting {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"profit: {profit_amount:8f} {stake_currency} ({profit_ratio})\"\n        },\n        \"exit_cancel\": {\n            \"value1\": \"Cancelling Open Exit Order for {pair}\",\n            \"value2\": \"limit {limit:8f}\",\n            \"value3\": \"profit: {profit_amount:8f} {stake_currency} ({profit_ratio})\"\n        },\n        \"exit_fill\": {\n            \"value1\": \"Exit Order for {pair} filled\",\n            \"value2\": \"at {close_rate:8f}.\",\n            \"value3\": \"\"\n        },\n        \"status\": {\n            \"value1\": \"Status: {status}\",\n            \"value2\": \"\",\n            \"value3\": \"\"\n        }\n    },\n

    The url in webhook.url should point to the correct url for your webhook. If you're using IFTTT (as shown in the sample above) please insert your event and key to the url.

    You can set the POST body format to Form-Encoded (default), JSON-Encoded, or raw data. Use \"format\": \"form\", \"format\": \"json\", or \"format\": \"raw\" respectively. Example configuration for Mattermost Cloud integration:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURSUBDOMAIN>.cloud.mattermost.com/hooks/<YOURHOOK>\",\n        \"format\": \"json\",\n        \"status\": {\n            \"text\": \"Status: {status}\"\n        }\n    },\n

    The result would be a POST request with e.g. {\"text\":\"Status: running\"} body and Content-Type: application/json header which results Status: running message in the Mattermost channel.

    When using the Form-Encoded or JSON-Encoded configuration you can configure any number of payload values, and both the key and value will be output in the POST request. However, when using the raw data format you can only configure one value and it must be named \"data\". In this instance the data key will not be output in the POST request, only the value. For example:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURHOOKURL>\",\n        \"format\": \"raw\",\n        \"webhookstatus\": {\n            \"data\": \"Status: {status}\"\n        }\n    },\n

    The result would be a POST request with e.g. Status: running body and Content-Type: text/plain header.

    "},{"location":"webhook-config/#additional-configurations","title":"Additional configurations","text":"

    The webhook.retries parameter can be set for the maximum number of retries the webhook request should attempt if it is unsuccessful (i.e. HTTP response status is not 200). By default this is set to 0 which is disabled. An additional webhook.retry_delay parameter can be set to specify the time in seconds between retry attempts. By default this is set to 0.1 (i.e. 100ms). Note that increasing the number of retries or retry delay may slow down the trader if there are connectivity issues with the webhook. You can also specify webhook.timeout - which defines how long the bot will wait until it assumes the other host as unresponsive (defaults to 10s).

    Example configuration for retries:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURHOOKURL>\",\n        \"timeout\": 10,\n        \"retries\": 3,\n        \"retry_delay\": 0.2,\n        \"status\": {\n            \"status\": \"Status: {status}\"\n        }\n    },\n

    Custom messages can be sent to Webhook endpoints via the self.dp.send_msg() function from within the strategy. To enable this, set the allow_custom_messages option to true:

      \"webhook\": {\n        \"enabled\": true,\n        \"url\": \"https://<YOURHOOKURL>\",\n        \"allow_custom_messages\": true,\n        \"strategy_msg\": {\n            \"status\": \"StrategyMessage: {msg}\"\n        }\n    },\n

    Different payloads can be configured for different events. Not all fields are necessary, but you should configure at least one of the dicts, otherwise the webhook will never be called.

    "},{"location":"webhook-config/#webhook-message-types","title":"Webhook Message types","text":""},{"location":"webhook-config/#entry","title":"Entry","text":"

    The fields in webhook.entry are filled when the bot executes a long/short. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • limit # Deprecated - should no longer be used.
    • open_rate
    • amount
    • open_date
    • stake_amount
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • order_type
    • current_rate
    • enter_tag
    "},{"location":"webhook-config/#entry-cancel","title":"Entry cancel","text":"

    The fields in webhook.entry_cancel are filled when the bot cancels a long/short order. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • limit
    • amount
    • open_date
    • stake_amount
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • order_type
    • current_rate
    • enter_tag
    "},{"location":"webhook-config/#entry-fill","title":"Entry fill","text":"

    The fields in webhook.entry_fill are filled when the bot filled a long/short order. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • open_rate
    • amount
    • open_date
    • stake_amount
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • order_type
    • current_rate
    • enter_tag
    "},{"location":"webhook-config/#exit","title":"Exit","text":"

    The fields in webhook.exit are filled when the bot exits a trade. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • gain
    • limit
    • amount
    • open_rate
    • profit_amount
    • profit_ratio
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • exit_reason
    • order_type
    • open_date
    • close_date
    "},{"location":"webhook-config/#exit-fill","title":"Exit fill","text":"

    The fields in webhook.exit_fill are filled when the bot fills a exit order (closes a Trade). Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • gain
    • close_rate
    • amount
    • open_rate
    • current_rate
    • profit_amount
    • profit_ratio
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • exit_reason
    • order_type
    • open_date
    • close_date
    "},{"location":"webhook-config/#exit-cancel","title":"Exit cancel","text":"

    The fields in webhook.exit_cancel are filled when the bot cancels a exit order. Parameters are filled using string.format. Possible parameters are:

    • trade_id
    • exchange
    • pair
    • direction
    • leverage
    • gain
    • limit
    • amount
    • open_rate
    • current_rate
    • profit_amount
    • profit_ratio
    • stake_currency
    • base_currency
    • quote_currency
    • fiat_currency
    • exit_reason
    • order_type
    • open_date
    • close_date
    "},{"location":"webhook-config/#status","title":"Status","text":"

    The fields in webhook.status are used for regular status messages (Started / Stopped / ...). Parameters are filled using string.format.

    The only possible value here is {status}.

    "},{"location":"webhook-config/#discord","title":"Discord","text":"

    A special form of webhooks is available for discord. You can configure this as follows:

    \"discord\": {\n    \"enabled\": true,\n    \"webhook_url\": \"https://discord.com/api/webhooks/<Your webhook URL ...>\",\n    \"exit_fill\": [\n        {\"Trade ID\": \"{trade_id}\"},\n        {\"Exchange\": \"{exchange}\"},\n        {\"Pair\": \"{pair}\"},\n        {\"Direction\": \"{direction}\"},\n        {\"Open rate\": \"{open_rate}\"},\n        {\"Close rate\": \"{close_rate}\"},\n        {\"Amount\": \"{amount}\"},\n        {\"Open date\": \"{open_date:%Y-%m-%d %H:%M:%S}\"},\n        {\"Close date\": \"{close_date:%Y-%m-%d %H:%M:%S}\"},\n        {\"Profit\": \"{profit_amount} {stake_currency}\"},\n        {\"Profitability\": \"{profit_ratio:.2%}\"},\n        {\"Enter tag\": \"{enter_tag}\"},\n        {\"Exit Reason\": \"{exit_reason}\"},\n        {\"Strategy\": \"{strategy}\"},\n        {\"Timeframe\": \"{timeframe}\"},\n    ],\n    \"entry_fill\": [\n        {\"Trade ID\": \"{trade_id}\"},\n        {\"Exchange\": \"{exchange}\"},\n        {\"Pair\": \"{pair}\"},\n        {\"Direction\": \"{direction}\"},\n        {\"Open rate\": \"{open_rate}\"},\n        {\"Amount\": \"{amount}\"},\n        {\"Open date\": \"{open_date:%Y-%m-%d %H:%M:%S}\"},\n        {\"Enter tag\": \"{enter_tag}\"},\n        {\"Strategy\": \"{strategy} {timeframe}\"},\n    ]\n}\n

    The above represents the default (exit_fill and entry_fill are optional and will default to the above configuration) - modifications are obviously possible. To disable either of the two default values (entry_fill / exit_fill), you can assign them an empty array (exit_fill: []).

    Available fields correspond to the fields for webhooks and are documented in the corresponding webhook sections.

    The notifications will look as follows by default.

    Custom messages can be sent from a strategy to Discord endpoints via the dataprovider.send_msg() function. To enable this, set the allow_custom_messages option to true:

      \"discord\": {\n        \"enabled\": true,\n        \"webhook_url\": \"https://discord.com/api/webhooks/<Your webhook URL ...>\",\n        \"allow_custom_messages\": true,\n    },\n
    "},{"location":"windows_installation/","title":"Windows installation","text":"

    We strongly recommend that Windows users use Docker as this will work much easier and smoother (also more secure).

    If that is not possible, try using the Windows Linux subsystem (WSL) - for which the Ubuntu instructions should work. Otherwise, please follow the instructions below.

    All instructions assume that python 3.9+ is installed and available.

    "},{"location":"windows_installation/#clone-the-git-repository","title":"Clone the git repository","text":"

    First of all clone the repository by running:

    git clone https://github.com/freqtrade/freqtrade.git\n

    Now, choose your installation method, either automatically via script (recommended) or manually following the corresponding instructions.

    "},{"location":"windows_installation/#install-freqtrade-automatically","title":"Install freqtrade automatically","text":""},{"location":"windows_installation/#run-the-installation-script","title":"Run the installation script","text":"

    The script will ask you a few questions to determine which parts should be installed.

    Set-ExecutionPolicy -ExecutionPolicy Bypass\ncd freqtrade\n. .\\setup.ps1\n
    "},{"location":"windows_installation/#install-freqtrade-manually","title":"Install freqtrade manually","text":"

    64bit Python version

    Please make sure to use 64bit Windows and 64bit Python to avoid problems with backtesting or hyperopt due to the memory constraints 32bit applications have under Windows. 32bit python versions are no longer supported under Windows.

    Hint

    Using the Anaconda Distribution under Windows can greatly help with installation problems. Check out the Anaconda installation section in the documentation for more information.

    "},{"location":"windows_installation/#install-ta-lib","title":"Install ta-lib","text":"

    Install ta-lib according to the ta-lib documentation.

    As compiling from source on windows has heavy dependencies (requires a partial visual studio installation), Freqtrade provides these dependencies (in the binary wheel format) for the latest 3 Python versions (3.9, 3.10, 3.11 and 3.12) and for 64bit Windows. These Wheels are also used by CI running on windows, and are therefore tested together with freqtrade.

    Other versions must be downloaded from the above link.

    cd \\path\\freqtrade\npython -m venv .venv\n.venv\\Scripts\\activate.ps1\n# optionally install ta-lib from wheel\n# Eventually adjust the below filename to match the downloaded wheel\npip install --find-links build_helpers\\ TA-Lib -U\npip install -r requirements.txt\npip install -e .\nfreqtrade\n

    Use Powershell

    The above installation script assumes you're using powershell on a 64bit windows. Commands for the legacy CMD windows console may differ.

    "},{"location":"windows_installation/#error-during-installation-on-windows","title":"Error during installation on Windows","text":"
    error: Microsoft Visual C++ 14.0 is required. Get it with \"Microsoft Visual C++ Build Tools\": http://landinghub.visualstudio.com/visual-cpp-build-tools\n

    Unfortunately, many packages requiring compilation don't provide a pre-built wheel. It is therefore mandatory to have a C/C++ compiler installed and available for your python environment to use.

    You can download the Visual C++ build tools from here and install \"Desktop development with C++\" in it's default configuration. Unfortunately, this is a heavy download / dependency so you might want to consider WSL2 or docker compose first.

    "},{"location":"includes/cors/","title":"Cors","text":""},{"location":"includes/cors/#cors","title":"CORS","text":"

    This whole section is only necessary in cross-origin cases (where you multiple bot API's running on localhost:8081, localhost:8082, ...), and want to combine them into one FreqUI instance.

    Technical explanation

    All web-based front-ends are subject to CORS - Cross-Origin Resource Sharing. Since most of the requests to the Freqtrade API must be authenticated, a proper CORS policy is key to avoid security problems. Also, the standard disallows * CORS policies for requests with credentials, so this setting must be set appropriately.

    Users can allow access from different origin URL's to the bot API via the CORS_origins configuration setting. It consists of a list of allowed URL's that are allowed to consume resources from the bot's API.

    Assuming your application is deployed as https://frequi.freqtrade.io/home/ - this would mean that the following configuration becomes necessary:

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"https://frequi.freqtrade.io\"],\n    //...\n}\n

    In the following (pretty common) case, FreqUI is accessible on http://localhost:8080/trade (this is what you see in your navbar when navigating to freqUI).

    The correct configuration for this case is http://localhost:8080 - the main part of the URL including the port.

    {\n    //...\n    \"jwt_secret_key\": \"somethingrandom\",\n    \"CORS_origins\": [\"http://localhost:8080\"],\n    //...\n}\n

    trailing Slash

    The trailing slash is not allowed in the CORS_origins configuration (e.g. \"http://localhots:8080/\"). Such a configuration will not take effect, and the cors errors will remain.

    Note

    We strongly recommend to also set jwt_secret_key to something random and known only to yourself to avoid unauthorized access to your bot.

    "},{"location":"includes/pairlists/","title":"Pairlists","text":""},{"location":"includes/pairlists/#pairlists-and-pairlist-handlers","title":"Pairlists and Pairlist Handlers","text":"

    Pairlist Handlers define the list of pairs (pairlist) that the bot should trade. They are configured in the pairlists section of the configuration settings.

    In your configuration, you can use Static Pairlist (defined by the StaticPairList Pairlist Handler) and Dynamic Pairlist (defined by the VolumePairList and PercentChangePairList Pairlist Handlers).

    Additionally, AgeFilter, PrecisionFilter, PriceFilter, ShuffleFilter, SpreadFilter and VolatilityFilter act as Pairlist Filters, removing certain pairs and/or moving their positions in the pairlist.

    If multiple Pairlist Handlers are used, they are chained and a combination of all Pairlist Handlers forms the resulting pairlist the bot uses for trading and backtesting. Pairlist Handlers are executed in the sequence they are configured. You can define either StaticPairList, VolumePairList, ProducerPairList, RemotePairList, MarketCapPairList or PercentChangePairList as the starting Pairlist Handler.

    Inactive markets are always removed from the resulting pairlist. Explicitly blacklisted pairs (those in the pair_blacklist configuration setting) are also always removed from the resulting pairlist.

    "},{"location":"includes/pairlists/#pair-blacklist","title":"Pair blacklist","text":"

    The pair blacklist (configured via exchange.pair_blacklist in the configuration) disallows certain pairs from trading. This can be as simple as excluding DOGE/BTC - which will remove exactly this pair.

    The pair-blacklist does also support wildcards (in regex-style) - so BNB/.* will exclude ALL pairs that start with BNB. You may also use something like .*DOWN/BTC or .*UP/BTC to exclude leveraged tokens (check Pair naming conventions for your exchange!)

    "},{"location":"includes/pairlists/#available-pairlist-handlers","title":"Available Pairlist Handlers","text":"
    • StaticPairList (default, if not configured differently)
    • VolumePairList
    • PercentChangePairList
    • ProducerPairList
    • RemotePairList
    • MarketCapPairList
    • AgeFilter
    • FullTradesFilter
    • OffsetFilter
    • PerformanceFilter
    • PrecisionFilter
    • PriceFilter
    • ShuffleFilter
    • SpreadFilter
    • RangeStabilityFilter
    • VolatilityFilter

    Testing pairlists

    Pairlist configurations can be quite tricky to get right. Best use the test-pairlist utility sub-command to test your configuration quickly.

    "},{"location":"includes/pairlists/#static-pair-list","title":"Static Pair List","text":"

    By default, the StaticPairList method is used, which uses a statically defined pair whitelist from the configuration. The pairlist also supports wildcards (in regex-style) - so .*/BTC will include all pairs with BTC as a stake.

    It uses configuration from exchange.pair_whitelist and exchange.pair_blacklist.

    \"pairlists\": [\n    {\"method\": \"StaticPairList\"}\n],\n

    By default, only currently enabled pairs are allowed. To skip pair validation against active markets, set \"allow_inactive\": true within the StaticPairList configuration. This can be useful for backtesting expired pairs (like quarterly spot-markets). This option must be configured along with exchange.skip_pair_validation in the exchange configuration.

    When used in a \"follow-up\" position (e.g. after VolumePairlist), all pairs in 'pair_whitelist' will be added to the end of the pairlist.

    "},{"location":"includes/pairlists/#volume-pair-list","title":"Volume Pair List","text":"

    VolumePairList employs sorting/filtering of pairs by their trading volume. It selects number_assets top pairs with sorting based on the sort_key (which can only be quoteVolume).

    When used in the chain of Pairlist Handlers in a non-leading position (after StaticPairList and other Pairlist Filters), VolumePairList considers outputs of previous Pairlist Handlers, adding its sorting/selection of the pairs by the trading volume.

    When used in the leading position of the chain of Pairlist Handlers, the pair_whitelist configuration setting is ignored. Instead, VolumePairList selects the top assets from all available markets with matching stake-currency on the exchange.

    The refresh_period setting allows to define the period (in seconds), at which the pairlist will be refreshed. Defaults to 1800s (30 minutes). The pairlist cache (refresh_period) on VolumePairList is only applicable to generating pairlists. Filtering instances (not the first position in the list) will not apply any cache (beyond caching candles for the duration of the candle in advanced mode) and will always use up-to-date data.

    VolumePairList is per default based on the ticker data from exchange, as reported by the ccxt library:

    • The quoteVolume is the amount of quote (stake) currency traded (bought or sold) in last 24 hours.
    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"max_value\": 8000000,\n        \"refresh_period\": 1800\n    }\n],\n

    You can define a minimum volume with min_value - which will filter out pairs with a volume lower than the specified value in the specified timerange. In addition to that, you can also define a maximum volume with max_value - which will filter out pairs with a volume higher than the specified value in the specified timerange.

    "},{"location":"includes/pairlists/#volumepairlist-advanced-mode","title":"VolumePairList Advanced mode","text":"

    VolumePairList can also operate in an advanced mode to build volume over a given timerange of specified candle size. It utilizes exchange historical candle data, builds a typical price (calculated by (open+high+low)/3) and multiplies the typical price with every candle's volume. The sum is the quoteVolume over the given range. This allows different scenarios, for a more smoothened volume, when using longer ranges with larger candle sizes, or the opposite when using a short range with small candles.

    For convenience lookback_days can be specified, which will imply that 1d candles will be used for the lookback. In the example below the pairlist would be created based on the last 7 days:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 7\n    }\n],\n

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range based volume can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with VolumeFilter to narrow the pairlist down for further range volume calculation.

    Unsupported exchanges

    On some exchanges (like Gemini), regular VolumePairList does not work as the api does not natively provide 24h volume. This can be worked around by using candle data to build the volume. To roughly simulate 24h volume, you can use the following configuration. Please note that These pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    More sophisticated approach can be used, by using lookback_timeframe for candle size and lookback_period which specifies the amount of candles. This example will build the volume pairs based on a rolling period of 3 days of 1h candles:

    \"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    Note

    VolumePairList does not support backtesting mode.

    "},{"location":"includes/pairlists/#percent-change-pair-list","title":"Percent Change Pair List","text":"

    PercentChangePairList filters and sorts pairs based on the percentage change in their price over the last 24 hours or any defined timeframe as part of advanced options. This allows traders to focus on assets that have experienced significant price movements, either positive or negative.

    Configuration Options

    • number_assets: Specifies the number of top pairs to select based on the 24-hour percentage change.
    • min_value: Sets a minimum percentage change threshold. Pairs with a percentage change below this value will be filtered out.
    • max_value: Sets a maximum percentage change threshold. Pairs with a percentage change above this value will be filtered out.
    • sort_direction: Specifies the order in which pairs are sorted based on their percentage change. Accepts two values: asc for ascending order and desc for descending order.
    • refresh_period: Defines the interval (in seconds) at which the pairlist will be refreshed. The default is 1800 seconds (30 minutes).
    • lookback_days: Number of days to look back. When lookback_days is selected, the lookback_timeframe is defaulted to 1 day.
    • lookback_timeframe: Timeframe to use for the lookback period.
    • lookback_period: Number of periods to look back at.

    When PercentChangePairList is used after other Pairlist Handlers, it will operate on the outputs of those handlers. If it is the leading Pairlist Handler, it will select pairs from all available markets with the specified stake currency.

    PercentChangePairList uses ticker data from the exchange, provided via the ccxt library: The percentage change is calculated as the change in price over the last 24 hours.

    Unsupported exchanges

    On some exchanges (like HTX), regular PercentChangePairList does not work as the api does not natively provide 24h percent change in price. This can be worked around by using candle data to calculate the percentage change. To roughly simulate 24h percent change, you can use the following configuration. Please note that these pairlists will only refresh once per day.

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 20,\n        \"min_value\": 0,\n        \"refresh_period\": 86400,\n        \"lookback_days\": 1\n    }\n],\n

    Example Configuration to Read from Ticker

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"min_value\": -10,\n        \"max_value\": 50\n    }\n],\n

    In this configuration:

    1. The top 15 pairs are selected based on the highest percentage change in price over the last 24 hours.
    2. Only pairs with a percentage change between -10% and 50% are considered.

    Example Configuration to Read from Candles

    \"pairlists\": [\n    {\n        \"method\": \"PercentChangePairList\",\n        \"number_assets\": 15,\n        \"sort_key\": \"percentage\",\n        \"min_value\": 0,\n        \"refresh_period\": 3600,\n        \"lookback_timeframe\": \"1h\",\n        \"lookback_period\": 72\n    }\n],\n

    This example builds the percent change pairs based on a rolling period of 3 days of 1-hour candles by using lookback_timeframe for candle size and lookback_period which specifies the number of candles.

    The percent change in price is calculated using the following formula, which expresses the percentage difference between the current candle's close price and the previous candle's close price, as defined by the specified timeframe and lookback period:

    \\[ Percent Change = (\\frac{Current Close - Previous Close}{Previous Close}) * 100 \\]

    Range look back and refresh period

    When used in conjunction with lookback_days and lookback_timeframe the refresh_period can not be smaller than the candle size in seconds. As this will result in unnecessary requests to the exchanges API.

    Performance implications when using lookback range

    If used in first position in combination with lookback, the computation of the range-based percent change can be time and resource consuming, as it downloads candles for all tradable pairs. Hence it's highly advised to use the standard approach with PercentChangePairList to narrow the pairlist down for further percent-change calculation.

    Backtesting

    PercentChangePairList does not support backtesting mode.

    "},{"location":"includes/pairlists/#producerpairlist","title":"ProducerPairList","text":"

    With ProducerPairList, you can reuse the pairlist from a Producer without explicitly defining the pairlist on each consumer.

    Consumer mode is required for this pairlist to work.

    The pairlist will perform a check on active pairs against the current exchange configuration to avoid attempting to trade on invalid markets.

    You can limit the length of the pairlist with the optional parameter number_assets. Using \"number_assets\"=0 or omitting this key will result in the reuse of all producer pairs valid for the current setup.

    \"pairlists\": [\n    {\n        \"method\": \"ProducerPairList\",\n        \"number_assets\": 5,\n        \"producer_name\": \"default\",\n    }\n],\n

    Combining pairlists

    This pairlist can be combined with all other pairlists and filters for further pairlist reduction, and can also act as an \"additional\" pairlist, on top of already defined pairs. ProducerPairList can also be used multiple times in sequence, combining the pairs from multiple producers. Obviously in complex such configurations, the Producer may not provide data for all pairs, so the strategy must be fit for this.

    "},{"location":"includes/pairlists/#remotepairlist","title":"RemotePairList","text":"

    It allows the user to fetch a pairlist from a remote server or a locally stored json file within the freqtrade directory, enabling dynamic updates and customization of the trading pairlist.

    The RemotePairList is defined in the pairlists section of the configuration settings. It uses the following configuration options:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"processing_mode\": \"filter\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"bearer_token\": \"my-bearer-token\",\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    The optional mode option specifies if the pairlist should be used as a blacklist or as a whitelist. The default value is \"whitelist\".

    The optional processing_mode option in the RemotePairList configuration determines how the retrieved pairlist is processed. It can have two values: \"filter\" or \"append\". The default value is \"filter\".

    In \"filter\" mode, the retrieved pairlist is used as a filter. Only the pairs present in both the original pairlist and the retrieved pairlist are included in the final pairlist. Other pairs are filtered out.

    In \"append\" mode, the retrieved pairlist is added to the original pairlist. All pairs from both lists are included in the final pairlist without any filtering.

    The pairlist_url option specifies the URL of the remote server where the pairlist is located, or the path to a local file (if file:/// is prepended). This allows the user to use either a remote server or a local file as the source for the pairlist.

    The save_to_file option, when provided with a valid filename, saves the processed pairlist to that file in JSON format. This option is optional, and by default, the pairlist is not saved to a file.

    Multi bot with shared pairlist example

    save_to_file can be used to save the pairlist to a file with Bot1:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"https://example.com/pairlist\",\n        \"number_assets\": 10,\n        \"refresh_period\": 1800,\n        \"keep_pairlist_on_failure\": true,\n        \"read_timeout\": 60,\n        \"save_to_file\": \"user_data/filename.json\" \n    }\n]\n

    This saved pairlist file can be loaded by Bot2, or any additional bot with this configuration:

    \"pairlists\": [\n    {\n        \"method\": \"RemotePairList\",\n        \"mode\": \"whitelist\",\n        \"pairlist_url\": \"file:///user_data/filename.json\",\n        \"number_assets\": 10,\n        \"refresh_period\": 10,\n        \"keep_pairlist_on_failure\": true,\n    }\n]\n

    The user is responsible for providing a server or local file that returns a JSON object with the following structure:

    {\n    \"pairs\": [\"XRP/USDT\", \"ETH/USDT\", \"LTC/USDT\"],\n    \"refresh_period\": 1800\n}\n

    The pairs property should contain a list of strings with the trading pairs to be used by the bot. The refresh_period property is optional and specifies the number of seconds that the pairlist should be cached before being refreshed.

    The optional keep_pairlist_on_failure specifies whether the previous received pairlist should be used if the remote server is not reachable or returns an error. The default value is true.

    The optional read_timeout specifies the maximum amount of time (in seconds) to wait for a response from the remote source, The default value is 60.

    The optional bearer_token will be included in the requests Authorization Header.

    Note

    In case of a server error the last received pairlist will be kept if keep_pairlist_on_failure is set to true, when set to false a empty pairlist is returned.

    "},{"location":"includes/pairlists/#marketcappairlist","title":"MarketCapPairList","text":"

    MarketCapPairList employs sorting/filtering of pairs by their marketcap rank based of CoinGecko. It will only recognize coins up to the coin placed at rank 250. The returned pairlist will be sorted based of their marketcap ranks.

    \"pairlists\": [\n    {\n        \"method\": \"MarketCapPairList\",\n        \"number_assets\": 20,\n        \"max_rank\": 50,\n        \"refresh_period\": 86400\n    }\n]\n

    number_assets defines the maximum number of pairs returned by the pairlist. max_rank will determine the maximum rank used in creating/filtering the pairlist. It's expected that some coins within the top max_rank marketcap will not be included in the resulting pairlist since not all pairs will have active trading pairs in your preferred market/stake/exchange combination.

    refresh_period setting defines the period (in seconds) at which the marketcap rank data will be refreshed. Defaults to 86,400s (1 day). The pairlist cache (refresh_period) is applicable on both generating pairlists (first position in the list) and filtering instances (not the first position in the list).

    "},{"location":"includes/pairlists/#agefilter","title":"AgeFilter","text":"

    Removes pairs that have been listed on the exchange for less than min_days_listed days (defaults to 10) or more than max_days_listed days (defaults None mean infinity).

    When pairs are first listed on an exchange they can suffer huge price drops and volatility in the first few days while the pair goes through its price-discovery period. Bots can often be caught out buying before the pair has finished dropping in price.

    This filter allows freqtrade to ignore pairs until they have been listed for at least min_days_listed days and listed before max_days_listed.

    "},{"location":"includes/pairlists/#fulltradesfilter","title":"FullTradesFilter","text":"

    Shrink whitelist to consist only in-trade pairs when the trade slots are full (when max_open_trades isn't being set to -1 in the config).

    When the trade slots are full, there is no need to calculate indicators of the rest of the pairs (except informative pairs) since no new trade can be opened. By shrinking the whitelist to just the in-trade pairs, you can improve calculation speeds and reduce CPU usage. When a trade slot is free (either a trade is closed or max_open_trades value in config is increased), then the whitelist will return to normal state.

    When multiple pairlist filters are being used, it's recommended to put this filter at second position directly below the primary pairlist, so when the trade slots are full, the bot doesn't have to download data for the rest of the filters.

    Backtesting

    FullTradesFilter does not support backtesting mode.

    "},{"location":"includes/pairlists/#offsetfilter","title":"OffsetFilter","text":"

    Offsets an incoming pairlist by a given offset value.

    As an example it can be used in conjunction with VolumeFilter to remove the top X volume pairs. Or to split a larger pairlist on two bot instances.

    Example to remove the first 10 pairs from the pairlist, and takes the next 20 (taking items 10-30 of the initial list):

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"OffsetFilter\",\n        \"offset\": 10,\n        \"number_assets\": 20\n    }\n],\n

    Warning

    When OffsetFilter is used to split a larger pairlist among multiple bots in combination with VolumeFilter it can not be guaranteed that pairs won't overlap due to slightly different refresh intervals for the VolumeFilter.

    Note

    An offset larger than the total length of the incoming pairlist will result in an empty pairlist.

    "},{"location":"includes/pairlists/#performancefilter","title":"PerformanceFilter","text":"

    Sorts pairs by past trade performance, as follows:

    1. Positive performance.
    2. No closed trades yet.
    3. Negative performance.

    Trade count is used as a tie breaker.

    You can use the minutes parameter to only consider performance of the past X minutes (rolling window). Not defining this parameter (or setting it to 0) will use all-time performance.

    The optional min_profit (as ratio -> a setting of 0.01 corresponds to 1%) parameter defines the minimum profit a pair must have to be considered. Pairs below this level will be filtered out. Using this parameter without minutes is highly discouraged, as it can lead to an empty pairlist without a way to recover.

    \"pairlists\": [\n    // ...\n    {\n        \"method\": \"PerformanceFilter\",\n        \"minutes\": 1440,  // rolling 24h\n        \"min_profit\": 0.01  // minimal profit 1%\n    }\n],\n

    As this Filter uses past performance of the bot, it'll have some startup-period - and should only be used after the bot has a few 100 trades in the database.

    Backtesting

    PerformanceFilter does not support backtesting mode.

    "},{"location":"includes/pairlists/#precisionfilter","title":"PrecisionFilter","text":"

    Filters low-value coins which would not allow setting stoplosses.

    Namely, pairs are blacklisted if a variance of one percent or more in the stop price would be caused by precision rounding on the exchange, i.e. rounded(stop_price) <= rounded(stop_price * 0.99). The idea is to avoid coins with a value VERY close to their lower trading boundary, not allowing setting of proper stoploss.

    PrecisionFilter is pointless for futures trading

    The above does not apply to shorts. And for longs, in theory the trade will be liquidated first.

    Backtesting

    PrecisionFilter does not support backtesting mode using multiple strategies.

    "},{"location":"includes/pairlists/#pricefilter","title":"PriceFilter","text":"

    The PriceFilter allows filtering of pairs by price. Currently the following price filters are supported:

    • min_price
    • max_price
    • max_value
    • low_price_ratio

    The min_price setting removes pairs where the price is below the specified price. This is useful if you wish to avoid trading very low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_price setting removes pairs where the price is above the specified price. This is useful if you wish to trade only low-priced pairs. This option is disabled by default, and will only apply if set to > 0.

    The max_value setting removes pairs where the minimum value change is above a specified value. This is useful when an exchange has unbalanced limits. For example, if step-size = 1 (so you can only buy 1, or 2, or 3, but not 1.1 Coins) - and the price is pretty high (like 20$) as the coin has risen sharply since the last limit adaption. As a result of the above, you can only buy for 20$, or 40$ - but not for 25$. On exchanges that deduct fees from the receiving currency (e.g. binance) - this can result in high value coins / amounts that are unsellable as the amount is slightly below the limit.

    The low_price_ratio setting removes pairs where a raise of 1 price unit (pip) is above the low_price_ratio ratio. This option is disabled by default, and will only apply if set to > 0.

    For PriceFilter at least one of its min_price, max_price or low_price_ratio settings must be applied.

    Calculation example:

    Min price precision for SHITCOIN/BTC is 8 decimals. If its price is 0.00000011 - one price step above would be 0.00000012, which is ~9% higher than the previous price value. You may filter out this pair by using PriceFilter with low_price_ratio set to 0.09 (9%) or with min_price set to 0.00000011, correspondingly.

    Low priced pairs

    Low priced pairs with high \"1 pip movements\" are dangerous since they are often illiquid and it may also be impossible to place the desired stoploss, which can often result in high losses since price needs to be rounded to the next tradable price - so instead of having a stoploss of -5%, you could end up with a stoploss of -9% simply due to price rounding.

    "},{"location":"includes/pairlists/#shufflefilter","title":"ShuffleFilter","text":"

    Shuffles (randomizes) pairs in the pairlist. It can be used for preventing the bot from trading some of the pairs more frequently then others when you want all pairs be treated with the same priority.

    By default, ShuffleFilter will shuffle pairs once per candle. To shuffle on every iteration, set \"shuffle_frequency\" to \"iteration\" instead of the default of \"candle\".

        {\n        \"method\": \"ShuffleFilter\", \n        \"shuffle_frequency\": \"candle\",\n        \"seed\": 42\n    }\n

    Tip

    You may set the seed value for this Pairlist to obtain reproducible results, which can be useful for repeated backtesting sessions. If seed is not set, the pairs are shuffled in the non-repeatable random order. ShuffleFilter will automatically detect runmodes and apply the seed only for backtesting modes - if a seed value is set.

    "},{"location":"includes/pairlists/#spreadfilter","title":"SpreadFilter","text":"

    Removes pairs that have a difference between asks and bids above the specified ratio, max_spread_ratio (defaults to 0.005).

    Example:

    If DOGE/BTC maximum bid is 0.00000026 and minimum ask is 0.00000027, the ratio is calculated as: 1 - bid/ask ~= 0.037 which is > 0.005 and this pair will be filtered out.

    "},{"location":"includes/pairlists/#rangestabilityfilter","title":"RangeStabilityFilter","text":"

    Removes pairs where the difference between lowest low and highest high over lookback_days days is below min_rate_of_change or above max_rate_of_change. Since this is a filter that requires additional data, the results are cached for refresh_period.

    In the below example: If the trading range over the last 10 days is <1% or >99%, remove the pair from the whitelist.

    \"pairlists\": [\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"max_rate_of_change\": 0.99,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting for this pairlist.

    Tip

    This Filter can be used to automatically remove stable coin pairs, which have a very low trading range, and are therefore extremely difficult to trade with profit. Additionally, it can also be used to automatically remove pairs with extreme high/low variance over a given amount of time.

    "},{"location":"includes/pairlists/#volatilityfilter","title":"VolatilityFilter","text":"

    Volatility is the degree of historical variation of a pairs over time, it is measured by the standard deviation of logarithmic daily returns. Returns are assumed to be normally distributed, although actual distribution might be different. In a normal distribution, 68% of observations fall within one standard deviation and 95% of observations fall within two standard deviations. Assuming a volatility of 0.05 means that the expected returns for 20 out of 30 days is expected to be less than 5% (one standard deviation). Volatility is a positive ratio of the expected deviation of return and can be greater than 1.00. Please refer to the wikipedia definition of volatility.

    This filter removes pairs if the average volatility over a lookback_days days is below min_volatility or above max_volatility. Since this is a filter that requires additional data, the results are cached for refresh_period.

    This filter can be used to narrow down your pairs to a certain volatility or avoid very volatile pairs.

    In the below example: If the volatility over the last 10 days is not in the range of 0.05-0.50, remove the pair from the whitelist. The filter is applied every 24h.

    \"pairlists\": [\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    }\n]\n

    Adding \"sort_direction\": \"asc\" or \"sort_direction\": \"desc\" enables sorting mode for this pairlist.

    "},{"location":"includes/pairlists/#full-example-of-pairlist-handlers","title":"Full example of Pairlist Handlers","text":"

    The below example blacklists BNB/BTC, uses VolumePairList with 20 assets, sorting pairs by quoteVolume and applies PrecisionFilter and PriceFilter, filtering all assets where 1 price unit is > 1%. Then the SpreadFilter and VolatilityFilter is applied and pairs are finally shuffled with the random seed set to some predefined value.

    \"exchange\": {\n    \"pair_whitelist\": [],\n    \"pair_blacklist\": [\"BNB/BTC\"]\n},\n\"pairlists\": [\n    {\n        \"method\": \"VolumePairList\",\n        \"number_assets\": 20,\n        \"sort_key\": \"quoteVolume\"\n    },\n    {\"method\": \"AgeFilter\", \"min_days_listed\": 10},\n    {\"method\": \"PrecisionFilter\"},\n    {\"method\": \"PriceFilter\", \"low_price_ratio\": 0.01},\n    {\"method\": \"SpreadFilter\", \"max_spread_ratio\": 0.005},\n    {\n        \"method\": \"RangeStabilityFilter\",\n        \"lookback_days\": 10,\n        \"min_rate_of_change\": 0.01,\n        \"refresh_period\": 86400\n    },\n    {\n        \"method\": \"VolatilityFilter\",\n        \"lookback_days\": 10,\n        \"min_volatility\": 0.05,\n        \"max_volatility\": 0.50,\n        \"refresh_period\": 86400\n    },\n    {\"method\": \"ShuffleFilter\", \"seed\": 42}\n],\n
    "},{"location":"includes/pricing/","title":"Pricing","text":""},{"location":"includes/pricing/#prices-used-for-orders","title":"Prices used for orders","text":"

    Prices for regular orders can be controlled via the parameter structures entry_pricing for trade entries and exit_pricing for trade exits. Prices are always retrieved right before an order is placed, either by querying the exchange tickers or by using the orderbook data.

    Note

    Orderbook data used by Freqtrade are the data retrieved from exchange by the ccxt's function fetch_order_book(), i.e. are usually data from the L2-aggregated orderbook, while the ticker data are the structures returned by the ccxt's fetch_ticker()/fetch_tickers() functions. Refer to the ccxt library documentation for more details.

    Using market orders

    Please read the section Market order pricing section when using market orders.

    "},{"location":"includes/pricing/#entry-price","title":"Entry price","text":""},{"location":"includes/pricing/#enter-price-side","title":"Enter price side","text":"

    The configuration setting entry_pricing.price_side defines the side of the orderbook the bot looks for when buying.

    The following displays an orderbook.

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If entry_pricing.price_side is set to \"bid\", then the bot will use 99 as entry price. In line with that, if entry_pricing.price_side is set to \"ask\", then the bot will use 101 as entry price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    direction Order setting price crosses spread long buy ask 101 yes long buy bid 99 no long buy same 99 no long buy other 101 yes short sell ask 101 no short sell bid 99 yes short sell same 101 no short sell other 99 yes

    Using the other side of the orderbook often guarantees quicker filled orders, but the bot can also end up paying more than what would have been necessary. Taker fees instead of maker fees will most likely apply even when using limit buy orders. Also, prices at the \"other\" side of the spread are higher than prices at the \"bid\" side in the orderbook, so the order behaves similar to a market order (however with a maximum price).

    "},{"location":"includes/pricing/#entry-price-with-orderbook-enabled","title":"Entry price with Orderbook enabled","text":"

    When entering a trade with the orderbook enabled (entry_pricing.use_order_book=True), Freqtrade fetches the entry_pricing.order_book_top entries from the orderbook and uses the entry specified as entry_pricing.order_book_top on the configured side (entry_pricing.price_side) of the orderbook. 1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"includes/pricing/#entry-price-without-orderbook-enabled","title":"Entry price without Orderbook enabled","text":"

    The following section uses side as the configured entry_pricing.price_side (defaults to \"same\").

    When not using orderbook (entry_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's below the last traded price from the ticker. Otherwise (when the side price is above the last price), it calculates a rate between side and last price based on entry_pricing.price_last_balance.

    The entry_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between ask and last price.

    "},{"location":"includes/pricing/#check-depth-of-market","title":"Check depth of market","text":"

    When check depth of market is enabled (entry_pricing.check_depth_of_market.enabled=True), the entry signals are filtered based on the orderbook depth (sum of all amounts) for each orderbook side.

    Orderbook bid (buy) side depth is then divided by the orderbook ask (sell) side depth and the resulting delta is compared to the value of the entry_pricing.check_depth_of_market.bids_to_ask_delta parameter. The entry order is only executed if the orderbook delta is greater than or equal to the configured delta value.

    Note

    A delta value below 1 means that ask (sell) orderbook side depth is greater than the depth of the bid (buy) orderbook side, while a value greater than 1 means opposite (depth of the buy side is higher than the depth of the sell side).

    "},{"location":"includes/pricing/#exit-price","title":"Exit price","text":""},{"location":"includes/pricing/#exit-price-side","title":"Exit price side","text":"

    The configuration setting exit_pricing.price_side defines the side of the spread the bot looks for when exiting a trade.

    The following displays an orderbook:

    ...\n103\n102\n101  # ask\n-------------Current spread\n99   # bid\n98\n97\n...\n

    If exit_pricing.price_side is set to \"ask\", then the bot will use 101 as exiting price. In line with that, if exit_pricing.price_side is set to \"bid\", then the bot will use 99 as exiting price.

    Depending on the order direction (long/short), this will lead to different results. Therefore we recommend to use \"same\" or \"other\" for this configuration instead. This would result in the following pricing matrix:

    Direction Order setting price crosses spread long sell ask 101 no long sell bid 99 yes long sell same 101 no long sell other 99 yes short buy ask 101 yes short buy bid 99 no short buy same 99 no short buy other 101 yes"},{"location":"includes/pricing/#exit-price-with-orderbook-enabled","title":"Exit price with Orderbook enabled","text":"

    When exiting with the orderbook enabled (exit_pricing.use_order_book=True), Freqtrade fetches the exit_pricing.order_book_top entries in the orderbook and uses the entry specified as exit_pricing.order_book_top from the configured side (exit_pricing.price_side) as trade exit price.

    1 specifies the topmost entry in the orderbook, while 2 would use the 2nd entry in the orderbook, and so on.

    "},{"location":"includes/pricing/#exit-price-without-orderbook-enabled","title":"Exit price without Orderbook enabled","text":"

    The following section uses side as the configured exit_pricing.price_side (defaults to \"ask\").

    When not using orderbook (exit_pricing.use_order_book=False), Freqtrade uses the best side price from the ticker if it's above the last traded price from the ticker. Otherwise (when the side price is below the last price), it calculates a rate between side and last price based on exit_pricing.price_last_balance.

    The exit_pricing.price_last_balance configuration parameter controls this. A value of 0.0 will use side price, while 1.0 will use the last price and values between those interpolate between side and last price.

    "},{"location":"includes/pricing/#market-order-pricing","title":"Market order pricing","text":"

    When using market orders, prices should be configured to use the \"correct\" side of the orderbook to allow realistic pricing detection. Assuming both entry and exits are using market orders, a configuration similar to the following must be used

      \"order_types\": {\n    \"entry\": \"market\",\n    \"exit\": \"market\"\n    // ...\n  },\n  \"entry_pricing\": {\n    \"price_side\": \"other\",\n    // ...\n  },\n  \"exit_pricing\":{\n    \"price_side\": \"other\",\n    // ...\n  },\n

    Obviously, if only one side is using limit orders, different pricing combinations can be used.

    "},{"location":"includes/protections/","title":"Protections","text":""},{"location":"includes/protections/#protections","title":"Protections","text":"

    Beta feature

    This feature is still in it's testing phase. Should you notice something you think is wrong please let us know via Discord or via Github Issue.

    Protections will protect your strategy from unexpected events and market conditions by temporarily stop trading for either one pair, or for all pairs. All protection end times are rounded up to the next candle to avoid sudden, unexpected intra-candle buys.

    Note

    Not all Protections will work for all strategies, and parameters will need to be tuned for your strategy to improve performance.

    Tip

    Each Protection can be configured multiple times with different parameters, to allow different levels of protection (short-term / long-term).

    Backtesting

    Protections are supported by backtesting and hyperopt, but must be explicitly enabled by using the --enable-protections flag.

    Setting protections from the configuration

    Setting protections from the configuration via \"protections\": [], key should be considered deprecated and will be removed in a future version. It is also no longer guaranteed that your protections apply to the strategy in cases where the strategy defines protections as property.

    "},{"location":"includes/protections/#available-protections","title":"Available Protections","text":"
    • StoplossGuard Stop trading if a certain amount of stoploss occurred within a certain time window.
    • MaxDrawdown Stop trading if max-drawdown is reached.
    • LowProfitPairs Lock pairs with low profits
    • CooldownPeriod Don't enter a trade right after selling a trade.
    "},{"location":"includes/protections/#common-settings-to-all-protections","title":"Common settings to all Protections","text":"Parameter Description method Protection name to use. Datatype: String, selected from available Protections stop_duration_candles For how many candles should the lock be set? Datatype: Positive integer (in candles) stop_duration how many minutes should protections be locked. Cannot be used together with stop_duration_candles. Datatype: Float (in minutes) lookback_period_candles Only trades that completed within the last lookback_period_candles candles will be considered. This setting may be ignored by some Protections. Datatype: Positive integer (in candles). lookback_period Only trades that completed after current_time - lookback_period will be considered. Cannot be used together with lookback_period_candles. This setting may be ignored by some Protections. Datatype: Float (in minutes) trade_limit Number of trades required at minimum (not used by all Protections). Datatype: Positive integer unlock_at Time when trading will be unlocked regularly (not used by all Protections). Datatype: string Input Format: \"HH:MM\" (24-hours)

    Durations

    Durations (stop_duration* and lookback_period* can be defined in either minutes or candles). For more flexibility when testing different timeframes, all below examples will use the \"candle\" definition.

    "},{"location":"includes/protections/#stoploss-guard","title":"Stoploss Guard","text":"

    StoplossGuard selects all trades within lookback_period in minutes (or in candles when using lookback_period_candles). If trade_limit or more trades resulted in stoploss, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    This applies across all pairs, unless only_per_pair is set to true, which will then only look at one pair at a time.

    Similarly, this protection will by default look at all trades (long and short). For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long stoplosses.

    required_profit will determine the required relative profit (or loss) for stoplosses to consider. This should normally not be set and defaults to 0.0 - which means all losing stoplosses will be triggering a block.

    The below example stops trading for all pairs for 4 candles after the last trade if the bot hit stoploss 4 times within the last 24 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"StoplossGuard\",\n            \"lookback_period_candles\": 24,\n            \"trade_limit\": 4,\n            \"stop_duration_candles\": 4,\n            \"required_profit\": 0.0,\n            \"only_per_pair\": False,\n            \"only_per_side\": False\n        }\n    ]\n

    Note

    StoplossGuard considers all trades with the results \"stop_loss\", \"stoploss_on_exchange\" and \"trailing_stop_loss\" if the resulting profit was negative. trade_limit and lookback_period will need to be tuned for your strategy.

    "},{"location":"includes/protections/#maxdrawdown","title":"MaxDrawdown","text":"

    MaxDrawdown uses all trades within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the maximum drawdown. If the drawdown is below max_allowed_drawdown, trading will stop for stop_duration in minutes (or in candles when using stop_duration_candles) after the last trade - assuming that the bot needs some time to let markets recover.

    The below sample stops trading for 12 candles if max-drawdown is > 20% considering all pairs - with a minimum of trade_limit trades - within the last 48 candles. If desired, lookback_period and/or stop_duration can be used.

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"MaxDrawdown\",\n            \"lookback_period_candles\": 48,\n            \"trade_limit\": 20,\n            \"stop_duration_candles\": 12,\n            \"max_allowed_drawdown\": 0.2\n        },\n    ]\n
    "},{"location":"includes/protections/#low-profit-pairs","title":"Low Profit Pairs","text":"

    LowProfitPairs uses all trades for a pair within lookback_period in minutes (or in candles when using lookback_period_candles) to determine the overall profit ratio. If that ratio is below required_profit, that pair will be locked for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at).

    For futures bots, setting only_per_side will make the bot only consider one side, and will then only lock this one side, allowing for example shorts to continue after a series of long losses.

    The below example will stop trading a pair for 60 minutes if the pair does not have a required profit of 2% (and a minimum of 2 trades) within the last 6 candles.

    @property\ndef protections(self):\n    return [\n        {\n            \"method\": \"LowProfitPairs\",\n            \"lookback_period_candles\": 6,\n            \"trade_limit\": 2,\n            \"stop_duration\": 60,\n            \"required_profit\": 0.02,\n            \"only_per_pair\": False,\n        }\n    ]\n
    "},{"location":"includes/protections/#cooldown-period","title":"Cooldown Period","text":"

    CooldownPeriod locks a pair for stop_duration in minutes (or in candles when using stop_duration_candles, or until the set time when using unlock_at) after exiting, avoiding a re-entry for this pair for stop_duration minutes.

    The below example will stop trading a pair for 2 candles after closing a trade, allowing this pair to \"cool down\".

    @property\ndef protections(self):\n    return  [\n        {\n            \"method\": \"CooldownPeriod\",\n            \"stop_duration_candles\": 2\n        }\n    ]\n

    Note

    This Protection applies only at pair-level, and will never lock all pairs globally. This Protection does not consider lookback_period as it only looks at the latest trade.

    "},{"location":"includes/protections/#full-example-of-protections","title":"Full example of Protections","text":"

    All protections can be combined at will, also with different parameters, creating a increasing wall for under-performing pairs. All protections are evaluated in the sequence they are defined.

    The below example assumes a timeframe of 1 hour:

    • Locks each pair after selling for an additional 5 candles (CooldownPeriod), giving other pairs a chance to get filled.
    • Stops trading for 4 hours (4 * 1h candles) if the last 2 days (48 * 1h candles) had 20 trades, which caused a max-drawdown of more than 20%. (MaxDrawdown).
    • Stops trading if more than 4 stoploss occur for all pairs within a 1 day (24 * 1h candles) limit (StoplossGuard).
    • Locks all pairs that had 2 Trades within the last 6 hours (6 * 1h candles) with a combined profit ratio of below 0.02 (<2%) (LowProfitPairs).
    • Locks all pairs for 2 candles that had a profit of below 0.01 (<1%) within the last 24h (24 * 1h candles), a minimum of 4 trades.
    from freqtrade.strategy import IStrategy\n\nclass AwesomeStrategy(IStrategy)\n    timeframe = '1h'\n\n    @property\n    def protections(self):\n        return [\n            {\n                \"method\": \"CooldownPeriod\",\n                \"stop_duration_candles\": 5\n            },\n            {\n                \"method\": \"MaxDrawdown\",\n                \"lookback_period_candles\": 48,\n                \"trade_limit\": 20,\n                \"stop_duration_candles\": 4,\n                \"max_allowed_drawdown\": 0.2\n            },\n            {\n                \"method\": \"StoplossGuard\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"only_per_pair\": False\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 6,\n                \"trade_limit\": 2,\n                \"stop_duration_candles\": 60,\n                \"required_profit\": 0.02\n            },\n            {\n                \"method\": \"LowProfitPairs\",\n                \"lookback_period_candles\": 24,\n                \"trade_limit\": 4,\n                \"stop_duration_candles\": 2,\n                \"required_profit\": 0.01\n            }\n        ]\n    # ...\n
    "},{"location":"includes/release_template/","title":"Release template","text":""},{"location":"includes/release_template/#highlighted-changes","title":"Highlighted changes","text":"
    • ...
    "},{"location":"includes/release_template/#how-to-update","title":"How to update","text":"

    As always, you can update your bot using one of the following commands:

    "},{"location":"includes/release_template/#docker-compose","title":"docker-compose","text":"
    docker-compose pull\ndocker-compose up -d\n
    "},{"location":"includes/release_template/#installation-via-setup-script","title":"Installation via setup script","text":"
    # Deactivate venv and run \n./setup.sh --update\n
    "},{"location":"includes/release_template/#plain-native-installation","title":"Plain native installation","text":"
    git pull\npip install -U -r requirements.txt\n
    Expand full changelog
    <Paste your changelog here>\n
    "},{"location":"includes/showcase/","title":"Showcase","text":"

    This section will highlight a few projects from members of the community.

    Note

    The projects below are for the most part not maintained by the freqtrade , therefore use your own caution before using them.

    • Example freqtrade strategies
    • FrequentHippo - Grafana dashboard with dry/live runs and backtests (by hippocritical).
    • Online pairlist generator (by Blood4rc).
    • Freqtrade Backtesting Project (by Blood4rc).
    • Freqtrade analysis notebook (by Froggleston).
    • TUI for freqtrade (by Froggleston).
    • Bot Academy (by stash86) - Blog about crypto bot projects.
    "},{"location":"includes/strategy-imports/","title":"Strategy imports","text":""},{"location":"includes/strategy-imports/#imports-necessary-for-a-strategy","title":"Imports necessary for a strategy","text":"

    When creating a strategy, you will need to import the necessary modules and classes. The following imports are required for a strategy:

    By default, we recommend the following imports as a base line for your strategy: This will cover all imports necessary for freqtrade functions to work. Obviously you can add more imports as needed for your strategy.

    # flake8: noqa: F401\n# isort: skip_file\n# --- Do not remove these imports ---\nimport numpy as np\nimport pandas as pd\nfrom datetime import datetime, timedelta, timezone\nfrom pandas import DataFrame\nfrom typing import Dict, Optional, Union, Tuple\n\nfrom freqtrade.strategy import (\n    IStrategy,\n    Trade, \n    Order,\n    PairLocks,\n    informative,  # @informative decorator\n    # Hyperopt Parameters\n    BooleanParameter,\n    CategoricalParameter,\n    DecimalParameter,\n    IntParameter,\n    RealParameter,\n    # timeframe helpers\n    timeframe_to_minutes,\n    timeframe_to_next_date,\n    timeframe_to_prev_date,\n    # Strategy helper functions\n    merge_informative_pair,\n    stoploss_from_absolute,\n    stoploss_from_open,\n)\n\n# --------------------------------\n# Add your lib to import here\nimport talib.abstract as ta\nfrom technical import qtpylib\n
    "}]} \ No newline at end of file