<metaname="description"content="Freqtrade is a free and open source crypto trading bot written in Python, designed to support all major exchanges and be controlled via Telegram or builtin Web UI">
<inputclass="md-option"data-md-color-media=""data-md-color-scheme="default"data-md-color-primary="blue-grey"data-md-color-accent="tear"aria-label="Switch to dark mode"type="radio"name="__palette"id="__palette_0">
<labelclass="md-header__button md-icon"title="Switch to dark mode"for="__palette_1"hidden>
<inputclass="md-option"data-md-color-media=""data-md-color-scheme="slate"data-md-color-primary="blue-grey"data-md-color-accent="tear"aria-label="Switch to light mode"type="radio"name="__palette"id="__palette_1">
<labelclass="md-header__button md-icon"title="Switch to light mode"for="__palette_0"hidden>
<p>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 <code>scikit-optimize</code> 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.</p>
<p>In general, the search for best parameters starts with a few random combinations (see <ahref="#reproducible-results">below</a> 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 <ahref="#loss-functions">loss function</a>.</p>
<p>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 <ahref="../data-download/">Data Downloading</a> section of the documentation.</p>
<divclass="admonition bug">
<pclass="admonition-title">Bug</p>
<p>Hyperopt can crash when used with only 1 CPU Core as found out in <ahref="https://github.com/freqtrade/freqtrade/issues/1133">Issue #1133</a></p>
</div>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>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.</p>
<p>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.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>Since Hyperopt is a resource intensive process, running it on a Raspberry Pi is not recommended nor supported.</p>
<p>Checklist on all tasks / possibilities in hyperopt</p>
<p>Depending on the space you want to optimize, only some of the below are required:</p>
<ul>
<li>define parameters with <code>space='buy'</code> - for entry signal optimization</li>
<li>define parameters with <code>space='sell'</code> - for exit signal optimization</li>
</ul>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p><code>populate_indicators</code> needs to create all indicators any of the spaces may use, otherwise hyperopt will not work.</p>
</div>
<p>Rarely you may also need to create a <ahref="../advanced-hyperopt/#overriding-pre-defined-spaces">nested class</a> named <code>HyperOpt</code> and implement</p>
<ul>
<li><code>roi_space</code> - for custom ROI optimization (if you need the ranges for the ROI parameters in the optimization hyperspace that differ from default)</li>
<li><code>generate_roi_table</code> - 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)</li>
<li><code>stoploss_space</code> - for custom stoploss optimization (if you need the range for the stoploss parameter in the optimization hyperspace that differs from default)</li>
<li><code>trailing_space</code> - for custom trailing stop optimization (if you need the ranges for the trailing stop parameters in the optimization hyperspace that differ from default)</li>
<li><code>max_open_trades_space</code> - 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)</li>
</ul>
<divclass="admonition tip">
<pclass="admonition-title">Quickly optimize ROI, stoploss and trailing stoploss</p>
<p>You can quickly optimize the spaces <code>roi</code>, <code>stoploss</code> and <code>trailing</code> without changing anything in your strategy.</p>
<divclass="highlight"><pre><span></span><code><spanclass="c1"># Have a working strategy at hand.</span>
<p>Hyperopt will first load your data into memory and will then run <code>populate_indicators()</code> once per Pair to generate all indicators, unless <code>--analyze-per-epoch</code> is specified.</p>
<p>Hyperopt will then spawn into different processes (number of processors, or <code>-j <n></code>), and run backtesting over and over again, changing the parameters that are part of the <code>--spaces</code> defined.</p>
<p>For every new set of parameters, freqtrade will run first <code>populate_entry_trend()</code> followed by <code>populate_exit_trend()</code>, and then run the regular backtesting process to simulate trades.</p>
<p>After backtesting, the results are passed into the <ahref="#loss-functions">loss function</a>, which will evaluate if this result was better or worse than previous results.<br/>
Based on the loss function result, hyperopt will determine the next set of parameters to try in the next round of backtesting.</p>
<h3id="configure-your-guards-and-triggers">Configure your Guards and Triggers<aclass="headerlink"href="#configure-your-guards-and-triggers"title="Permanent link">¶</a></h3>
<p>There are two places you need to change in your strategy file to add a new buy hyperopt for testing:</p>
<ul>
<li>Define the parameters at the class level hyperopt shall be optimizing.</li>
<li>Within <code>populate_entry_trend()</code> - use defined parameter values instead of raw constants.</li>
</ul>
<p>There you have two different types of indicators: 1. <code>guards</code> and 2. <code>triggers</code>.</p>
<ol>
<li>Guards are conditions like "never buy if ADX < 10", or never buy if current price is over EMA10.</li>
<li>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".</li>
</ol>
<divclass="admonition hint">
<pclass="admonition-title">Guards and Triggers</p>
<p>Technically, there is no difference between Guards and Triggers.<br/>
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).</p>
</div>
<p>Hyper-optimization will, for each epoch round, pick one trigger and possibly multiple guards.</p>
<h4id="exit-signal-optimization">Exit signal optimization<aclass="headerlink"href="#exit-signal-optimization"title="Permanent link">¶</a></h4>
<p>Similar to the entry-signal above, exit-signals can also be optimized.
Place the corresponding settings into the following methods</p>
<ul>
<li>Define the parameters at the class level hyperopt shall be optimizing, either naming them <code>sell_*</code>, or by explicitly defining <code>space='sell'</code>.</li>
<li>Within <code>populate_exit_trend()</code> - use defined parameter values instead of raw constants.</li>
</ul>
<p>The configuration and rules are the same than for buy signals.</p>
<h2id="solving-a-mystery">Solving a Mystery<aclass="headerlink"href="#solving-a-mystery"title="Permanent link">¶</a></h2>
<p>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?</p>
<p>So let's use hyperparameter optimization to solve this mystery.</p>
<h3id="defining-indicators-to-be-used">Defining indicators to be used<aclass="headerlink"href="#defining-indicators-to-be-used"title="Permanent link">¶</a></h3>
<p>We start by calculating the indicators our strategy is going to use.</p>
<p>The above definition says: I have five parameters I want to randomly combine to find the best combination.<br/>
<code>buy_rsi</code> is an integer parameter, which will be tested between 20 and 40. This space has a size of 20.<br/>
<code>buy_adx</code> 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.<br/>
Then we have three category variables. First two are either <code>True</code> or <code>False</code>.
We use these to either enable or disable the ADX and RSI guards.
The last one we call <code>trigger</code> and use it to decide which buy trigger we want to use.</p>
<divclass="admonition note">
<pclass="admonition-title">Parameter space assignment</p>
<p>Parameters must either be assigned to a variable named <code>buy_*</code> or <code>sell_*</code> - or contain <code>space='buy'</code> | <code>space='sell'</code> 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.<br/>
Parameters with unclear space (e.g. <code>adx_period = IntParameter(4, 24, default=14)</code> - no explicit nor implicit space) will not be detected and will therefore be ignored.</p>
</div>
<p>So let's write the buy strategy using these values:</p>
<p>Hyperopt will now call <code>populate_entry_trend()</code> many times (<code>epochs</code>) with different value combinations.<br/>
It will use the given historical data and simulate buys based on the buy signals generated with the above function.<br/>
Based on the results, hyperopt will tell you which parameter combination produced the best results (based on the configured <ahref="#loss-functions">loss function</a>).</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>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 <code>populate_indicators()</code> method in your strategy or hyperopt file.</p>
<p>There are four parameter types each suited for different purposes.</p>
<ul>
<li><code>IntParameter</code> - defines an integral parameter with upper and lower boundaries of search space.</li>
<li><code>DecimalParameter</code> - defines a floating point parameter with a limited number of decimals (default 3). Should be preferred instead of <code>RealParameter</code> in most cases.</li>
<li><code>RealParameter</code> - 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.</li>
<li><code>CategoricalParameter</code> - defines a parameter with a predetermined number of choices.</li>
<li><code>BooleanParameter</code> - Shorthand for <code>CategoricalParameter([True, False])</code> - great for "enable" parameters.</li>
<p>There are two parameter options that can help you to quickly test various ideas:</p>
<ul>
<li><code>optimize</code> - when set to <code>False</code>, the parameter will not be included in optimization process. (Default: True)</li>
<li><code>load</code> - when set to <code>False</code>, results of a previous hyperopt run (in <code>buy_params</code> and <code>sell_params</code> 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)</li>
</ul>
<divclass="admonition tip">
<pclass="admonition-title">Effects of <code>load=False</code> on backtesting</p>
<p>Be aware that setting the <code>load</code> option to <code>False</code> will mean backtesting will also use the default value specified in the parameter and <em>not</em> the value found through hyperoptimisation.</p>
</div>
<divclass="admonition warning">
<pclass="admonition-title">Warning</p>
<p>Hyperoptable parameters cannot be used in <code>populate_indicators</code> - as hyperopt does not recalculate indicators for each epoch, so the starting value would be used in this case.</p>
</div>
<h2id="optimizing-an-indicator-parameter">Optimizing an indicator parameter<aclass="headerlink"href="#optimizing-an-indicator-parameter"title="Permanent link">¶</a></h2>
<p>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 (<code>minimal_roi</code>) of 10% - which means freqtrade will sell the trade once 10% profit has been reached.</p>
<p>Using <code>self.buy_ema_short.range</code> will return a range object containing all entries between the Parameters low and high value.
In this case (<code>IntParameter(3, 50, default=5)</code>), the loop would run for all numbers between 3 and 50 (<code>[3, 4, 5, ... 49, 50]</code>).
By using this in a loop, hyperopt will generate 48 new columns (<code>['buy_ema_3', 'buy_ema_4', ... , 'buy_ema_50']</code>).</p>
<p>Hyperopt itself will then use the selected value to create the buy and sell signals.</p>
<p>While this strategy is most likely too simple to provide consistent profit, it should serve as an example how optimize indicator parameters.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p><code>self.buy_ema_short.range</code> 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 <code>self.buy_ema_short.value</code>).</p>
</div>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p><code>range</code> property may also be used with <code>DecimalParameter</code> and <code>CategoricalParameter</code>. <code>RealParameter</code> does not provide this property due to infinite search space.</p>
</div>
<detailsclass="hint">
<summary>Performance tip</summary>
<p>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</p>
<ul>
<li>Move <code>ema_short</code> and <code>ema_long</code> calculations from <code>populate_indicators()</code> to <code>populate_entry_trend()</code>. Since <code>populate_entry_trend()</code> will be calculated every epoch, you don't need to use <code>.range</code> functionality.</li>
<li>hyperopt provides <code>--analyze-per-epoch</code> which will move the execution of <code>populate_indicators()</code> to the epoch process, calculating a single value per parameter per epoch instead of using the <code>.range</code> functionality. In this case, <code>.range</code> functionality will only return the actually used value.</li>
</ul>
<p>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.</p>
<p>Whether you are using <code>.range</code> functionality or the alternatives above, you should try to use space ranges as small as possible since this will improve CPU/RAM usage.</p>
<p>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.</p>
</div>
<divclass="admonition warning">
<pclass="admonition-title">Warning</p>
<p>If protections are defined as property, entries from the configuration will be ignored.
It is therefore recommended to not define protections in the configuration.</p>
</div>
<h3id="migrating-from-previous-property-setups">Migrating from previous property setups<aclass="headerlink"href="#migrating-from-previous-property-setups"title="Permanent link">¶</a></h3>
<p>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.</p>
<p>While <code>max_entry_position_adjustment</code> is not a separate space, it can still be used in hyperopt by using the property approach shown above.</p>
<p>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.</p>
<p>A loss function must be specified via the <code>--hyperopt-loss <Class-name></code> argument (or optionally via the configuration under the <code>"hyperopt_loss"</code> key).
This class should be in its own file within the <code>user_data/hyperopts/</code> directory.</p>
<p>Currently, the following loss functions are builtin:</p>
<ul>
<li><code>ShortTradeDurHyperOptLoss</code> - (default legacy Freqtrade hyperoptimization loss function) - Mostly for short trade duration and avoiding losses.</li>
<li><code>OnlyProfitHyperOptLoss</code> - takes only amount of profit into consideration.</li>
<li><code>SharpeHyperOptLoss</code> - Optimizes Sharpe Ratio calculated on trade returns relative to standard deviation.</li>
<li><code>SharpeHyperOptLossDaily</code> - Optimizes Sharpe Ratio calculated on <strong>daily</strong> trade returns relative to standard deviation.</li>
<li><code>SortinoHyperOptLoss</code> - Optimizes Sortino Ratio calculated on trade returns relative to <strong>downside</strong> standard deviation.</li>
<li><code>SortinoHyperOptLossDaily</code> - optimizes Sortino Ratio calculated on <strong>daily</strong> trade returns relative to <strong>downside</strong> standard deviation.</li>
<li><code>MaxDrawDownHyperOptLoss</code> - Optimizes Maximum absolute drawdown.</li>
<li><code>MaxDrawDownRelativeHyperOptLoss</code> - Optimizes both maximum absolute drawdown while also adjusting for maximum relative drawdown.</li>
<li><code>CalmarHyperOptLoss</code> - Optimizes Calmar Ratio calculated on trade returns relative to max drawdown.</li>
<li><code>ProfitDrawDownHyperOptLoss</code> - Optimizes by max Profit & min Drawdown objective. <code>DRAWDOWN_MULT</code> variable within the hyperoptloss file can be adjusted to be stricter or more flexible on drawdown purposes.</li>
<li><code>MultiMetricHyperOptLoss</code> - Optimizes by several key metrics to achieve balanced performance. The primary focus is on maximizing Profit and minimizing Drawdown, while also considering additional metrics such as Profit Factor, Expectancy Ratio and Winrate. Moreover, it applies a penalty for epochs with a low number of trades, encouraging strategies with adequate trade frequency.</li>
<p>The <code>-e</code> 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.<br/>
Doing multiple runs (executions) with a few 1000 epochs and different random state will most likely produce different results.</p>
<p>The <code>--spaces all</code> option determines that all possible parameters should be optimized. Possibilities are listed below.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>Hyperopt will store hyperopt results with the timestamp of the hyperopt start time.
Reading commands (<code>hyperopt-list</code>, <code>hyperopt-show</code>) can use <code>--hyperopt-filename <filename></code> to read and display older hyperopt results.
You can find a list of filenames with <code>ls -l user_data/hyperopt_results/</code>.</p>
</div>
<h3id="execute-hyperopt-with-different-historical-data-source">Execute Hyperopt with different historical data source<aclass="headerlink"href="#execute-hyperopt-with-different-historical-data-source"title="Permanent link">¶</a></h3>
<p>If you would like to hyperopt parameters using an alternate historical data set that
you have on-disk, use the <code>--datadir PATH</code> option. By default, hyperopt uses data from directory <code>user_data/data</code>.</p>
<h3id="running-hyperopt-with-a-smaller-test-set">Running Hyperopt with a smaller test-set<aclass="headerlink"href="#running-hyperopt-with-a-smaller-test-set"title="Permanent link">¶</a></h3>
<p>Use the <code>--timerange</code> argument to change how much of the test-set you want to use.
For example, to use one month of data, pass <code>--timerange 20210101-20210201</code> (from january 2021 - february 2021) to the hyperopt call.</p>
<h3id="running-hyperopt-with-smaller-search-space">Running Hyperopt with Smaller Search Space<aclass="headerlink"href="#running-hyperopt-with-smaller-search-space"title="Permanent link">¶</a></h3>
<p>Use the <code>--spaces</code> 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.</p>
<p>Legal values are:</p>
<ul>
<li><code>all</code>: optimize everything</li>
<li><code>buy</code>: just search for a new buy strategy</li>
<li><code>sell</code>: just search for a new sell strategy</li>
<li><code>roi</code>: just optimize the minimal profit table for your strategy</li>
<li><code>stoploss</code>: search for the best stoploss value</li>
<li><code>trailing</code>: search for the best trailing stop values</li>
<li><code>trades</code>: search for the best max open trades values</li>
<li><code>protection</code>: search for the best protection parameters (read the <ahref="#optimizing-protections">protections section</a> on how to properly define these)</li>
<li><code>default</code>: <code>all</code> except <code>trailing</code> and <code>protection</code></li>
<li>space-separated list of any of the above values for example <code>--spaces roi stoploss</code></li>
</ul>
<p>The default Hyperopt Search Space, used when no <code>--space</code> command line option is specified, does not include the <code>trailing</code> hyperspace. We recommend you to run optimization for the <code>trailing</code> hyperspace separately, when the best parameters for other hyperspaces were found, validated and pasted into your custom strategy.</p>
<h2id="understand-the-hyperopt-result">Understand the Hyperopt Result<aclass="headerlink"href="#understand-the-hyperopt-result"title="Permanent link">¶</a></h2>
<p>Once Hyperopt is completed you can use the result to update your strategy.
<li>The buy trigger that worked best was <code>bb_lower</code>.</li>
<li>You should not use ADX because <code>'buy_adx_enabled': False</code>.</li>
<li>You should <strong>consider</strong> using the RSI indicator (<code>'buy_rsi_enabled': True</code>) and the best value is <code>29.0</code> (<code>'buy_rsi': 29.0</code>)</li>
</ul>
<h3id="automatic-parameter-application-to-the-strategy">Automatic parameter application to the strategy<aclass="headerlink"href="#automatic-parameter-application-to-the-strategy"title="Permanent link">¶</a></h3>
<p>When using Hyperoptable parameters, the result of your hyperopt-run will be written to a json file next to your strategy (so for <code>MyAwesomeStrategy.py</code>, the file would be <code>MyAwesomeStrategy.json</code>).<br/>
This file is also updated when using the <code>hyperopt-show</code> sub-command, unless <code>--disable-param-export</code> is provided to either of the 2 commands.</p>
<p>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.</p>
<p>Transferring your whole hyperopt result to your strategy would then look like:</p>
<p>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 <code>*_params</code>> parameter default</p>
</div>
<h3id="understand-hyperopt-roi-results">Understand Hyperopt ROI results<aclass="headerlink"href="#understand-hyperopt-roi-results"title="Permanent link">¶</a></h3>
<p>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:</p>
<p>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 <code>minimal_roi</code> attribute of your custom strategy:</p>
<divclass="highlight"><pre><span></span><code> # Minimal ROI designed for the strategy.
# This attribute will be overridden if the config file contains "minimal_roi"
minimal_roi = {
0: 0.10674,
21: 0.09158,
78: 0.03634,
118: 0
}
</code></pre></div>
<p>As stated in the comment, you can also use it as the value of the <code>minimal_roi</code> setting in the configuration file.</p>
<h4id="default-roi-search-space">Default ROI Search Space<aclass="headerlink"href="#default-roi-search-space"title="Permanent link">¶</a></h4>
<p>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):</p>
<table>
<thead>
<tr>
<th># step</th>
<th>1m</th>
<th></th>
<th>5m</th>
<th></th>
<th>1h</th>
<th></th>
<th>1d</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>0</td>
<td>0.011...0.119</td>
<td>0</td>
<td>0.03...0.31</td>
<td>0</td>
<td>0.068...0.711</td>
<td>0</td>
<td>0.121...1.258</td>
</tr>
<tr>
<td>2</td>
<td>2...8</td>
<td>0.007...0.042</td>
<td>10...40</td>
<td>0.02...0.11</td>
<td>120...480</td>
<td>0.045...0.252</td>
<td>2880...11520</td>
<td>0.081...0.446</td>
</tr>
<tr>
<td>3</td>
<td>4...20</td>
<td>0.003...0.015</td>
<td>20...100</td>
<td>0.01...0.04</td>
<td>240...1200</td>
<td>0.022...0.091</td>
<td>5760...28800</td>
<td>0.040...0.162</td>
</tr>
<tr>
<td>4</td>
<td>6...44</td>
<td>0.0</td>
<td>30...220</td>
<td>0.0</td>
<td>360...2640</td>
<td>0.0</td>
<td>8640...63360</td>
<td>0.0</td>
</tr>
</tbody>
</table>
<p>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.</p>
<p>If you have the <code>generate_roi_table()</code> and <code>roi_space()</code> 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.</p>
<p>Override the <code>roi_space()</code> method if you need components of the ROI tables to vary in other ranges. Override the <code>generate_roi_table()</code> and <code>roi_space()</code> 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).</p>
<p>A sample for these methods can be found in the <ahref="../advanced-hyperopt/#overriding-pre-defined-spaces">overriding pre-defined spaces section</a>.</p>
<p>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 <ahref="../advanced-hyperopt/#overriding-pre-defined-spaces">overriding pre-defined spaces</a> to change this to your needs.</p>
<p>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:</p>
<p>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 <code>stoploss</code> attribute of your custom strategy:</p>
<divclass="highlight"><pre><span></span><code><spanclass="c1"># Optimal stoploss designed for the strategy</span>
<spanclass="c1"># This attribute will be overridden if the config file contains "stoploss"</span>
<p>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.</p>
<p>If you have the <code>stoploss_space()</code> method in your custom hyperopt file, remove it in order to utilize Stoploss hyperoptimization space generated by Freqtrade by default.</p>
<p>Override the <code>stoploss_space()</code> 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 <ahref="../advanced-hyperopt/#overriding-pre-defined-spaces">overriding pre-defined spaces section</a>.</p>
<p>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 <ahref="../advanced-hyperopt/#overriding-pre-defined-spaces">overriding pre-defined spaces</a> to change this to your needs.</p>
<p>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:</p>
<p>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:</p>
<p>If you are optimizing trailing stop values, Freqtrade creates the 'trailing' optimization hyperspace for you. By default, the <code>trailing_stop</code> parameter is always set to True in that hyperspace, the value of the <code>trailing_only_offset_is_reached</code> vary between True and False, the values of the <code>trailing_stop_positive</code> and <code>trailing_stop_positive_offset</code> parameters vary in the ranges 0.02...0.35 and 0.01...0.1 correspondingly, which is sufficient in most cases.</p>
<p>Override the <code>trailing_space()</code> 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 <ahref="../advanced-hyperopt/#overriding-pre-defined-spaces">overriding pre-defined spaces section</a>.</p>
<p>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 <ahref="../advanced-hyperopt/#overriding-pre-defined-spaces">overriding pre-defined spaces</a> to change this to your needs.</p>
<p>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 (<code>*</code>) in the first column in the Hyperopt output.</p>
<p>The initial state for generation of these random values (random state) is controlled by the value of the <code>--random-state</code> command line option. You can set it to some arbitrary value of your choice to obtain reproducible results.</p>
<p>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 <code>--random-state</code> command line option to repeat the set of the initial random epochs used.</p>
<p>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.</p>
<p>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 <code>--no-color</code> option in the command line.</p>
<p>You can use the <code>--print-all</code> command line option if you would like to see all results in the hyperopt output, not only the best ones. When <code>--print-all</code> 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 <code>--no-color</code> command line option.</p>
<divclass="admonition note">
<pclass="admonition-title">Windows and color output</p>
<p>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.</p>
</div>
<h2id="position-stacking-and-disabling-max-market-positions">Position stacking and disabling max market positions<aclass="headerlink"href="#position-stacking-and-disabling-max-market-positions"title="Permanent link">¶</a></h2>
<p>In some situations, you may need to run Hyperopt (and Backtesting) with the <code>--eps</code>/<code>--enable-position-staking</code> argument, or you may need to set <code>max_open_trades</code> to a very high number to disable the limit on the number of open trades.</p>
<p>Dry/live runs will <strong>NOT</strong> use position stacking - therefore it does make sense to also validate the strategy without this as it's closer to reality.</p>
</div>
<p>You can also enable position stacking in the configuration file by explicitly setting
<code>"position_stacking"=true</code>.</p>
<h2id="out-of-memory-errors">Out of Memory errors<aclass="headerlink"href="#out-of-memory-errors"title="Permanent link">¶</a></h2>
<p>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:</p>
<ul>
<li>Reduce the amount of pairs.</li>
<li>Reduce the timerange used (<code>--timerange <timerange></code>).</li>
<li>Avoid using <code>--timeframe-detail</code> (this loads a lot of additional data into memory).</li>
<li>Reduce the number of parallel processes (<code>-j <n></code>).</li>
<li>Increase the memory of your machine.</li>
<li>Use <code>--analyze-per-epoch</code> if you're using a lot of parameters with <code>.range</code> functionality.</li>
</ul>
<h2id="the-objective-has-been-evaluated-at-this-point-before">The objective has been evaluated at this point before.<aclass="headerlink"href="#the-objective-has-been-evaluated-at-this-point-before"title="Permanent link">¶</a></h2>
<p>If you see <code>The objective has been evaluated at this point before.</code> - 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.</p>
<spanclass="c1"># This is the only parameter in the buy space</span>
</code></pre></div>
<p>The <code>buy_ema_short</code> space has 15 possible values (<code>5, 6, ... 19, 20</code>). 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 <code>The objective has been evaluated at this point before.</code> warnings.</p>
<h2id="show-details-of-hyperopt-results">Show details of Hyperopt results<aclass="headerlink"href="#show-details-of-hyperopt-results"title="Permanent link">¶</a></h2>
<p>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 <code>hyperopt-list</code> and <code>hyperopt-show</code> sub-commands. The usage of these sub-commands is described in the <ahref="../utils/#list-hyperopt-results">Utils</a> chapter.</p>
<p>Once the optimized strategy has been implemented into your strategy, you should backtest this strategy to make sure everything is working as expected.</p>
<p>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 for Backtesting.</p>
<h3id="why-do-my-backtest-results-not-match-my-hyperopt-results">Why do my backtest results not match my hyperopt results?<aclass="headerlink"href="#why-do-my-backtest-results-not-match-my-hyperopt-results"title="Permanent link">¶</a></h3>
<p>Should results not match, check the following factors:</p>
<ul>
<li>You may have added parameters to hyperopt in <code>populate_indicators()</code> where they will be calculated only once <strong>for all epochs</strong>. If you are, for example, trying to optimise multiple SMA timeperiod values, the hyperoptable timeperiod parameter should be placed in <code>populate_entry_trend()</code> which is calculated every epoch. See <ahref="https://www.freqtrade.io/en/stable/hyperopt/#optimizing-an-indicator-parameter">Optimizing an indicator parameter</a>.</li>
<li>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.</li>
<li>Check the logs to verify what parameters are being set and what values are being used.</li>
<li>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 <code>stoploss</code>, <code>max_open_trades</code> or <code>trailing_stop</code>).</li>
<li>Verify that you do not have an unexpected parameters JSON file overriding the parameters or the default hyperopt settings in your strategy.</li>
<li>Verify that any protections that are enabled in backtesting are also enabled when hyperopting, and vice versa. When using <code>--space protection</code>, protections are auto-enabled for hyperopting.</li>
<scriptid="__config"type="application/json">{"base":"..","features":["content.code.annotate","search.share","content.code.copy","navigation.top","navigation.footer"],"search":"../assets/javascripts/workers/search.6ce7567c.min.js","translations":{"clipboard.copied":"Copied to clipboard","clipboard.copy":"Copy to clipboard","search.result.more.one":"1 more on this page","search.result.more.other":"# more on this page","search.result.none":"No matching documents","search.result.one":"1 matching document","search.result.other":"# matching documents","search.result.placeholder":"Type to start searching","search.result.term.missing":"Missing","select.version":"Select version"},"version":{"alias":true,"provider":"mike"}}</script>