From 6c4b261469aef755c94be672d3eba807e50860da Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 16 Jan 2022 08:04:39 +0100 Subject: [PATCH] Convert nan to None in get_signal. --- freqtrade/strategy/interface.py | 3 +++ tests/strategy/test_interface.py | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 36061dc20..c8fb24da1 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -654,6 +654,9 @@ class IStrategy(ABC, HyperStrategyMixin): buy_tag = latest.get(SignalTagType.BUY_TAG.value, None) exit_tag = latest.get(SignalTagType.EXIT_TAG.value, None) + # Tags can be None, which does not resolve to False. + buy_tag = buy_tag if isinstance(buy_tag, str) else None + exit_tag = exit_tag if isinstance(exit_tag, str) else None logger.debug('trigger: %s (pair=%s) buy=%s sell=%s', latest['date'], pair, str(buy), str(sell)) diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index f57a9f34e..fd1c2753f 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -36,6 +36,10 @@ def test_returns_latest_signal(ohlcv_history): mocked_history = ohlcv_history.copy() mocked_history['sell'] = 0 mocked_history['buy'] = 0 + # Set tags in lines that don't matter to test nan in the sell line + mocked_history.loc[0, 'buy_tag'] = 'wrong_line' + mocked_history.loc[0, 'exit_tag'] = 'wrong_line' + mocked_history.loc[1, 'sell'] = 1 assert _STRATEGY.get_signal('ETH/BTC', '5m', mocked_history) == (False, True, None, None)