projects /
pivotstructure
Is this market making higher highs and higher lows? Swing-pivot structure (HH / HL / LH / LL) from any price series.
pivots = detect_pivots(highs, lows, lookback=10)
state = structure_state(pivots)
state.sequence # 'LH-HL-HH-HL'
state.reading # 'a higher low after a higher high: the advance is extending, …'
A moving average lags and whipsaws in a directionless market. A pivot read degrades more honestly: chop produces mixed labels, which is information rather than a false signal.
It works in three stages: mark pivots using a backward-only window, collapse them into a strictly alternating zigzag, then label each pivot against the previous one of its kind. Stdlib only.