From fdf0801806ab5f53919bc59aca8cd4f6f94f5552 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 18 May 2025 00:19:37 +0200 Subject: [PATCH] fix(qav3): make TP/SL targets handle assets with price close to zero MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../freqaimodels/QuickAdapterRegressorV3.py | 12 +++++++----- quickadapter/user_data/strategies/QuickAdapterV3.py | 10 +++++----- quickadapter/user_data/strategies/Utils.py | 12 +++++++----- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 362ca1b..02f3304 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -900,8 +900,9 @@ def zigzag( lookback_natr = natr_values[start:end] natr_pos = natr_values[pos] median_natr = np.median(lookback_natr) - - natr_ratio = natr_pos / (median_natr + np.finfo(float).eps) + if median_natr == 0: + median_natr = np.finfo(float).eps + natr_ratio = natr_pos / median_natr smoothed_natr_ratio = np.sqrt(natr_ratio) depth_factor = ( @@ -945,9 +946,10 @@ def zigzag( return min_value natr_min = np.min(natr_values[start:end]) natr_max = np.max(natr_values[start:end]) - normalized_natr_pos = (natr_pos - natr_min) / ( - natr_max - natr_min + np.finfo(float).eps - ) + natr_range = natr_max - natr_min + if natr_range == 0: + natr_range = np.finfo(float).eps + normalized_natr_pos = (natr_pos - natr_min) / natr_range return min_value + (max_value - min_value) * normalized_natr_pos diff --git a/quickadapter/user_data/strategies/QuickAdapterV3.py b/quickadapter/user_data/strategies/QuickAdapterV3.py index 7994b54..837c56a 100644 --- a/quickadapter/user_data/strategies/QuickAdapterV3.py +++ b/quickadapter/user_data/strategies/QuickAdapterV3.py @@ -58,7 +58,7 @@ class QuickAdapterV3(IStrategy): INTERFACE_VERSION = 3 def version(self) -> str: - return "3.3.36" + return "3.3.37" timeframe = "5m" @@ -530,8 +530,8 @@ class QuickAdapterV3(IStrategy): else: entry_natr_weight += weight_adjustment current_natr_weight -= weight_adjustment - entry_natr_weight = max(0.0, min(1.0, entry_natr_weight)) - current_natr_weight = max(0.0, min(1.0, current_natr_weight)) + entry_natr_weight = np.clip(entry_natr_weight, 0.0, 1.0) + current_natr_weight = np.clip(current_natr_weight, 0.0, 1.0) take_profit_natr = ( entry_natr_weight * entry_natr + current_natr_weight * current_natr ) @@ -559,7 +559,7 @@ class QuickAdapterV3(IStrategy): stoploss_distance = self.get_stoploss_distance(df, trade, current_rate) if isna(stoploss_distance): return None - if np.isclose(stoploss_distance, 0) or stoploss_distance < 0: + if stoploss_distance <= 0: return None sign = 1 if trade.is_short else -1 return stoploss_from_absolute( @@ -607,7 +607,7 @@ class QuickAdapterV3(IStrategy): take_profit_distance = self.get_take_profit_distance(df, trade) if isna(take_profit_distance): return None - if np.isclose(take_profit_distance, 0) or take_profit_distance < 0: + if take_profit_distance <= 0: return None take_profit_price = ( trade.open_rate + (-1 if trade.is_short else 1) * take_profit_distance diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 1d75d16..e43c323 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -397,8 +397,9 @@ def zigzag( lookback_natr = natr_values[start:end] natr_pos = natr_values[pos] median_natr = np.median(lookback_natr) - - natr_ratio = natr_pos / (median_natr + np.finfo(float).eps) + if median_natr == 0: + median_natr = np.finfo(float).eps + natr_ratio = natr_pos / median_natr smoothed_natr_ratio = np.sqrt(natr_ratio) depth_factor = ( @@ -442,9 +443,10 @@ def zigzag( return min_value natr_min = np.min(natr_values[start:end]) natr_max = np.max(natr_values[start:end]) - normalized_natr_pos = (natr_pos - natr_min) / ( - natr_max - natr_min + np.finfo(float).eps - ) + natr_range = natr_max - natr_min + if natr_range == 0: + natr_range = np.finfo(float).eps + normalized_natr_pos = (natr_pos - natr_min) / natr_range return min_value + (max_value - min_value) * normalized_natr_pos -- 2.43.0