Skip to content

Commit 2697ac3

Browse files
committed
chore: stop detail processing once a trade closed
1 parent 70d9ac0 commit 2697ac3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

freqtrade/optimize/backtesting.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,9 @@ def backtest(self, processed: dict, start_date: datetime, end_date: datetime) ->
14861486
current_detail_time: datetime = row[DATE_IDX].to_pydatetime()
14871487
trade_dir: LongShort | None = self.check_for_trade_entry(row)
14881488

1489+
pair_has_open_trades = len(LocalTrade.bt_trades_open_pp[pair]) > 0
14891490
if (
1490-
(trade_dir is not None or len(LocalTrade.bt_trades_open_pp[pair]) > 0)
1491+
(trade_dir is not None or pair_has_open_trades)
14911492
and self.timeframe_detail
14921493
and pair in self.detail_data
14931494
):
@@ -1525,6 +1526,9 @@ def backtest(self, processed: dict, start_date: datetime, end_date: datetime) ->
15251526
)
15261527
current_time_det += self.timeframe_detail_td
15271528
is_first = False
1529+
if pair_has_open_trades and not len(LocalTrade.bt_trades_open_pp[pair]) > 0:
1530+
# Auto-lock pair for the rest of the candle if the trade has been closed.
1531+
break
15281532
else:
15291533
self.dataprovider._set_dataframe_max_date(current_time)
15301534
self.backtest_loop(row, pair, current_time, trade_dir, not is_last_row)

0 commit comments

Comments
 (0)