From: Jérôme Benoit Date: Sat, 9 Aug 2025 19:59:48 +0000 (+0200) Subject: perf(qav3): tune trade final exit condition X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a3509b632493d2b74f179adbeb87b32551bd60a5;p=freqai-strategies.git perf(qav3): tune trade final exit condition Signed-off-by: Jérôme Benoit --- diff --git a/ReforceXY/user_data/strategies/RLAgentStrategy.py b/ReforceXY/user_data/strategies/RLAgentStrategy.py index ad03d0c..a4b0cf3 100644 --- a/ReforceXY/user_data/strategies/RLAgentStrategy.py +++ b/ReforceXY/user_data/strategies/RLAgentStrategy.py @@ -23,13 +23,11 @@ class RLAgentStrategy(IStrategy): process_only_new_candles = True stoploss = -0.02 - # Trailing stop: - trailing_stop = False - trailing_stop_positive = 0.01 - trailing_stop_positive_offset = 0.011 - trailing_only_offset_is_reached = True - - use_exit_signal = True + # # Trailing stop: + # trailing_stop = False + # trailing_stop_positive = 0.01 + # trailing_stop_positive_offset = 0.011 + # trailing_only_offset_is_reached = True startup_candle_count: int = 300 diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index 9bd454e..7842928 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -65,19 +65,13 @@ class QuickAdapterV3(IStrategy): INTERFACE_VERSION = 3 def version(self) -> str: - return "3.3.149" + return "3.3.150" timeframe = "5m" stoploss = -0.02 use_custom_stoploss = True - # Trailing stop: - trailing_stop = False - trailing_stop_positive = 0.01 - trailing_stop_positive_offset = 0.011 - trailing_only_offset_is_reached = True - order_types = { "entry": "limit", "exit": "limit", @@ -98,7 +92,7 @@ class QuickAdapterV3(IStrategy): } default_exit_thresholds_calibration: dict[str, float] = { - "spike_quantile": 0.98, + "spike_quantile": 0.95, "decline_quantile": 0.90, "min_k_spike": 0.3, "min_k_decline": 0.15, @@ -863,19 +857,8 @@ class QuickAdapterV3(IStrategy): trade.open_rate + (-1 if trade.is_short else 1) * take_profit_distance ) trade_take_profit_price_history = ( - QuickAdapterV3.get_trade_take_profit_price_history(trade) - ) - previous_take_profit_price = ( - trade_take_profit_price_history[-1] - if trade_take_profit_price_history - else None + QuickAdapterV3.safe_append_trade_take_profit_price(trade, take_profit_price) ) - if previous_take_profit_price is None or not np.isclose( - previous_take_profit_price, take_profit_price - ): - trade_take_profit_price_history = self.append_trade_take_profit_price( - trade, take_profit_price - ) if exit_stage not in self.partial_exit_stages: if not trade_take_profit_price_history: @@ -917,6 +900,19 @@ class QuickAdapterV3(IStrategy): trade.set_custom_data("history", history) return pnl_history + def safe_append_trade_unrealized_pnl(self, trade: Trade, pnl: float) -> list[float]: + trade_unrealized_pnl_history = QuickAdapterV3.get_trade_unrealized_pnl_history( + trade + ) + previous_unrealized_pnl = ( + trade_unrealized_pnl_history[-1] if trade_unrealized_pnl_history else None + ) + if previous_unrealized_pnl is None or not np.isclose( + previous_unrealized_pnl, pnl + ): + trade_unrealized_pnl_history = self.append_trade_unrealized_pnl(trade, pnl) + return trade_unrealized_pnl_history + def append_trade_take_profit_price( self, trade: Trade, take_profit_price: float ) -> list[float]: @@ -929,6 +925,25 @@ class QuickAdapterV3(IStrategy): trade.set_custom_data("history", history) return price_history + def safe_append_trade_take_profit_price( + self, trade: Trade, take_profit_price: float + ) -> list[float]: + trade_take_profit_price_history = ( + QuickAdapterV3.get_trade_take_profit_price_history(trade) + ) + previous_take_profit_price = ( + trade_take_profit_price_history[-1] + if trade_take_profit_price_history + else None + ) + if previous_take_profit_price is None or not np.isclose( + previous_take_profit_price, take_profit_price + ): + trade_take_profit_price_history = self.append_trade_take_profit_price( + trade, take_profit_price + ) + return trade_take_profit_price_history + def adjust_trade_position( self, trade: Trade, @@ -1199,16 +1214,7 @@ class QuickAdapterV3(IStrategy): current_profit: float, **kwargs, ) -> Optional[str]: - trade_unrealized_pnl_history = QuickAdapterV3.get_trade_unrealized_pnl_history( - trade - ) - previous_unrealized_pnl = ( - trade_unrealized_pnl_history[-1] if trade_unrealized_pnl_history else None - ) - if previous_unrealized_pnl is None or not np.isclose( - previous_unrealized_pnl, current_profit - ): - self.append_trade_unrealized_pnl(trade, current_profit) + self.safe_append_trade_unrealized_pnl(trade, current_profit) df, _ = self.dp.get_analyzed_dataframe( pair=pair, timeframe=self.config.get("timeframe")