diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 179db1313..3fddc98df 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -961,9 +961,9 @@ class IStrategy(ABC, HyperStrategyMixin): else: logger.warning("CustomStoploss function did not return valid stoploss") - sl_lower_long = (trade.stop_loss < (low or current_rate) and not trade.is_short) - sl_higher_short = (trade.stop_loss > (high or current_rate) and trade.is_short) - if self.trailing_stop and (sl_lower_long or sl_higher_short): + sl_lower_short = (trade.stop_loss < (low or current_rate) and not trade.is_short) + sl_higher_long = (trade.stop_loss > (high or current_rate) and trade.is_short) + if self.trailing_stop and (sl_lower_short or sl_higher_long): # trailing stoploss handling sl_offset = self.trailing_stop_positive_offset @@ -981,12 +981,12 @@ class IStrategy(ABC, HyperStrategyMixin): trade.adjust_stop_loss(bound or current_rate, stop_loss_value) - sl_higher_short = (trade.stop_loss >= (low or current_rate) and not trade.is_short) - sl_lower_long = ((trade.stop_loss <= (high or current_rate) and trade.is_short)) + sl_higher_long = (trade.stop_loss >= (low or current_rate) and not trade.is_short) + sl_lower_short = (trade.stop_loss <= (high or current_rate) and trade.is_short) # evaluate if the stoploss was hit if stoploss is not on exchange # in Dry-Run, this handles stoploss logic as well, as the logic will not be different to # regular stoploss handling. - if ((sl_higher_short or sl_lower_long) and + if ((sl_higher_long or sl_lower_short) and (not self.order_types.get('stoploss_on_exchange') or self.config['dry_run'])): sell_type = SellType.STOP_LOSS diff --git a/tests/optimize/test_backtest_detail.py b/tests/optimize/test_backtest_detail.py index ad9ae7786..7ede1adc3 100644 --- a/tests/optimize/test_backtest_detail.py +++ b/tests/optimize/test_backtest_detail.py @@ -520,7 +520,9 @@ tc28s = BTContainer(data=[ stop_loss=-0.10, roi={"0": 0.10}, profit_perc=-0.03, trailing_stop=True, trailing_only_offset_is_reached=True, trailing_stop_positive_offset=0.05, trailing_stop_positive=0.03, - trades=[BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=3, is_short=True)] + trades=[ + BTrade(sell_reason=SellType.TRAILING_STOP_LOSS, open_tick=1, close_tick=3, is_short=True) + ] ) # Test 29: trailing_stop should be triggered by low of next candle, without adjusting stoploss using