From: Jérôme Benoit Date: Sat, 26 Apr 2025 21:48:55 +0000 (+0200) Subject: refactor(qav3): cleanup zigzag() X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=cb4da0c950dbc0dc587c6d01993ff5e79e4efc66;p=freqai-strategies.git refactor(qav3): cleanup zigzag() Signed-off-by: Jérôme Benoit --- diff --git a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py index d13441c..f3b1c2e 100644 --- a/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py +++ b/quickadapter/user_data/freqaimodels/QuickAdapterRegressorV3.py @@ -898,20 +898,21 @@ def zigzag( return [], [], [] for i in range(i + 1, len(df)): + last_pivot_val = pivots_values[-1] if state == 1: - if highs[i] > pivots_values[-1]: + if highs[i] > last_pivot_val: update_last_pivot(i, highs[i], 1) - elif (pivots_values[-1] - lows[i]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (last_pivot_val - lows[i]) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, lows[i], -1) state = -1 elif state == -1: - if lows[i] < pivots_values[-1]: + if lows[i] < last_pivot_val: update_last_pivot(i, lows[i], -1) - elif (highs[i] - pivots_values[-1]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (highs[i] - last_pivot_val) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, highs[i], 1) state = 1 diff --git a/quickadapter/user_data/strategies/Utils.py b/quickadapter/user_data/strategies/Utils.py index 3d44ae9..7d13607 100644 --- a/quickadapter/user_data/strategies/Utils.py +++ b/quickadapter/user_data/strategies/Utils.py @@ -353,20 +353,21 @@ def zigzag( return [], [], [] for i in range(i + 1, len(df)): + last_pivot_val = pivots_values[-1] if state == 1: - if highs[i] > pivots_values[-1]: + if highs[i] > last_pivot_val: update_last_pivot(i, highs[i], 1) - elif (pivots_values[-1] - lows[i]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (last_pivot_val - lows[i]) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, lows[i], -1) state = -1 elif state == -1: - if lows[i] < pivots_values[-1]: + if lows[i] < last_pivot_val: update_last_pivot(i, lows[i], -1) - elif (highs[i] - pivots_values[-1]) / pivots_values[-1] >= thresholds[ - i - ] and (i - last_pivot_pos) >= depth: + elif (highs[i] - last_pivot_val) / last_pivot_val >= thresholds[i] and ( + i - last_pivot_pos + ) >= depth: add_pivot(i, highs[i], 1) state = 1