]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
fix(qav3): relax slope check at pivot labeling to handle corner case
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 8 May 2025 22:34:14 +0000 (00:34 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 8 May 2025 22:34:14 +0000 (00:34 +0200)
pullback with huge high candle

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 6dada925720490732d71fca35044d9d4199d8a5a..af191a8e8515b295d60233e0ddfe935495f67b48 100644 (file)
@@ -917,22 +917,13 @@ def zigzag(
         if len(next_closes) == 0 or len(previous_closes) == 0:
             return False
 
-        next_slope_ok = True
+        slope_ok = True
         if len(next_closes) >= 2:
             next_slope = np.polyfit(range(len(next_closes)), next_closes, 1)[0]
             if direction == TrendDirection.DOWN:
-                next_slope_ok = next_slope < 0
+                slope_ok = next_slope < 0
             elif direction == TrendDirection.UP:
-                next_slope_ok = next_slope > 0
-        previous_slope_ok = True
-        if len(previous_closes) >= 2:
-            previous_slope = np.polyfit(
-                range(len(previous_closes)), previous_closes, 1
-            )[0]
-            if direction == TrendDirection.DOWN:
-                previous_slope_ok = previous_slope > 0
-            elif direction == TrendDirection.UP:
-                previous_slope_ok = previous_slope < 0
+                slope_ok = next_slope > 0
 
         significant_move_away_ok = False
         if direction == TrendDirection.DOWN:
@@ -956,8 +947,7 @@ def zigzag(
                 and np.all(previous_closes < highs[candidate_pivot_pos])
                 and np.max(next_highs) <= highs[candidate_pivot_pos]
                 and np.max(previous_highs) <= highs[candidate_pivot_pos]
-                and next_slope_ok
-                and previous_slope_ok
+                and slope_ok
                 and significant_move_away_ok
             )
         elif direction == TrendDirection.UP:
@@ -966,8 +956,7 @@ def zigzag(
                 and np.all(previous_closes > lows[candidate_pivot_pos])
                 and np.min(next_lows) >= lows[candidate_pivot_pos]
                 and np.min(previous_lows) >= lows[candidate_pivot_pos]
-                and next_slope_ok
-                and previous_slope_ok
+                and slope_ok
                 and significant_move_away_ok
             )
         return False
index 1ebdfac92255c9ff1c57375dabd7d0cd4d19407e..8ab5cb2267e419376a857e48b534a7b8dba3b1ec 100644 (file)
@@ -411,22 +411,13 @@ def zigzag(
         if len(next_closes) == 0 or len(previous_closes) == 0:
             return False
 
-        next_slope_ok = True
+        slope_ok = True
         if len(next_closes) >= 2:
             next_slope = np.polyfit(range(len(next_closes)), next_closes, 1)[0]
             if direction == TrendDirection.DOWN:
-                next_slope_ok = next_slope < 0
+                slope_ok = next_slope < 0
             elif direction == TrendDirection.UP:
-                next_slope_ok = next_slope > 0
-        previous_slope_ok = True
-        if len(previous_closes) >= 2:
-            previous_slope = np.polyfit(
-                range(len(previous_closes)), previous_closes, 1
-            )[0]
-            if direction == TrendDirection.DOWN:
-                previous_slope_ok = previous_slope > 0
-            elif direction == TrendDirection.UP:
-                previous_slope_ok = previous_slope < 0
+                slope_ok = next_slope > 0
 
         significant_move_away_ok = False
         if direction == TrendDirection.DOWN:
@@ -450,8 +441,7 @@ def zigzag(
                 and np.all(previous_closes < highs[candidate_pivot_pos])
                 and np.max(next_highs) <= highs[candidate_pivot_pos]
                 and np.max(previous_highs) <= highs[candidate_pivot_pos]
-                and next_slope_ok
-                and previous_slope_ok
+                and slope_ok
                 and significant_move_away_ok
             )
         elif direction == TrendDirection.UP:
@@ -460,8 +450,7 @@ def zigzag(
                 and np.all(previous_closes > lows[candidate_pivot_pos])
                 and np.min(next_lows) >= lows[candidate_pivot_pos]
                 and np.min(previous_lows) >= lows[candidate_pivot_pos]
-                and next_slope_ok
-                and previous_slope_ok
+                and slope_ok
                 and significant_move_away_ok
             )
         return False