From: Jérôme Benoit Date: Thu, 8 May 2025 22:34:14 +0000 (+0200) Subject: fix(qav3): relax slope check at pivot labeling to handle corner case X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4b62b2af607a82955f86175a53cef4ee1bab44e3;p=freqai-strategies.git fix(qav3): relax slope check at pivot labeling to handle corner case pullback with huge high candle Signed-off-by: Jérôme Benoit --- 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