From 0820844c84485c3e25868734e53da8ffeab4258e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 1 May 2025 00:08:21 +0200 Subject: [PATCH] refactor(qav3): cleanup trade entry confirmation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../user_data/strategies/QuickAdapterV3.py | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index c819816..92d27fc 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -366,13 +366,13 @@ class QuickAdapterV3(IStrategy): self._label_params[pair]["label_natr_ratio"] = label_natr_ratio def get_entry_natr_ratio(self, pair: str) -> float: - return self.get_label_natr_ratio(pair) * 0.0125 + return self.get_label_natr_ratio(pair) * 0.0175 def get_stoploss_natr_ratio(self, pair: str) -> float: return self.get_label_natr_ratio(pair) * 0.625 def get_take_profit_natr_ratio(self, pair: str) -> float: - return self.get_stoploss_natr_ratio(pair) * 0.85 + return self.get_stoploss_natr_ratio(pair) * 0.825 def set_freqai_targets(self, dataframe: DataFrame, metadata: dict, **kwargs): pair = str(metadata.get("pair")) @@ -619,15 +619,8 @@ class QuickAdapterV3(IStrategy): max_open_trades_per_side = self.max_open_trades_per_side() if max_open_trades_per_side >= 0: open_trades = Trade.get_open_trades() - num_shorts, num_longs = 0, 0 - for trade in open_trades: - if "short" in trade.enter_tag: - num_shorts += 1 - elif "long" in trade.enter_tag: - num_longs += 1 - if (side == "long" and num_longs >= max_open_trades_per_side) or ( - side == "short" and num_shorts >= max_open_trades_per_side - ): + trades_per_side = sum(1 for trade in open_trades if trade.side == side) + if trades_per_side >= max_open_trades_per_side: return False df, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe) @@ -641,10 +634,11 @@ class QuickAdapterV3(IStrategy): entry_price_fluctuation_threshold = ( last_candle_natr * self.get_entry_natr_ratio(pair) ) - # Confirm extrema with reversal with price movement boundaries - if (rate > last_candle_close * (1 + entry_price_fluctuation_threshold)) or ( - rate < last_candle_close * (1 - entry_price_fluctuation_threshold) - ): + upper_bound = last_candle_close * (1 + entry_price_fluctuation_threshold) + lower_bound = last_candle_close * (1 - entry_price_fluctuation_threshold) + if side == "long" and (rate > upper_bound or rate < lower_bound): + return False + elif side == "short" and (rate < lower_bound or rate > upper_bound): return False return True -- 2.43.0