]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): make TP/SL targets handle assets with price close to zero
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 17 May 2025 22:19:37 +0000 (00:19 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sat, 17 May 2025 22:19:37 +0000 (00:19 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/QuickAdapterV3.py
quickadapter/user_data/strategies/Utils.py

index 362ca1b403a8899f02358aa95bf106aa50c6e3ab..02f33040b269e431c403789399242b2f30d4828b 100644 (file)
@@ -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
 
index 7994b5471e3e02e70451870914bce7b8b5dd6729..837c56a5ee99abdbcdd10e804c0f7f206bc44455 100644 (file)
@@ -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
index 1d75d16e233ac26bf36baef40d6427fc4a87dcb4..e43c323fc0b0df280567d15f9fb74ea7d1905f99 100644 (file)
@@ -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