<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 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.</p>
</div>
<p>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.</p>
<divclass="admonition note">
<pclass="admonition-title">Note</p>
<p>Not all Protections will work for all strategies, and parameters will need to be tuned for your strategy to improve performance. </p>
</div>
<divclass="admonition tip">
<pclass="admonition-title">Tip</p>
<p>Each Protection can be configured multiple times with different parameters, to allow different levels of protection (short-term / long-term).</p>
</div>
<divclass="admonition note">
<pclass="admonition-title">Backtesting</p>
<p>Protections are supported by backtesting and hyperopt, but must be explicitly enabled by using the <code>--enable-protections</code> flag.</p>
</div>
<divclass="admonition warning">
<pclass="admonition-title">Setting protections from the configuration</p>
<p>Setting protections from the configuration via <code>"protections": [],</code> 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 <ahref="hyperopt.md#optimizing-protections">protections as property</a>.</p>
<li><ahref="#stoploss-guard"><code>StoplossGuard</code></a> Stop trading if a certain amount of stoploss occurred within a certain time window.</li>
<li><ahref="#maxdrawdown"><code>MaxDrawdown</code></a> Stop trading if max-drawdown is reached.</li>
<li><ahref="#low-profit-pairs"><code>LowProfitPairs</code></a> Lock pairs with low profits</li>
<li><ahref="#cooldown-period"><code>CooldownPeriod</code></a> Don't enter a trade right after selling a trade.</li>
</ul>
<h3id="common-settings-to-all-protections">Common settings to all Protections<aclass="headerlink"href="#common-settings-to-all-protections"title="Permanent link">¶</a></h3>
<table>
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>method</code></td>
<td>Protection name to use. <br><strong>Datatype:</strong> String, selected from <ahref="#available-protections">available Protections</a></td>
</tr>
<tr>
<td><code>stop_duration_candles</code></td>
<td>For how many candles should the lock be set? <br><strong>Datatype:</strong> Positive integer (in candles)</td>
</tr>
<tr>
<td><code>stop_duration</code></td>
<td>how many minutes should protections be locked. <br>Cannot be used together with <code>stop_duration_candles</code>. <br><strong>Datatype:</strong> Float (in minutes)</td>
</tr>
<tr>
<td><code>lookback_period_candles</code></td>
<td>Only trades that completed within the last <code>lookback_period_candles</code> candles will be considered. This setting may be ignored by some Protections. <br><strong>Datatype:</strong> Positive integer (in candles).</td>
</tr>
<tr>
<td><code>lookback_period</code></td>
<td>Only trades that completed after <code>current_time - lookback_period</code> will be considered. <br>Cannot be used together with <code>lookback_period_candles</code>. <br>This setting may be ignored by some Protections. <br><strong>Datatype:</strong> Float (in minutes)</td>
</tr>
<tr>
<td><code>trade_limit</code></td>
<td>Number of trades required at minimum (not used by all Protections). <br><strong>Datatype:</strong> Positive integer</td>
</tr>
<tr>
<td><code>unlock_at</code></td>
<td>Time when trading will be unlocked regularly (not used by all Protections). <br><strong>Datatype:</strong> string <br><strong>Input Format:</strong> "HH:MM" (24-hours)</td>
</tr>
</tbody>
</table>
<divclass="admonition note">
<pclass="admonition-title">Durations</p>
<p>Durations (<code>stop_duration*</code> and <code>lookback_period*</code> can be defined in either minutes or candles).
For more flexibility when testing different timeframes, all below examples will use the "candle" definition.</p>
<p><code>StoplossGuard</code> selects all trades within <code>lookback_period</code> in minutes (or in candles when using <code>lookback_period_candles</code>).
If <code>trade_limit</code> or more trades resulted in stoploss, trading will stop for <code>stop_duration</code> in minutes (or in candles when using <code>stop_duration_candles</code>, or until the set time when using <code>unlock_at</code>).</p>
<p>This applies across all pairs, unless <code>only_per_pair</code> is set to true, which will then only look at one pair at a time.</p>
<p>Similarly, this protection will by default look at all trades (long and short). For futures bots, setting <code>only_per_side</code> 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.</p>
<p><code>required_profit</code> 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.</p>
<p>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.</p>
<p><code>StoplossGuard</code> considers all trades with the results <code>"stop_loss"</code>, <code>"stoploss_on_exchange"</code> and <code>"trailing_stop_loss"</code> if the resulting profit was negative.
<code>trade_limit</code> and <code>lookback_period</code> will need to be tuned for your strategy.</p>
<p><code>MaxDrawdown</code> uses all trades within <code>lookback_period</code> in minutes (or in candles when using <code>lookback_period_candles</code>) to determine the maximum drawdown. If the drawdown is below <code>max_allowed_drawdown</code>, trading will stop for <code>stop_duration</code> in minutes (or in candles when using <code>stop_duration_candles</code>) after the last trade - assuming that the bot needs some time to let markets recover.</p>
<p>The below sample stops trading for 12 candles if max-drawdown is > 20% considering all pairs - with a minimum of <code>trade_limit</code> trades - within the last 48 candles. If desired, <code>lookback_period</code> and/or <code>stop_duration</code> can be used.</p>
<p><code>LowProfitPairs</code> uses all trades for a pair within <code>lookback_period</code> in minutes (or in candles when using <code>lookback_period_candles</code>) to determine the overall profit ratio.
If that ratio is below <code>required_profit</code>, that pair will be locked for <code>stop_duration</code> in minutes (or in candles when using <code>stop_duration_candles</code>, or until the set time when using <code>unlock_at</code>).</p>
<p>For futures bots, setting <code>only_per_side</code> 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.</p>
<p>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.</p>
<p><code>CooldownPeriod</code> locks a pair for <code>stop_duration</code> in minutes (or in candles when using <code>stop_duration_candles</code>, or until the set time when using <code>unlock_at</code>) after exiting, avoiding a re-entry for this pair for <code>stop_duration</code> minutes.</p>
<p>The below example will stop trading a pair for 2 candles after closing a trade, allowing this pair to "cool down".</p>
<p>This Protection applies only at pair-level, and will never lock all pairs globally.
This Protection does not consider <code>lookback_period</code> as it only looks at the latest trade.</p>
</div>
<h3id="full-example-of-protections">Full example of Protections<aclass="headerlink"href="#full-example-of-protections"title="Permanent link">¶</a></h3>
<p>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.</p>
<p>The below example assumes a timeframe of 1 hour:</p>
<ul>
<li>Locks each pair after selling for an additional 5 candles (<code>CooldownPeriod</code>), giving other pairs a chance to get filled.</li>
<li>Stops trading for 4 hours (<code>4 * 1h candles</code>) if the last 2 days (<code>48 * 1h candles</code>) had 20 trades, which caused a max-drawdown of more than 20%. (<code>MaxDrawdown</code>).</li>
<li>Stops trading if more than 4 stoploss occur for all pairs within a 1 day (<code>24 * 1h candles</code>) limit (<code>StoplossGuard</code>).</li>
<li>Locks all pairs that had 2 Trades within the last 6 hours (<code>6 * 1h candles</code>) with a combined profit ratio of below 0.02 (<2%) (<code>LowProfitPairs</code>).</li>
<li>Locks all pairs for 2 candles that had a profit of below 0.01 (<1%) within the last 24h (<code>24 * 1h candles</code>), a minimum of 4 trades.</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.b8dbb3d2.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":{"provider":"mike"}}</script>