diff --git a/freqtrade/persistence.py b/freqtrade/persistence.py index 5be61393e..5a18a922a 100644 --- a/freqtrade/persistence.py +++ b/freqtrade/persistence.py @@ -240,16 +240,16 @@ class Trade(_DECL_BASE): if not self.stop_loss: logger.debug("assigning new stop loss") self.stop_loss = new_loss - self.stop_loss_pct = stoploss + self.stop_loss_pct = -1 * abs(stoploss) self.initial_stop_loss = new_loss - self.initial_stop_loss_pct = stoploss + self.initial_stop_loss_pct = -1 * abs(stoploss) self.stoploss_last_update = datetime.utcnow() # evaluate if the stop loss needs to be updated else: if new_loss > self.stop_loss: # stop losses only walk up, never down! self.stop_loss = new_loss - self.stop_loss_pct = stoploss + self.stop_loss_pct = -1 * abs(stoploss) self.stoploss_last_update = datetime.utcnow() logger.debug("adjusted stop loss") else: diff --git a/freqtrade/tests/test_persistence.py b/freqtrade/tests/test_persistence.py index 042237ce7..f57a466e3 100644 --- a/freqtrade/tests/test_persistence.py +++ b/freqtrade/tests/test_persistence.py @@ -599,32 +599,42 @@ def test_adjust_stop_loss(fee): trade.adjust_stop_loss(trade.open_rate, 0.05, True) assert trade.stop_loss == 0.95 + assert trade.stop_loss_pct == -0.05 assert trade.initial_stop_loss == 0.95 + assert trade.initial_stop_loss_pct == -0.05 # Get percent of profit with a lower rate trade.adjust_stop_loss(0.96, 0.05) assert trade.stop_loss == 0.95 + assert trade.stop_loss_pct == -0.05 assert trade.initial_stop_loss == 0.95 + assert trade.initial_stop_loss_pct == -0.05 # Get percent of profit with a custom rate (Higher than open rate) trade.adjust_stop_loss(1.3, -0.1) assert round(trade.stop_loss, 8) == 1.17 + assert trade.stop_loss_pct == -0.1 assert trade.initial_stop_loss == 0.95 + assert trade.initial_stop_loss_pct == -0.05 # current rate lower again ... should not change trade.adjust_stop_loss(1.2, 0.1) assert round(trade.stop_loss, 8) == 1.17 assert trade.initial_stop_loss == 0.95 + assert trade.initial_stop_loss_pct == -0.05 # current rate higher... should raise stoploss trade.adjust_stop_loss(1.4, 0.1) assert round(trade.stop_loss, 8) == 1.26 assert trade.initial_stop_loss == 0.95 + assert trade.initial_stop_loss_pct == -0.05 # Initial is true but stop_loss set - so doesn't do anything trade.adjust_stop_loss(1.7, 0.1, True) assert round(trade.stop_loss, 8) == 1.26 assert trade.initial_stop_loss == 0.95 + assert trade.initial_stop_loss_pct == -0.05 + assert trade.stop_loss_pct == -0.1 def test_adjust_min_max_rates(fee):