Elffuss BraidHub

kikocis/freqtrade public

develop · 8.8 KiBRenderedRawPermalink
1# Stop Loss
2
3The `stoploss` configuration parameter is loss as ratio that should trigger a sale.
4For example, value `-0.10` will cause immediate sell if the profit dips below -10% for a given trade. This parameter is optional.
5
6Most of the strategy files already include the optimal `stoploss` value.
7
8!!! Info
9 All stoploss properties mentioned in this file can be set in the Strategy, or in the configuration.
10 <ins>Configuration values will override the strategy values.</ins>
11
12## Stop Loss On-Exchange/Freqtrade
13
14Those stoploss modes can be *on exchange* or *off exchange*.
15
16These modes can be configured with these values:
17
18``` python
19 'emergencysell': 'market',
20 'stoploss_on_exchange': False
21 'stoploss_on_exchange_interval': 60,
22 'stoploss_on_exchange_limit_ratio': 0.99
23```
24
25!!! Note
26 Stoploss on exchange is only supported for Binance (stop-loss-limit), Kraken (stop-loss-market, stop-loss-limit) and FTX (stop limit and stop-market) as of now.
27 <ins>Do not set too low/tight stoploss value if using stop loss on exchange!</ins>
28 If set to low/tight then you have greater risk of missing fill on the order and stoploss will not work.
29
30### stoploss_on_exchange and stoploss_on_exchange_limit_ratio
31
32Enable or Disable stop loss on exchange.
33If 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.
34
35If `stoploss_on_exchange` uses limit orders, the exchange needs 2 prices, the stoploss_price and the Limit price.
36`stoploss` defines the stop-price where the limit order is placed - and limit should be slightly below this.
37If an exchange supports both limit and market stoploss orders, then the value of `stoploss` will be used to determine the stoploss type.
38
39Calculation example: we bought the asset at 100\$.
40Stop-price is 95\$, then limit would be `95 * 0.99 = 94.05$` - so the limit order fill can happen between 95$ and 94.05$.
41
42For 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.
43
44!!! Note
45 If `stoploss_on_exchange` is enabled and the stoploss is cancelled manually on the exchange, then the bot will create a new stoploss order.
46
47### stoploss_on_exchange_interval
48
49In 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.
50The bot cannot do these every 5 seconds (at each iteration), otherwise it would get banned by the exchange.
51So this parameter will tell the bot how often it should update the stoploss order. The default value is 60 (1 minute).
52This same logic will reapply a stoploss order on the exchange should you cancel it accidentally.
53
54### forcesell
55
56`forcesell` is an optional value, which defaults to the same value as `sell` and is used when sending a `/forcesell` command from Telegram or from the Rest API.
57
58### forcebuy
59
60`forcebuy` is an optional value, which defaults to the same value as `buy` and is used when sending a `/forcebuy` command from Telegram or from the Rest API.
61
62### emergencysell
63
64`emergencysell` is an optional value, which defaults to `market` and is used when creating stop loss on exchange orders fails.
65The below is the default which is used if not changed in strategy or configuration file.
66
67Example from strategy file:
68
69``` python
70order_types = {
71 'buy': 'limit',
72 'sell': 'limit',
73 'emergencysell': 'market',
74 'stoploss': 'market',
75 'stoploss_on_exchange': True,
76 'stoploss_on_exchange_interval': 60,
77 'stoploss_on_exchange_limit_ratio': 0.99
78}
79```
80
81## Stop Loss Types
82
83At this stage the bot contains the following stoploss support modes:
84
851. Static stop loss.
862. Trailing stop loss.
873. Trailing stop loss, custom positive loss.
884. Trailing stop loss only once the trade has reached a certain offset.
895. [Custom stoploss function](strategy-advanced.md#custom-stoploss)
90
91### Static Stop Loss
92
93This 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.
94
95Example of stop loss:
96
97``` python
98 stoploss = -0.10
99```
100
101For example, simplified math:
102
103* the bot buys an asset at a price of 100$
104* the stop loss is defined at -10%
105* the stop loss would get triggered once the asset drops below 90$
106
107### Trailing Stop Loss
108
109The initial value for this is `stoploss`, just as you would define your static Stop loss.
110To enable trailing stoploss:
111
112``` python
113 stoploss = -0.10
114 trailing_stop = True
115```
116
117This will now activate an algorithm, which automatically moves the stop loss up every time the price of your asset increases.
118
119For example, simplified math:
120
121* the bot buys an asset at a price of 100$
122* the stop loss is defined at -10%
123* the stop loss would get triggered once the asset drops below 90$
124* assuming the asset now increases to 102$
125* the stop loss will now be -10% of 102$ = 91.8$
126* now the asset drops in value to 101\$, the stop loss will still be 91.8$ and would trigger at 91.8$.
127
128In summary: The stoploss will be adjusted to be always be -10% of the highest observed price.
129
130### Trailing stop loss, custom positive loss
131
132It 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.
133For 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.
134
135!!! Note
136 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).
137
138Both values require `trailing_stop` to be set to true and `trailing_stop_positive` with a value.
139
140``` python
141 stoploss = -0.10
142 trailing_stop = True
143 trailing_stop_positive = 0.02
144```
145
146For example, simplified math:
147
148* the bot buys an asset at a price of 100$
149* the stop loss is defined at -10%
150* the stop loss would get triggered once the asset drops below 90$
151* assuming the asset now increases to 102$
152* 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%)
153* now the asset drops in value to 101\$, the stop loss will still be 99.96$ and would trigger at 99.96$
154
155The 0.02 would translate to a -2% stop loss.
156Before this, `stoploss` is used for the trailing stoploss.
157
158### Trailing stop loss only once the trade has reached a certain offset
159
160It 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.
161
162If `"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`.
163This option can be used with or without `trailing_stop_positive`, but uses `trailing_stop_positive_offset` as offset.
164
165``` python
166 trailing_stop_positive_offset = 0.011
167 trailing_only_offset_is_reached = True
168```
169
170Configuration (offset is buy-price + 3%):
171
172``` python
173 stoploss = -0.10
174 trailing_stop = True
175 trailing_stop_positive = 0.02
176 trailing_stop_positive_offset = 0.03
177 trailing_only_offset_is_reached = True
178```
179
180For example, simplified math:
181
182* the bot buys an asset at a price of 100$
183* the stop loss is defined at -10%
184* the stop loss would get triggered once the asset drops below 90$
185* stoploss will remain at 90$ unless asset increases to or above our configured offset
186* assuming the asset now increases to 103$ (where we have the offset configured)
187* the stop loss will now be -2% of 103$ = 100.94$
188* now the asset drops in value to 101\$, the stop loss will still be 100.94$ and would trigger at 100.94$
189
190!!! Tip
191 Make sure to have this value (`trailing_stop_positive_offset`) lower than minimal ROI, otherwise minimal ROI will apply first and sell the trade.
192
193## Changing stoploss on open trades
194
195A 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).
196
197The new stoploss value will be applied to open trades (and corresponding log-messages will be generated).
198
199### Limitations
200
201Stoploss values cannot be changed if `trailing_stop` is enabled and the stoploss has already been adjusted, or if [Edge](edge.md) is enabled (since Edge would recalculate stoploss based on the current market situation).