From cc38f0656dc0161e5103a145fdce443642dd6289 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 5 Mar 2022 14:11:21 +0100 Subject: [PATCH] Explicitly check for None to determine if initial stoploss was set closes #6460 --- freqtrade/constants.py | 2 +- freqtrade/persistence/models.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 320820b20..cc4a14a2b 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -144,7 +144,7 @@ CONF_SCHEMA = { 'minProperties': 1 }, 'amount_reserve_percent': {'type': 'number', 'minimum': 0.0, 'maximum': 0.5}, - 'stoploss': {'type': 'number', 'maximum': 0, 'exclusiveMaximum': True}, + 'stoploss': {'type': 'number', 'maximum': 0, 'exclusiveMaximum': True, 'minimum': -1}, 'trailing_stop': {'type': 'boolean'}, 'trailing_stop_positive': {'type': 'number', 'minimum': 0, 'maximum': 1}, 'trailing_stop_positive_offset': {'type': 'number', 'minimum': 0, 'maximum': 1}, diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index 36340033c..f074ecfd9 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -311,7 +311,7 @@ class LocalTrade(): # absolute value of the initial stop loss initial_stop_loss: float = 0.0 # percentage value of the initial stop loss - initial_stop_loss_pct: float = 0.0 + initial_stop_loss_pct: Optional[float] = None # stoploss order id which is on exchange stoploss_order_id: Optional[str] = None # last update time of the stoploss order on exchange @@ -576,7 +576,8 @@ class LocalTrade(): new_loss = max(self.isolated_liq, new_loss) # no stop loss assigned yet - if not self.stop_loss: + # if not self.stop_loss: + if self.initial_stop_loss_pct is None: logger.debug(f"{self.pair} - Assigning new stoploss...") self._set_stop_loss(new_loss, stoploss) self.initial_stop_loss = new_loss @@ -1040,6 +1041,7 @@ class LocalTrade(): logger.info(f"Stoploss for {trade} needs adjustment...") # Force reset of stoploss trade.stop_loss = None + trade.initial_stop_loss_pct = None trade.adjust_stop_loss(trade.open_rate, desired_stoploss) logger.info(f"New stoploss: {trade.stop_loss}.")