pub fn zigzag(
highs: &[f64],
lows: &[f64],
deviation_pct: f64,
) -> Result<Vec<ZigZagPoint>>Expand description
Calculate ZigZag swing points from high/low series using a percentage reversal threshold.
Starting from the first bar, price must move by at least deviation_pct
(e.g. 5.0 for 5%) away from the running extreme before a reversal is
confirmed and a pivot recorded. Consecutive pivots always alternate
between highs and lows. The final unconfirmed extreme (the most recent
swing-in-progress) is included as the last point.
§Arguments
highs- High priceslows- Low pricesdeviation_pct- Minimum reversal size as a percentage (e.g.5.0= 5%)
§Example
use finance_query::indicators::zigzag;
let highs = vec![100.0, 110.0, 90.0, 120.0, 80.0];
let lows = vec![100.0, 110.0, 90.0, 120.0, 80.0];
let pivots = zigzag(&highs, &lows, 5.0).unwrap();
assert_eq!(pivots.len(), 4);
assert!(pivots[0].is_high);
assert!(!pivots[1].is_high);