From 53d46a0385e859e199b8aa038205169f0d38bc22 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 25 Aug 2022 20:36:17 +0200 Subject: [PATCH] align `max_entry_position_adjustment` behavior of backtesting to live closes #7293 --- freqtrade/optimize/backtesting.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 248300fad..00cd8fa4a 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -534,12 +534,16 @@ class Backtesting: # Check if we should increase our position if stake_amount is not None and stake_amount > 0.0: - - pos_trade = self._enter_trade( - trade.pair, row, 'short' if trade.is_short else 'long', stake_amount, trade) - if pos_trade is not None: - self.wallets.update() - return pos_trade + check_adjust_entry = True + if self.strategy.max_entry_position_adjustment > -1: + entry_count = trade.nr_of_successful_entries + check_adjust_entry = (entry_count <= self.strategy.max_entry_position_adjustment) + if check_adjust_entry: + pos_trade = self._enter_trade( + trade.pair, row, 'short' if trade.is_short else 'long', stake_amount, trade) + if pos_trade is not None: + self.wallets.update() + return pos_trade if stake_amount is not None and stake_amount < 0.0: amount = abs(stake_amount) / current_rate @@ -570,12 +574,7 @@ class Backtesting: # Check if we need to adjust our current positions if self.strategy.position_adjustment_enable: - check_adjust_entry = True - if self.strategy.max_entry_position_adjustment > -1: - entry_count = trade.nr_of_successful_entries - check_adjust_entry = (entry_count <= self.strategy.max_entry_position_adjustment) - if check_adjust_entry: - trade = self._get_adjust_trade_entry_for_candle(trade, row) + trade = self._get_adjust_trade_entry_for_candle(trade, row) enter = row[SHORT_IDX] if trade.is_short else row[LONG_IDX] exit_sig = row[ESHORT_IDX] if trade.is_short else row[ELONG_IDX]