diff --git a/freqtrade/resolvers/strategy_resolver.py b/freqtrade/resolvers/strategy_resolver.py index a349f6da4..7dfa6b0f2 100644 --- a/freqtrade/resolvers/strategy_resolver.py +++ b/freqtrade/resolvers/strategy_resolver.py @@ -177,7 +177,8 @@ class StrategyResolver(IResolver): raise ImportError( "Short strategies cannot run in spot markets. Please make sure that this " "is the correct strategy and that your trading mode configuration is correct. " - "You can run this strategy by setting `can_short=False` in your strategy." + "You can run this strategy in spot markets by setting `can_short=False`" + " in your strategy. Please note that short signals will be ignored in that case." ) @staticmethod diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index bbd7f7a19..09f611b1e 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -759,7 +759,7 @@ class IStrategy(ABC, HyperStrategyMixin): enter_long = latest[SignalType.ENTER_LONG.value] == 1 exit_long = latest.get(SignalType.EXIT_LONG.value, 0) == 1 - enter_short = latest.get(SignalType.ENTER_SHORT.value, 0) == 1 + enter_short = latest.get(SignalType.ENTER_SHORT.value, 0 == 1) exit_short = latest.get(SignalType.EXIT_SHORT.value, 0) == 1 enter_signal: Optional[SignalDirection] = None @@ -768,6 +768,7 @@ class IStrategy(ABC, HyperStrategyMixin): enter_signal = SignalDirection.LONG enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None) if (self.config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT + and self.can_short and enter_short == 1 and not any([exit_short, enter_long])): enter_signal = SignalDirection.SHORT enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None) diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 82cc707f4..367818215 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -78,6 +78,12 @@ def test_returns_latest_signal(ohlcv_history): assert _STRATEGY.get_entry_signal('ETH/BTC', '5m', mocked_history) == (None, None) _STRATEGY.config['trading_mode'] = 'futures' + # Short signal get's ignored as can_short is not set. + assert _STRATEGY.get_entry_signal( + 'ETH/BTC', '5m', mocked_history) == (None, None) + + _STRATEGY.can_short = True + assert _STRATEGY.get_entry_signal( 'ETH/BTC', '5m', mocked_history) == (SignalDirection.SHORT, 'sell_signal_01') assert _STRATEGY.get_exit_signal('ETH/BTC', '5m', mocked_history) == (False, False, None) @@ -93,6 +99,7 @@ def test_returns_latest_signal(ohlcv_history): assert _STRATEGY.get_exit_signal( 'ETH/BTC', '5m', mocked_history, True) == (False, True, 'sell_signal_02') + _STRATEGY.can_short = False _STRATEGY.config['trading_mode'] = 'spot'