]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): filter noisy candles in pivot labeling
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 8 May 2025 20:59:17 +0000 (22:59 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 8 May 2025 20:59:17 +0000 (22:59 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py
quickadapter/user_data/strategies/Utils.py

index ec6e4923100dab08da10b2535c233d956f0350bd..6dada925720490732d71fca35044d9d4199d8a5a 100644 (file)
@@ -934,6 +934,22 @@ def zigzag(
             elif direction == TrendDirection.UP:
                 previous_slope_ok = previous_slope < 0
 
+        significant_move_away_ok = False
+        if direction == TrendDirection.DOWN:
+            if np.any(
+                next_lows
+                < highs[candidate_pivot_pos]
+                * (1 - thresholds[candidate_pivot_pos] * 0.15)
+            ):
+                significant_move_away_ok = True
+        elif direction == TrendDirection.UP:
+            if np.any(
+                next_highs
+                > lows[candidate_pivot_pos]
+                * (1 + thresholds[candidate_pivot_pos] * 0.15)
+            ):
+                significant_move_away_ok = True
+
         if direction == TrendDirection.DOWN:
             return (
                 np.all(next_closes < highs[candidate_pivot_pos])
@@ -942,6 +958,7 @@ def zigzag(
                 and np.max(previous_highs) <= highs[candidate_pivot_pos]
                 and next_slope_ok
                 and previous_slope_ok
+                and significant_move_away_ok
             )
         elif direction == TrendDirection.UP:
             return (
@@ -951,6 +968,7 @@ def zigzag(
                 and np.min(previous_lows) >= lows[candidate_pivot_pos]
                 and next_slope_ok
                 and previous_slope_ok
+                and significant_move_away_ok
             )
         return False
 
index 68a5770f349aa8d55437a26aafd5e3539450f365..1ebdfac92255c9ff1c57375dabd7d0cd4d19407e 100644 (file)
@@ -428,6 +428,22 @@ def zigzag(
             elif direction == TrendDirection.UP:
                 previous_slope_ok = previous_slope < 0
 
+        significant_move_away_ok = False
+        if direction == TrendDirection.DOWN:
+            if np.any(
+                next_lows
+                < highs[candidate_pivot_pos]
+                * (1 - thresholds[candidate_pivot_pos] * 0.15)
+            ):
+                significant_move_away_ok = True
+        elif direction == TrendDirection.UP:
+            if np.any(
+                next_highs
+                > lows[candidate_pivot_pos]
+                * (1 + thresholds[candidate_pivot_pos] * 0.15)
+            ):
+                significant_move_away_ok = True
+
         if direction == TrendDirection.DOWN:
             return (
                 np.all(next_closes < highs[candidate_pivot_pos])
@@ -436,6 +452,7 @@ def zigzag(
                 and np.max(previous_highs) <= highs[candidate_pivot_pos]
                 and next_slope_ok
                 and previous_slope_ok
+                and significant_move_away_ok
             )
         elif direction == TrendDirection.UP:
             return (
@@ -445,6 +462,7 @@ def zigzag(
                 and np.min(previous_lows) >= lows[candidate_pivot_pos]
                 and next_slope_ok
                 and previous_slope_ok
+                and significant_move_away_ok
             )
         return False