From 2a678bdbb4494cb143b8a2b0dee4e7aebcaa06f1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 25 Sep 2021 19:31:06 +0200 Subject: [PATCH] Update buy_tag column to long_tag --- freqtrade/data/btanalysis.py | 1 + freqtrade/enums/signaltype.py | 2 +- freqtrade/optimize/backtesting.py | 7 ++++--- freqtrade/strategy/interface.py | 4 ++-- tests/optimize/test_hyperopt_tools.py | 2 +- tests/strategy/test_interface.py | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/freqtrade/data/btanalysis.py b/freqtrade/data/btanalysis.py index 7d97661c4..e8d878838 100644 --- a/freqtrade/data/btanalysis.py +++ b/freqtrade/data/btanalysis.py @@ -31,6 +31,7 @@ BT_DATA_COLUMNS = ['pair', 'stake_amount', 'amount', 'open_date', 'close_date', 'profit_ratio', 'profit_abs', 'sell_reason', 'initial_stop_loss_abs', 'initial_stop_loss_ratio', 'stop_loss_abs', 'stop_loss_ratio', 'min_rate', 'max_rate', 'is_open', 'buy_tag'] +# TODO-lev: usage of the above might need compatibility code (buy_tag, is_short?, ...?) def get_latest_optimize_filename(directory: Union[Path, str], variant: str) -> str: diff --git a/freqtrade/enums/signaltype.py b/freqtrade/enums/signaltype.py index b1b86fc47..1f2b6d331 100644 --- a/freqtrade/enums/signaltype.py +++ b/freqtrade/enums/signaltype.py @@ -15,7 +15,7 @@ class SignalTagType(Enum): """ Enum for signal columns """ - BUY_TAG = "buy_tag" + LONG_TAG = "long_tag" SHORT_TAG = "short_tag" diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 4094cf0aa..63d307908 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -45,7 +45,7 @@ LONG_IDX = 5 ELONG_IDX = 6 # Exit long SHORT_IDX = 7 ESHORT_IDX = 8 # Exit short -BUY_TAG_IDX = 9 +ENTER_TAG_IDX = 9 SHORT_TAG_IDX = 10 @@ -454,7 +454,8 @@ class Backtesting: if stake_amount and (not min_stake_amount or stake_amount > min_stake_amount): # Enter trade - has_buy_tag = len(row) >= BUY_TAG_IDX + 1 + # TODO-lev: SHORT_TAG ... + has_buy_tag = len(row) >= ENTER_TAG_IDX + 1 trade = LocalTrade( pair=pair, open_rate=row[OPEN_IDX], @@ -464,7 +465,7 @@ class Backtesting: fee_open=self.fee, fee_close=self.fee, is_open=True, - buy_tag=row[BUY_TAG_IDX] if has_buy_tag else None, + buy_tag=row[ENTER_TAG_IDX] if has_buy_tag else None, exchange=self._exchange_name, is_short=(direction == 'short'), ) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index abaf7d224..4e8881295 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -519,7 +519,7 @@ class IStrategy(ABC, HyperStrategyMixin): dataframe[SignalType.EXIT_LONG.value] = 0 dataframe[SignalType.ENTER_SHORT.value] = 0 dataframe[SignalType.EXIT_SHORT.value] = 0 - dataframe[SignalTagType.BUY_TAG.value] = None + dataframe[SignalTagType.LONG_TAG.value] = None dataframe[SignalTagType.SHORT_TAG.value] = None # Other Defs in strategy that want to be called every loop here @@ -690,7 +690,7 @@ class IStrategy(ABC, HyperStrategyMixin): enter_tag_value: Optional[str] = None if enter_long == 1 and not any([exit_long, enter_short]): enter_signal = SignalDirection.LONG - enter_tag_value = latest.get(SignalTagType.BUY_TAG.value, None) + enter_tag_value = latest.get(SignalTagType.LONG_TAG.value, None) if enter_short == 1 and not any([exit_short, enter_long]): enter_signal = SignalDirection.SHORT enter_tag_value = latest.get(SignalTagType.SHORT_TAG.value, None) diff --git a/tests/optimize/test_hyperopt_tools.py b/tests/optimize/test_hyperopt_tools.py index 5a46f238b..17e8248c3 100644 --- a/tests/optimize/test_hyperopt_tools.py +++ b/tests/optimize/test_hyperopt_tools.py @@ -167,7 +167,7 @@ def test__pprint_dict(): def test_get_strategy_filename(default_conf): - x = HyperoptTools.get_strategy_filename(default_conf, CURRENT_TEST_STRATEGY) + x = HyperoptTools.get_strategy_filename(default_conf, 'StrategyTestV3') assert isinstance(x, Path) assert x == Path(__file__).parents[1] / 'strategy/strats/strategy_test_v3.py' diff --git a/tests/strategy/test_interface.py b/tests/strategy/test_interface.py index 4b39adaf7..1ec5eef5a 100644 --- a/tests/strategy/test_interface.py +++ b/tests/strategy/test_interface.py @@ -59,7 +59,7 @@ def test_returns_latest_signal(ohlcv_history): assert _STRATEGY.get_exit_signal('ETH/BTC', '5m', mocked_history, True) == (False, False) mocked_history.loc[1, 'exit_long'] = 0 mocked_history.loc[1, 'enter_long'] = 1 - mocked_history.loc[1, 'buy_tag'] = 'buy_signal_01' + mocked_history.loc[1, 'long_tag'] = 'buy_signal_01' assert _STRATEGY.get_entry_signal( 'ETH/BTC', '5m', mocked_history) == (SignalDirection.LONG, 'buy_signal_01')