From 6637dacd7f0556b6076f63f099fed6d9e9899de1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 30 Jan 2022 17:17:03 +0100 Subject: [PATCH] Extract protections in backtesting --- freqtrade/optimize/backtesting.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 220d7557e..2a7602cd3 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -630,6 +630,11 @@ class Backtesting: self.rejected_trades += 1 return False + def run_protections(self, enable_protections, pair: str, current_time: datetime): + if enable_protections: + self.protections.stop_per_pair(pair, current_time) + self.protections.global_stop(current_time) + def backtest(self, processed: Dict, start_date: datetime, end_date: datetime, max_open_trades: int = 0, position_stacking: bool = False, @@ -736,9 +741,7 @@ class Backtesting: open_trades[pair].remove(trade) LocalTrade.close_bt_trade(trade) trades.append(trade) - if enable_protections: - self.protections.stop_per_pair(pair, row[DATE_IDX]) - self.protections.global_stop(current_time) + self.run_protections(enable_protections, pair, current_time) # 5. Cancel expired buy/sell orders. for order in [o for o in trade.orders if o.ft_is_open]: