1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! 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);
//! }
//! ```
pub
pub use ;
pub use ;
pub use SegmentStats;
pub use ZigZagState;
pub use ;
pub use ;
/// Errors from the ZigZag indicator.