Rename flag to "use_custom_stoposs"
This commit is contained in:
parent
8574751a07
commit
277342f167
@ -16,12 +16,12 @@ If you're just getting started, please be familiar with the methods described in
|
|||||||
A stoploss can only ever move upwards - so if you set it to an absolute profit of 2%, you can never move it below this price.
|
A stoploss can only ever move upwards - so if you set it to an absolute profit of 2%, you can never move it below this price.
|
||||||
Also, the traditional `stoploss` value serves as an absolute lower level and will be instated as the initial stoploss.
|
Also, the traditional `stoploss` value serves as an absolute lower level and will be instated as the initial stoploss.
|
||||||
|
|
||||||
The usage of the custom stoploss method must be enabled by setting `custom_stoploss=True` on the strategy object.
|
The usage of the custom stoploss method must be enabled by setting `use_custom_stoploss=True` on the strategy object.
|
||||||
The method must return a stoploss value (float / number) with a relative ratio below the current price.
|
The method must return a stoploss value (float / number) with a relative ratio below the current price.
|
||||||
E.g. `current_profit = 0.05` (5% profit) - stoploss returns `0.02` - then you "locked in" a profit of 3% (`0.05 - 0.02 = 0.03`).
|
E.g. `current_profit = 0.05` (5% profit) - stoploss returns `0.02` - then you "locked in" a profit of 3% (`0.05 - 0.02 = 0.03`).
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
@ -45,7 +45,7 @@ Of course, many more things are possible, and all examples can be combined at wi
|
|||||||
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.
|
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.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
@ -65,7 +65,7 @@ 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.
|
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.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
@ -88,7 +88,7 @@ The below example sets absolute profit levels based on the current profit.
|
|||||||
* Once profit is > 20% - stoploss will be set to 7%.
|
* Once profit is > 20% - stoploss will be set to 7%.
|
||||||
|
|
||||||
``` python
|
``` python
|
||||||
custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
def stoploss_value(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
|
@ -89,7 +89,7 @@ class IStrategy(ABC):
|
|||||||
trailing_stop_positive: Optional[float] = None
|
trailing_stop_positive: Optional[float] = None
|
||||||
trailing_stop_positive_offset: float = 0.0
|
trailing_stop_positive_offset: float = 0.0
|
||||||
trailing_only_offset_is_reached = False
|
trailing_only_offset_is_reached = False
|
||||||
custom_stoploss: bool = False
|
use_custom_stoploss: bool = False
|
||||||
|
|
||||||
# associated timeframe
|
# associated timeframe
|
||||||
ticker_interval: str # DEPRECATED
|
ticker_interval: str # DEPRECATED
|
||||||
@ -265,7 +265,7 @@ class IStrategy(ABC):
|
|||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
|
|
||||||
When not implemented by a strategy, returns the initial stoploss value
|
When not implemented by a strategy, returns the initial stoploss value
|
||||||
Only called when custom_stoploss is set to True.
|
Only called when use_custom_stoploss is set to True.
|
||||||
|
|
||||||
:param pair: Pair that's about to be sold.
|
:param pair: Pair that's about to be sold.
|
||||||
:param trade: trade object.
|
:param trade: trade object.
|
||||||
@ -554,7 +554,7 @@ class IStrategy(ABC):
|
|||||||
# Initiate stoploss with open_rate. Does nothing if stoploss is already set.
|
# Initiate stoploss with open_rate. Does nothing if stoploss is already set.
|
||||||
trade.adjust_stop_loss(trade.open_rate, stop_loss_value, initial=True)
|
trade.adjust_stop_loss(trade.open_rate, stop_loss_value, initial=True)
|
||||||
|
|
||||||
if self.custom_stoploss:
|
if self.use_custom_stoploss:
|
||||||
stop_loss_value = strategy_safe_wrapper(self.stoploss_value, default_retval=None
|
stop_loss_value = strategy_safe_wrapper(self.stoploss_value, default_retval=None
|
||||||
)(pair=trade.pair, trade=trade,
|
)(pair=trade.pair, trade=trade,
|
||||||
current_time=current_time,
|
current_time=current_time,
|
||||||
|
@ -12,7 +12,7 @@ def bot_loop_start(self, **kwargs) -> None:
|
|||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
custom_stoploss = True
|
use_custom_stoploss = True
|
||||||
|
|
||||||
def stoploss_value(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
|
def stoploss_value(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
|
||||||
current_profit: float, **kwargs) -> float:
|
current_profit: float, **kwargs) -> float:
|
||||||
@ -24,7 +24,7 @@ def stoploss_value(self, pair: str, trade: 'Trade', current_time: 'datetime', cu
|
|||||||
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
For full documentation please go to https://www.freqtrade.io/en/latest/strategy-advanced/
|
||||||
|
|
||||||
When not implemented by a strategy, returns the initial stoploss value
|
When not implemented by a strategy, returns the initial stoploss value
|
||||||
Only called when custom_stoploss is set to True.
|
Only called when use_custom_stoploss is set to True.
|
||||||
|
|
||||||
:param pair: Pair that's about to be sold.
|
:param pair: Pair that's about to be sold.
|
||||||
:param trade: trade object.
|
:param trade: trade object.
|
||||||
|
@ -328,7 +328,7 @@ def test_stop_loss_reached(default_conf, fee, profit, adjusted, expected, traili
|
|||||||
trade.adjust_min_max_rates(trade.open_rate)
|
trade.adjust_min_max_rates(trade.open_rate)
|
||||||
strategy.trailing_stop = trailing
|
strategy.trailing_stop = trailing
|
||||||
strategy.trailing_stop_positive = -0.05
|
strategy.trailing_stop_positive = -0.05
|
||||||
strategy.custom_stoploss = custom
|
strategy.use_custom_stoploss = custom
|
||||||
original_stopvalue = strategy.stoploss_value
|
original_stopvalue = strategy.stoploss_value
|
||||||
if custom_stop:
|
if custom_stop:
|
||||||
strategy.stoploss_value = custom_stop
|
strategy.stoploss_value = custom_stop
|
||||||
|
Loading…
Reference in New Issue
Block a user