Merge pull request #3688 from freqtrade/Fredrik81-stoploss.md
Update stoploss.md
This commit is contained in:
commit
c2707bdd9b
@ -55,9 +55,9 @@ Mandatory parameters are marked as **Required**, which means that they are requi
|
|||||||
| `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](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **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](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `minimal_roi` | **Required.** Set the threshold as ratio the bot will use to sell a trade. [More information below](#understand-minimal_roi). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Dict
|
| `minimal_roi` | **Required.** Set the threshold as ratio the bot will use to sell a trade. [More information below](#understand-minimal_roi). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Dict
|
||||||
| `stoploss` | **Required.** Value as ratio of the stoploss used by the bot. More details in the [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Float (as ratio)
|
| `stoploss` | **Required.** Value as ratio of the stoploss used by the bot. More details in the [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Float (as ratio)
|
||||||
| `trailing_stop` | Enables trailing stoploss (based on `stoploss` in either configuration or strategy file). More details in the [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Boolean
|
| `trailing_stop` | Enables trailing stoploss (based on `stoploss` in either configuration or strategy file). More details in the [stoploss documentation](stoploss.md#trailing-stop-loss). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Boolean
|
||||||
| `trailing_stop_positive` | Changes stoploss once profit has been reached. More details in the [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br> **Datatype:** Float
|
| `trailing_stop_positive` | Changes stoploss once profit has been reached. More details in the [stoploss documentation](stoploss.md#trailing-stop-loss-custom-positive-loss). [Strategy Override](#parameters-in-the-strategy). <br> **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](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `0.0` (no offset).* <br> **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](stoploss.md#trailing-stop-loss-only-once-the-trade-has-reached-a-certain-offset). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `0.0` (no offset).* <br> **Datatype:** Float
|
||||||
| `trailing_only_offset_is_reached` | Only apply trailing stoploss when the offset is reached. [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
| `trailing_only_offset_is_reached` | Only apply trailing stoploss when the offset is reached. [stoploss documentation](stoploss.md). [Strategy Override](#parameters-in-the-strategy). <br>*Defaults to `false`.* <br> **Datatype:** Boolean
|
||||||
| `unfilledtimeout.buy` | **Required.** How long (in minutes) the bot will wait for an unfilled buy order to complete, after which the order will be cancelled. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
| `unfilledtimeout.buy` | **Required.** How long (in minutes) the bot will wait for an unfilled buy order to complete, after which the order will be cancelled. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
||||||
| `unfilledtimeout.sell` | **Required.** How long (in minutes) the bot will wait for an unfilled sell order to complete, after which the order will be cancelled. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
| `unfilledtimeout.sell` | **Required.** How long (in minutes) the bot will wait for an unfilled sell order to complete, after which the order will be cancelled. [Strategy Override](#parameters-in-the-strategy).<br> **Datatype:** Integer
|
||||||
@ -278,24 +278,13 @@ This allows to buy using limit orders, sell using
|
|||||||
limit-orders, and create stoplosses using market orders. It also allows to set the
|
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
|
stoploss "on exchange" which means stoploss order would be placed immediately once
|
||||||
the buy order is fulfilled.
|
the buy order is fulfilled.
|
||||||
If `stoploss_on_exchange` and `trailing_stop` are both set, then the bot will use `stoploss_on_exchange_interval` to check and update the stoploss on exchange periodically.
|
|
||||||
`order_types` can be set in the configuration file or in the strategy.
|
|
||||||
`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.
|
`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 (`buy`, `sell`, `stoploss` and
|
If this is configured, the following 4 values (`buy`, `sell`, `stoploss` and
|
||||||
`stoploss_on_exchange`) need to be present, otherwise the bot will fail to start.
|
`stoploss_on_exchange`) need to be present, otherwise the bot will fail to start.
|
||||||
|
|
||||||
`emergencysell` is an optional value, which defaults to `market` and is used when creating stoploss on exchange orders fails.
|
For information on (`emergencysell`,`stoploss_on_exchange`,`stoploss_on_exchange_interval`,`stoploss_on_exchange_limit_ratio`) please see stop loss documentation [stop loss on exchange](stoploss.md)
|
||||||
The below is the default which is used if this is not configured in either strategy or configuration file.
|
|
||||||
|
|
||||||
Not all Exchanges support `stoploss_on_exchange`. If an exchange supports both limit and market stoploss orders, then the value of `stoploss` will be used to determine the stoploss type.
|
|
||||||
|
|
||||||
If `stoploss_on_exchange` uses limit orders, the exchange needs 2 prices, the stoploss_price and the Limit price.
|
|
||||||
`stoploss` defines the stop-price - and limit should be slightly below this.
|
|
||||||
|
|
||||||
This defaults to 0.99 / 1% (configurable via `stoploss_on_exchange_limit_ratio`).
|
|
||||||
Calculation example: we bought the asset at 100$.
|
|
||||||
Stop-price is 95$, then limit would be `95 * 0.99 = 94.05$` - so the stoploss will happen between 95$ and 94.05$.
|
|
||||||
|
|
||||||
Syntax for Strategy:
|
Syntax for Strategy:
|
||||||
|
|
||||||
|
149
docs/stoploss.md
149
docs/stoploss.md
@ -6,7 +6,63 @@ For example, value `-0.10` will cause immediate sell if the profit dips below -1
|
|||||||
Most of the strategy files already include the optimal `stoploss` value.
|
Most of the strategy files already include the optimal `stoploss` value.
|
||||||
|
|
||||||
!!! Info
|
!!! 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.
|
* All stoploss properties mentioned in this file can be set in the Strategy, or in the configuration.
|
||||||
|
* <ins>Configuration values will override the strategy values.</ins>
|
||||||
|
|
||||||
|
## Stop Loss On-Exchange/Freqtrade
|
||||||
|
|
||||||
|
Those stoploss modes can be *on exchange* or *off exchange*.
|
||||||
|
|
||||||
|
These modes can be configured with these values:
|
||||||
|
|
||||||
|
``` python
|
||||||
|
'emergencysell': 'market',
|
||||||
|
'stoploss_on_exchange': False
|
||||||
|
'stoploss_on_exchange_interval': 60,
|
||||||
|
'stoploss_on_exchange_limit_ratio': 0.99
|
||||||
|
```
|
||||||
|
|
||||||
|
!!! Note
|
||||||
|
* Stoploss on exchange is only supported for Binance (stop-loss-limit), Kraken (stop-loss-market) and FTX (stop limit and stop-market) as of now.
|
||||||
|
* <ins>Do not set too low stoploss value if using stop loss on exchange!</ins>
|
||||||
|
* If set to low/tight then you have greater risk of missing fill on the order and stoploss will not work
|
||||||
|
|
||||||
|
### stoploss_on_exchange and stoploss_on_exchange_limit_ratio
|
||||||
|
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 happens successfully. This will protect you against sudden crashes in market as the order will be in the queue immediately and if market goes down then the order has more chance of being fulfilled.
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
### stoploss_on_exchange_interval
|
||||||
|
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.
|
||||||
|
|
||||||
|
### emergencysell
|
||||||
|
`emergencysell` 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:
|
||||||
|
|
||||||
|
``` python
|
||||||
|
order_types = {
|
||||||
|
'buy': 'limit',
|
||||||
|
'sell': 'limit',
|
||||||
|
'emergencysell': 'market',
|
||||||
|
'stoploss': 'market',
|
||||||
|
'stoploss_on_exchange': True,
|
||||||
|
'stoploss_on_exchange_interval': 60,
|
||||||
|
'stoploss_on_exchange_limit_ratio': 0.99
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Stop Loss Types
|
## Stop Loss Types
|
||||||
|
|
||||||
@ -17,28 +73,28 @@ At this stage the bot contains the following stoploss support modes:
|
|||||||
3. Trailing stop loss, custom positive loss.
|
3. Trailing stop loss, custom positive loss.
|
||||||
4. Trailing stop loss only once the trade has reached a certain offset.
|
4. Trailing stop loss only once the trade has reached a certain offset.
|
||||||
|
|
||||||
Those stoploss modes can be *on exchange* or *off exchange*. If the stoploss is *on exchange* it means a stoploss limit order is placed on the exchange immediately after buy order happens successfully. This will protect you against sudden crashes in market as the order will be in the queue immediately and if market goes down then the order has more chance of being fulfilled.
|
### Static Stop Loss
|
||||||
|
|
||||||
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.
|
|
||||||
|
|
||||||
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.
|
|
||||||
The bot cannot do this 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.
|
|
||||||
|
|
||||||
!!! Note
|
|
||||||
Stoploss on exchange is only supported for Binance (stop-loss-limit), Kraken (stop-loss-market) and FTX (stop limit and stop-market) as of now.
|
|
||||||
|
|
||||||
## Static Stop Loss
|
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
## Trailing Stop Loss
|
Example of stop loss:
|
||||||
|
|
||||||
|
``` python
|
||||||
|
stoploss = -0.10
|
||||||
|
```
|
||||||
|
|
||||||
|
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$
|
||||||
|
|
||||||
|
### Trailing Stop Loss
|
||||||
|
|
||||||
The initial value for this is `stoploss`, just as you would define your static Stop loss.
|
The initial value for this is `stoploss`, just as you would define your static Stop loss.
|
||||||
To enable trailing stoploss:
|
To enable trailing stoploss:
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
|
stoploss = -0.10
|
||||||
trailing_stop = True
|
trailing_stop = True
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -47,35 +103,43 @@ This will now activate an algorithm, which automatically moves the stop loss up
|
|||||||
For example, simplified math:
|
For example, simplified math:
|
||||||
|
|
||||||
* the bot buys an asset at a price of 100$
|
* the bot buys an asset at a price of 100$
|
||||||
* the stop loss is defined at 2%
|
* the stop loss is defined at -10%
|
||||||
* the stop loss would get triggered once the asset dropps below 98$
|
* the stop loss would get triggered once the asset drops below 90$
|
||||||
* assuming the asset now increases to 102$
|
* assuming the asset now increases to 102$
|
||||||
* the stop loss will now be 2% of 102$ or 99.96$
|
* 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 99.96$ and would trigger at 99.96$.
|
* 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 2% of the highest observed price.
|
In summary: The stoploss will be adjusted to be always be -10% of the highest observed price.
|
||||||
|
|
||||||
### Custom positive stoploss
|
### Trailing stop loss, custom positive loss
|
||||||
|
|
||||||
It is also possible to have a default stop loss, when you are in the red with your buy, but once your profit surpasses a certain percentage, the system will utilize a new stop loss, which can have a different value.
|
It is also possible to have a default stop loss, when you are in the red with your buy (buy - fee), but once you hit positive result the system will utilize a new stop loss, which can have a different value.
|
||||||
For example your default stop loss is 5%, but once you have 1.1% profit, it will be changed to be only a 1% stop loss, which trails the green candles until it goes below them.
|
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.
|
||||||
|
|
||||||
Both values require `trailing_stop` to be set to true.
|
!!! 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](#Trailing-stop-loss-only-once-the-trade-has-reached-a-certain-offset).
|
||||||
|
|
||||||
|
Both values require `trailing_stop` to be set to true and `trailing_stop_positive` with a value.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
trailing_stop_positive = 0.01
|
stoploss = -0.10
|
||||||
trailing_stop_positive_offset = 0.011
|
trailing_stop = True
|
||||||
|
trailing_stop_positive = 0.02
|
||||||
```
|
```
|
||||||
|
|
||||||
The 0.01 would translate to a 1% stop loss, once you hit 1.1% profit.
|
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 increasements 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.
|
Before this, `stoploss` is used for the trailing stoploss.
|
||||||
|
|
||||||
Read the [next section](#trailing-only-once-offset-is-reached) to keep stoploss at 5% of the entry point.
|
### Trailing stop loss only once the trade has reached a certain offset
|
||||||
|
|
||||||
!!! 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.
|
|
||||||
|
|
||||||
### Trailing only once offset is reached
|
|
||||||
|
|
||||||
It is also possible to use a static stoploss until the offset is reached, and then trail the trade to take profits once the market turns.
|
It is also possible to use a static stoploss until the offset is reached, and then trail the trade to take profits once the market turns.
|
||||||
|
|
||||||
@ -87,17 +151,28 @@ This option can be used with or without `trailing_stop_positive`, but uses `trai
|
|||||||
trailing_only_offset_is_reached = True
|
trailing_only_offset_is_reached = True
|
||||||
```
|
```
|
||||||
|
|
||||||
Simplified example:
|
Configuration (offset is buyprice + 3%):
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
stoploss = 0.05
|
stoploss = -0.10
|
||||||
|
trailing_stop = True
|
||||||
|
trailing_stop_positive = 0.02
|
||||||
trailing_stop_positive_offset = 0.03
|
trailing_stop_positive_offset = 0.03
|
||||||
trailing_only_offset_is_reached = True
|
trailing_only_offset_is_reached = True
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For example, simplified math:
|
||||||
|
|
||||||
* the bot buys an asset at a price of 100$
|
* the bot buys an asset at a price of 100$
|
||||||
* the stop loss is defined at 5%
|
* the stop loss is defined at -10%
|
||||||
* the stop loss will remain at 95% until profit reaches +3%
|
* the stop loss would get triggered once the asset drops below 90$
|
||||||
|
* stoploss will remain at 90$ unless asset increases to or above our 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.
|
||||||
|
|
||||||
## Changing stoploss on open trades
|
## Changing stoploss on open trades
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user