Expand description
Streaming ZigZag indicator for swing structure detection on open deviation bars.
Identifies swing highs and swing lows — the foundation for trend classification, pattern recognition, and regime labeling in algorithmic trading.
§Key Properties
- No repainting: Once confirmed, pivots never change price or index.
- Streaming: Processes one bar at a time with O(1) state.
- Range-bar native: Threshold τ = N × δ scales naturally with bar width.
- Classification: Automatic EL/HL/LL base class assignment per segment.
§Quick Start
use qta::zigzag::{ZigZagConfig, ZigZagState, BarInput};
let config = ZigZagConfig::new(3.0, 1.0, 250).unwrap();
let mut state = ZigZagState::new(config);
let bar = BarInput {
index: 0, timestamp_us: 1_000_000,
high: 5_012_500_000_000, low: 5_000_000_000_000,
close: 5_006_000_000_000, duration_us: Some(60_000_000),
};
let output = state.process_bar(&bar);
if let Some(pivot) = output.newly_confirmed {
println!("Confirmed {} at price {}", pivot.kind, pivot.price);
}
if let Some(segment) = &output.completed_segment {
println!("Segment: {} (z={:.3})", segment.base_class, segment.z);
}Re-exports§
pub use config::ThresholdMode;pub use config::ZigZagConfig;pub use ctrends::CTrendsConfig;pub use ctrends::filter_ctrends;pub use ctrends::is_noise_counter_move;pub use segment::SegmentStats;pub use state::ZigZagState;pub use types::BarInput;pub use types::BaseClass;pub use types::ConfirmationStatus;pub use types::Pivot;pub use types::PivotKind;pub use types::Segment;pub use types::ZigZagOutput;
Modules§
- base_
class - Base class classification for L₀-H₁-L₂ segments.
- config
- ZigZag configuration and threshold computation.
- ctrends
- CTrends noise filter — merges short counter-trend moves.
- segment
- Segment statistics for tracking swing structure over time.
- state
- ZigZag state machine — the core streaming pivot detection engine.
- types
- Core types for the ZigZag indicator.
Enums§
- ZigZag
Error - Errors from the ZigZag indicator.