From: Jérôme Benoit Date: Thu, 8 May 2025 20:59:17 +0000 (+0200) Subject: fix(qav3): filter noisy candles in pivot labeling X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=184e8d630947ab1fb85dd699031c547ec35d29a3;p=freqai-strategies.git fix(qav3): filter noisy candles in pivot labeling Signed-off-by: Jérôme Benoit --- diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index ec6e492..6dada92 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -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 diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 68a5770..1ebdfac 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -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