From 4d49f1a0c7627f8e8a96adaf4d90c9dac3fc0eb8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 26 Sep 2021 15:39:34 +0200 Subject: [PATCH] Reset columns by dropping instead of resetting --- freqtrade/optimize/backtesting.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 4a20d9738..c82ee4afc 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -263,14 +263,7 @@ class Backtesting: if not pair_data.empty: # Cleanup from prior runs - # TODO-lev: The below is not 100% compatible with the interface compatibility layer - if 'enter_long' in pair_data.columns: - pair_data.loc[:, 'enter_long'] = 0 - pair_data.loc[:, 'enter_short'] = 0 - if 'exit_long' in pair_data.columns: - pair_data.loc[:, 'exit_long'] = 0 - pair_data.loc[:, 'exit_short'] = 0 - pair_data.loc[:, 'enter_tag'] = None + pair_data.drop(headers[5:] + ['buy', 'sell'], axis=1, errors='ignore') df_analyzed = self.strategy.advise_exit( self.strategy.advise_entry(pair_data, {'pair': pair}), @@ -281,11 +274,11 @@ class Backtesting: startup_candles=self.required_startup) # To avoid using data from future, we use buy/sell signals shifted # from the previous candle - df_analyzed.loc[:, 'enter_long'] = df_analyzed.loc[:, 'enter_long'].shift(1) - df_analyzed.loc[:, 'enter_short'] = df_analyzed.loc[:, 'enter_short'].shift(1) - df_analyzed.loc[:, 'exit_long'] = df_analyzed.loc[:, 'exit_long'].shift(1) - df_analyzed.loc[:, 'exit_short'] = df_analyzed.loc[:, 'exit_short'].shift(1) - df_analyzed.loc[:, 'enter_tag'] = df_analyzed.loc[:, 'enter_tag'].shift(1) + for col in headers[5:]: + if col in df_analyzed.columns: + df_analyzed.loc[:, col] = df_analyzed.loc[:, col].shift(1) + else: + df_analyzed.loc[:, col] = 0 if col != 'enter_tag' else None # Update dataprovider cache self.dataprovider._set_cached_df(pair, self.timeframe, df_analyzed)