df: pd.DataFrame,
natr_period: int = 14,
natr_ratio: float = 1.0,
- confirmation_window: int = 2,
+ confirmation_window: int = 3,
depth: int = 12,
) -> tuple[list[int], list[float], list[int]]:
n = len(df)
elif direction == TrendDirection.UP:
previous_slope_ok = previous_slope < 0
- previous_timing_ok = True
- if direction == TrendDirection.DOWN:
- if len(previous_highs) >= 1:
- previous_timing_ok = (
- highs[previous_slice].argmax() >= (len(previous_highs) - 1) // 2
- )
- elif direction == TrendDirection.UP:
- if len(previous_lows) >= 1:
- previous_timing_ok = (
- lows[previous_slice].argmin() <= (len(previous_lows) - 1) // 2
- )
-
- next_timing_ok = True
- if direction == TrendDirection.DOWN:
- if len(next_lows) >= 1:
- next_timing_ok = lows[next_slice].argmin() >= (len(next_lows) - 1) // 2
-
- elif direction == TrendDirection.UP:
- if len(next_highs) >= 1:
- next_timing_ok = (
- highs[next_slice].argmax() >= (len(next_highs) - 1) // 2
- )
-
if direction == TrendDirection.DOWN:
return (
np.all(next_closes < highs[pos])
and np.all(previous_closes < highs[pos])
and np.max(next_highs) <= highs[pos]
and np.max(previous_highs) <= highs[pos]
- and next_timing_ok
- and previous_timing_ok
and next_slope_ok
and previous_slope_ok
)
and np.all(previous_closes > lows[pos])
and np.min(next_lows) >= lows[pos]
and np.min(previous_lows) >= lows[pos]
- and next_timing_ok
- and previous_timing_ok
and next_slope_ok
and previous_slope_ok
)
df: pd.DataFrame,
natr_period: int = 14,
natr_ratio: float = 1.0,
- confirmation_window: int = 2,
+ confirmation_window: int = 3,
depth: int = 12,
) -> tuple[list[int], list[float], list[int]]:
n = len(df)
elif direction == TrendDirection.UP:
previous_slope_ok = previous_slope < 0
- previous_timing_ok = True
- if direction == TrendDirection.DOWN:
- if len(previous_highs) >= 1:
- previous_timing_ok = (
- highs[previous_slice].argmax() >= (len(previous_highs) - 1) // 2
- )
- elif direction == TrendDirection.UP:
- if len(previous_lows) >= 1:
- previous_timing_ok = (
- lows[previous_slice].argmin() <= (len(previous_lows) - 1) // 2
- )
-
- next_timing_ok = True
- if direction == TrendDirection.DOWN:
- if len(next_lows) >= 1:
- next_timing_ok = lows[next_slice].argmin() >= (len(next_lows) - 1) // 2
-
- elif direction == TrendDirection.UP:
- if len(next_highs) >= 1:
- next_timing_ok = (
- highs[next_slice].argmax() >= (len(next_highs) - 1) // 2
- )
-
if direction == TrendDirection.DOWN:
return (
np.all(next_closes < highs[pos])
and np.all(previous_closes < highs[pos])
and np.max(next_highs) <= highs[pos]
and np.max(previous_highs) <= highs[pos]
- and next_timing_ok
- and previous_timing_ok
and next_slope_ok
and previous_slope_ok
)
and np.all(previous_closes > lows[pos])
and np.min(next_lows) >= lows[pos]
and np.min(previous_lows) >= lows[pos]
- and next_timing_ok
- and previous_timing_ok
and next_slope_ok
and previous_slope_ok
)