]> Piment Noir Git Repositories - freqai-strategies.git/commitdiff
perf(qav3): stricter depth check at pivot labeling
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 4 May 2025 21:24:51 +0000 (23:24 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 4 May 2025 21:24:51 +0000 (23:24 +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 ae39a1b905ff381dab075a2879cda7aef49ec814..ed01c2b8617e04887a799172edd3c5d82e5e91e5 100644 (file)
@@ -870,13 +870,15 @@ def zigzag(
 
     def add_pivot(pos: int, value: float, direction: TrendDirection):
         nonlocal last_pivot_pos
+        if pivots_indices and indices[pos] == pivots_indices[-1]:
+            return
         pivots_indices.append(indices[pos])
         pivots_values.append(value)
         pivots_directions.append(direction)
         last_pivot_pos = pos
 
     def update_last_pivot(pos: int, value: float, direction: TrendDirection):
-        if pivots_indices:
+        if pivots_indices and indices[pos] != pivots_indices[-1]:
             pivots_indices[-1] = indices[pos]
             pivots_values[-1] = value
             pivots_directions[-1] = direction
@@ -901,6 +903,11 @@ def zigzag(
             initial_high, initial_high_pos = highs[i], i
         if lows[i] < initial_low:
             initial_low, initial_low_pos = lows[i], i
+        if (
+            i - initial_high_pos < confirmation_window
+            or i - initial_low_pos < confirmation_window
+        ):
+            continue
 
         initial_move_from_high = (initial_high - lows[i]) / initial_high
         initial_move_from_low = (highs[i] - initial_low) / initial_low
@@ -928,7 +935,7 @@ def zigzag(
                 update_last_pivot(i, current_high, TrendDirection.UP)
             elif (
                 (last_pivot_val - current_low) / last_pivot_val >= thresholds[i]
-                and (i - last_pivot_pos) >= depth
+                and (i - last_pivot_pos) > depth
                 and is_reversal_confirmed(i, TrendDirection.DOWN)
             ):
                 add_pivot(i, current_low, TrendDirection.DOWN)
@@ -938,7 +945,7 @@ def zigzag(
                 update_last_pivot(i, current_low, TrendDirection.DOWN)
             elif (
                 (current_high - last_pivot_val) / last_pivot_val >= thresholds[i]
-                and (i - last_pivot_pos) >= depth
+                and (i - last_pivot_pos) > depth
                 and is_reversal_confirmed(i, TrendDirection.UP)
             ):
                 add_pivot(i, current_high, TrendDirection.UP)
index acef9e7c31531f3c5cbe95fcdb9e10d78cd4ebcb..3111957cd66c05bbf68b8b4b7346a1ce50239e7b 100644 (file)
@@ -359,13 +359,15 @@ def zigzag(
 
     def add_pivot(pos: int, value: float, direction: TrendDirection):
         nonlocal last_pivot_pos
+        if pivots_indices and indices[pos] == pivots_indices[-1]:
+            return
         pivots_indices.append(indices[pos])
         pivots_values.append(value)
         pivots_directions.append(direction)
         last_pivot_pos = pos
 
     def update_last_pivot(pos: int, value: float, direction: TrendDirection):
-        if pivots_indices:
+        if pivots_indices and indices[pos] != pivots_indices[-1]:
             pivots_indices[-1] = indices[pos]
             pivots_values[-1] = value
             pivots_directions[-1] = direction
@@ -390,6 +392,11 @@ def zigzag(
             initial_high, initial_high_pos = highs[i], i
         if lows[i] < initial_low:
             initial_low, initial_low_pos = lows[i], i
+        if (
+            i - initial_high_pos < confirmation_window
+            or i - initial_low_pos < confirmation_window
+        ):
+            continue
 
         initial_move_from_high = (initial_high - lows[i]) / initial_high
         initial_move_from_low = (highs[i] - initial_low) / initial_low
@@ -417,7 +424,7 @@ def zigzag(
                 update_last_pivot(i, current_high, TrendDirection.UP)
             elif (
                 (last_pivot_val - current_low) / last_pivot_val >= thresholds[i]
-                and (i - last_pivot_pos) >= depth
+                and (i - last_pivot_pos) > depth
                 and is_reversal_confirmed(i, TrendDirection.DOWN)
             ):
                 add_pivot(i, current_low, TrendDirection.DOWN)
@@ -427,7 +434,7 @@ def zigzag(
                 update_last_pivot(i, current_low, TrendDirection.DOWN)
             elif (
                 (current_high - last_pivot_val) / last_pivot_val >= thresholds[i]
-                and (i - last_pivot_pos) >= depth
+                and (i - last_pivot_pos) > depth
                 and is_reversal_confirmed(i, TrendDirection.UP)
             ):
                 add_pivot(i, current_high, TrendDirection.UP)