From 0672d8f094ebd56a5852bfa942e4a5253a080669 Mon Sep 17 00:00:00 2001 From: ABS <53243996+ABSllk@users.noreply.github.com> Date: Thu, 19 Feb 2026 04:14:41 +0800 Subject: [PATCH] refactor: limit pre-window balance aggregation to equity mode --- .../protections/max_drawdown_protection.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/freqtrade/plugins/protections/max_drawdown_protection.py b/freqtrade/plugins/protections/max_drawdown_protection.py index 6f80acf22..396791d10 100644 --- a/freqtrade/plugins/protections/max_drawdown_protection.py +++ b/freqtrade/plugins/protections/max_drawdown_protection.py @@ -54,17 +54,17 @@ class MaxDrawdown(IProtection): if len(trades_in_window) < self._trade_limit: return None - # Get all trades to calculate cumulative profit before the window - all_closed_trades = Trade.get_trades_proxy(is_open=False) - profit_before_window = sum( - trade.close_profit_abs or 0.0 - for trade in all_closed_trades - if trade.close_date_utc <= look_back_until - ) - try: if self._calculation_mode == "equity": # Standard equity-based drawdown + # Get all trades to calculate cumulative profit before the window + all_closed_trades = Trade.get_trades_proxy(is_open=False) + profit_before_window = sum( + trade.close_profit_abs or 0.0 + for trade in all_closed_trades + if trade.close_date_utc <= look_back_until + ) + trades_df = pd.DataFrame( [ {"close_date": t.close_date_utc, "profit_abs": t.close_profit_abs}