From: Jérôme Benoit Date: Mon, 20 Jul 2026 20:11:15 +0000 (+0200) Subject: refactor(quickadapter): disambiguate and centralize final exit stage constants X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=9aeb2d24826232b1c4c5d49a962517b2b73db00f;p=freqai-strategies.git refactor(quickadapter): disambiguate and centralize final exit stage constants Rename the _FINAL_EXIT_STAGE tuple to _FINAL_EXIT_STAGE_PARAMS and add the class-level constant _FINAL_EXIT_STAGE_INDEX (max(partial_exit_stages) + 1), referenced from the configuration logging, the get_trade_exit_stage clamp, and the plot config. This removes the triplicated stage-index expression and distinguishes the final stage parameters from its index. Qualify the plot config partial_exit_stages and stage-index accesses with QuickAdapterV3 to match the surrounding constant access. --- diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index 1eb0771..9603cf7 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -159,7 +159,16 @@ class QuickAdapterV3(IStrategy): } # (natr_multiplier_fraction, stake_percent, color) - _FINAL_EXIT_STAGE: Final[tuple[float, float, str]] = (1.0, 1.0, "deepskyblue") + _FINAL_EXIT_STAGE_PARAMS: Final[tuple[float, float, str]] = ( + 1.0, + 1.0, + "deepskyblue", + ) + + # Stage index of the final full exit: one past the last partial stage. + _FINAL_EXIT_STAGE_INDEX: Final[int] = ( + max(partial_exit_stages.keys(), default=-1) + 1 + ) _TAKE_PROFIT_ORDER_TAG_PREFIX: Final[str] = "take_profit_" @@ -611,9 +620,9 @@ class QuickAdapterV3(IStrategy): f" stage {stage}: natr_multiplier_fraction={format_number(natr_multiplier_fraction)}, stake_percent={format_number(stake_percent)}, color={color}" ) - final_stage = max(QuickAdapterV3.partial_exit_stages.keys(), default=-1) + 1 + final_stage = QuickAdapterV3._FINAL_EXIT_STAGE_INDEX logger.info( - f"Final Exit Stage: stage {final_stage}: natr_multiplier_fraction={format_number(QuickAdapterV3._FINAL_EXIT_STAGE[0])}, stake_percent={format_number(QuickAdapterV3._FINAL_EXIT_STAGE[1])}, color={QuickAdapterV3._FINAL_EXIT_STAGE[2]}" + f"Final Exit Stage: stage {final_stage}: natr_multiplier_fraction={format_number(QuickAdapterV3._FINAL_EXIT_STAGE_PARAMS[0])}, stake_percent={format_number(QuickAdapterV3._FINAL_EXIT_STAGE_PARAMS[1])}, color={QuickAdapterV3._FINAL_EXIT_STAGE_PARAMS[2]}" ) logger.info("Protections:") @@ -1270,8 +1279,7 @@ class QuickAdapterV3(IStrategy): QuickAdapterV3._TAKE_PROFIT_ORDER_TAG_PREFIX ) ) - final_stage = max(QuickAdapterV3.partial_exit_stages.keys(), default=-1) + 1 - return min(n_filled_take_profit_exits, final_stage) + return min(n_filled_take_profit_exits, QuickAdapterV3._FINAL_EXIT_STAGE_INDEX) @staticmethod @lru_cache(maxsize=128) @@ -1410,7 +1418,7 @@ class QuickAdapterV3(IStrategy): natr_multiplier_fraction = ( QuickAdapterV3.partial_exit_stages[exit_stage][0] if exit_stage in QuickAdapterV3.partial_exit_stages - else QuickAdapterV3._FINAL_EXIT_STAGE[0] + else QuickAdapterV3._FINAL_EXIT_STAGE_PARAMS[0] ) take_profit_distance = self.get_take_profit_distance( df, trade, natr_multiplier_fraction @@ -2301,7 +2309,7 @@ class QuickAdapterV3(IStrategy): trade_exit_stage = QuickAdapterV3.get_trade_exit_stage(trade) - for take_profit_stage, (_, _, color) in self.partial_exit_stages.items(): + for take_profit_stage in QuickAdapterV3.partial_exit_stages: if take_profit_stage < trade_exit_stage: continue @@ -2318,7 +2326,7 @@ class QuickAdapterV3(IStrategy): "end": end_date, "y_start": partial_take_profit_price, "y_end": partial_take_profit_price, - "color": color, + "color": QuickAdapterV3.partial_exit_stages[take_profit_stage][2], "line_style": "solid", "width": 1, "label": f"Take Profit {take_profit_stage}", @@ -2326,7 +2334,7 @@ class QuickAdapterV3(IStrategy): } annotations.append(take_profit_line_annotation) - final_stage = max(self.partial_exit_stages.keys(), default=-1) + 1 + final_stage = QuickAdapterV3._FINAL_EXIT_STAGE_INDEX final_take_profit_price = self.get_take_profit_price( dataframe, trade, final_stage ) @@ -2338,7 +2346,7 @@ class QuickAdapterV3(IStrategy): "end": end_date, "y_start": final_take_profit_price, "y_end": final_take_profit_price, - "color": QuickAdapterV3._FINAL_EXIT_STAGE[2], + "color": QuickAdapterV3._FINAL_EXIT_STAGE_PARAMS[2], "line_style": "solid", "width": 1, "label": f"Take Profit {final_stage}",