From 4b62b2af607a82955f86175a53cef4ee1bab44e3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 9 May 2025 00:34:14 +0200 Subject: [PATCH] fix(qav3): relax slope check at pivot labeling to handle corner case pullback with huge high candle MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../freqaimodels/QuickAdapterRegressorV3.py | 21 +++++-------------- quickadapter/user_data/strategies/Utils.py | 21 +++++-------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index 6dada92..af191a8 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -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 diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 1ebdfac..8ab5cb2 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -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 -- 2.43.0