Classifies ZigZag swing patterns (UP-DOWN and UP-DOWN-UP) for algorithmic trading, mapping every confirmed sequence to a distinct variant with market regime implications.
Ships in quant-research. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Complete taxonomy for classifying ZigZag swing patterns by structure and market regime. Every confirmed ZigZag sequence maps to exactly one variant — no gaps, no overlaps.
Self-Evolving Skill: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.
qta crate, Python pipelines)| Symbol | Definition | Example |
|---|---|---|
| L₀ | Initial low (first confirmed pivot) | 1.0800 |
| H₁ | Swing high (reversal peak) | 1.0850 |
| L₂ | Second low (retracement) | 1.0810 |
| H₃ | Second high (three-pivot only) | 1.0870 |
| W | Swing magnitude: H₁ − L₀ | 0.0050 |
| z | Normalized retracement: (L₂ − L₀) / (H₁ − L₀) | 0.20 |
| o | Volatility-normalized overshoot: (L₀ − L₂) / ATR₁₄ | 0.35 |
| ε | Tolerance band for "equal" classification | 5 pips |
| τ | ZigZag reversal threshold | 6.6 pips |
| Code | Meaning | Condition |
|---|---|---|
| HL | Higher Low | L₂ > L₀ + ε |
| EL | Equal Low | |L₂ − L₀| ≤ ε |
| LL | Lower Low | L₂ < L₀ − ε |
| HH | Higher High | H₃ > H₁ + ε |
| EH | Equal High | |H₃ − H₁| ≤ ε |
| LH | Lower High | H₃ < H₁ − ε |
Pattern: L₀ → H₁ → L₂ (one up-leg, one down-leg)
Every UP-DOWN triplet falls into exactly one:
| Class | Condition | Meaning | Frequency |
|---|---|---|---|
| EL | |L₂ − L₀| ≤ ε | Equal Low (retest) | ~20–30% |
| HL | L₂ > L₀ + ε | Higher Low (pullback) | ~50–60% |
| LL | L₂ < L₀ − ε | Lower Low (undercut) | ~10–20% |
HL and LL each decompose into 4 sub-classes using Freedman-Diaconis binning on normalized coordinates:
| Variant | z or o Range | Market Regime | Probability |
|---|---|---|---|
| EL | |z| ≤ ε_r | Retest — support re-established | 20–30% |
| HL-FD1 | 0.75 < z < 1.0 | Shallow pullback — buyers in control | 20–25% |
| HL-FD2 | 0.50 < z ≤ 0.75 | Moderate pullback — Fib 38–50% | 15–20% |
| HL-FD3 | 0.25 < z ≤ 0.50 | Deep pullback — Fib 61.8% | 10–15% |
| HL-FD4 | 0 < z ≤ 0.25 | Near-complete retrace — barely held | 5–10% |
| LL-FD1 | o ≤ q₂₀ | Micro undercut — brief false break | 8–12% |
| LL-FD2 | q₂₀ < o ≤ q₄₀ | Shallow undercut — moderate panic | 4–8% |
| LL-FD3 | q₄₀ < o ≤ q₆₀ | Deep undercut — structural break | 2–5% |
| LL-FD4 | o > q₆₀ | Extreme undercut — tail event | <2% |
| Variant | Entry Signal | Stop Loss | Target |
|---|---|---|---|
| EL | Long from L₀+ε | L₀−ε | H₁ + ΔH |
| HL-FD1 | Long from L₂ | L₂−ε | H₁ + ΔH |
| HL-FD2 | Long at confirmation | L₂−ε | Prior H + ΔH |
| HL-FD3 | Reduced size; wait | L₂−ε | Support + ΔH |
| HL-FD4 | Extreme risk; avoid | L₂−ε | Critical |
| LL-FD1 | Short spike trade | L₂+spike | L₀ |
| LL-FD2 | Wait for reversal | Breakout | L₀ |
| LL-FD3 | Short continuation | Reversal | New lows |
| LL-FD4 | Crisis mode; hedge | Capitulation | TBD |
Attach to any variant for richer context:
| Flag | Meaning | Signal |
|---|---|---|
| +C | Any close < L₀ between H₁→L₂ | Stronger bearish commitment |
| +S | L₂ occurs in single bar (spike) | Sharp reversal; mean reversion |
| +X | Wicks below L₀ only, no close | Liquidity grab; false break |
Example labels: HL-FD2+C, LL-FD4+S+C, EL+X
Pattern: L₀ → H₁ → L₂ → H₃ (up-leg, down-leg, up-leg)
Two independent dimensions × 3 values each = 3×3 = 9 mutually exclusive, collectively exhaustive variants.
Dimension 1 — L₂ vs L₀: {HL, EL, LL} Dimension 2 — H₃ vs H₁: {HH, EH, LH}
| # | L₂ vs L₀ | H₃ vs H₁ | Name | Market Regime |
|---|---|---|---|---|
| 1 | HL | HH | Continuation impulse | Bull trend continuation |
| 2 | HL | EH | Double-top test | Range, bullish bias |
| 3 | HL | LH | Triangle compression | Neutral consolidation |
| 4 | EL | HH | Range break up | Bullish transition |
| 5 | EL | EH | Rectangle | Balanced range |
| 6 | EL | LH | Lower-high at flat base | Range, bearish bias |
| 7 | LL | HH | V-reversal / spring | Bullish reversal |
| 8 | LL | EH | Undercut then stall | Volatile range |
| 9 | LL | LH | Rally failure | Bear trend continuation |
All variants satisfy these mandatory constraints:
L₂ has exactly 3 relationships to L₀ (higher, equal, lower). H₃ has exactly 3 relationships to H₁ (higher, equal, lower). These dimensions are independent — no constraint eliminates any combination. Therefore 3 × 3 = 9 variants, all feasible, none missing.
| Regime | Variants |
|---|---|
| Trend Continuation | HL+HH (bull), LL+LH (bear) |
| Range Consolidation | HL+LH, EL+EH, LL+EH |
| Bullish Transition | EL+HH, HL+EH |
| Bearish Transition | EL+LH |
| Reversal | LL+HH |
Adding H₃ vs L₀ as a third independent dimension:
This yields 3×3×3 = 27 sub-variants. Some are mathematically impossible due to constraints (e.g., HL+LH+H₃<L₀ requires H₃ < L₀ < L₂ < H₃, a contradiction).
Analysts often simplify this third dimension to a binary: "reclaims L₀" vs "fails to reclaim L₀".
The tolerance band ε determines what "equal" means. It adapts to volatility and microstructure.
ε = min(ε_max, max(ε_min, √[(a·S)² + (b·ATR₁₄)²]))
Where:
ε_min = max(3 ticks, 1×S) = max(0.00003, S)
ε_max = min(5 pips, 0.20 × swing) = min(0.00050, 0.20 × W)
ε_r = ε / W (relative tolerance)
EL if |z| ≤ ε_r
HL if z > ε_r
LL if z < −ε_r
If bid-ask spread unavailable:
For complete worked examples with sensitivity analysis, read references/epsilon-tolerance-detail.md.
The FD rule computes statistically optimal bin edges from data:
h = 2 × IQR(X) × n^(-1/3) (bin width)
K = clip(⌈(max−min) / h⌉, 3, 6) (number of bins)
edges = linspace(min, max, K+1)
Recompute bin edges monthly or quarterly to track regime drift. Fall back to quantile binning if sample < 400.
The qta Rust crate (crates/qta/) implements the core ZigZag state machine that produces the pivots consumed by this classification framework:
ZigZagConfig::new(reversal_depth, epsilon_multiplier, bar_threshold_dbps)ZigZagState::process_bar(&bar) → ZigZagOutput with completed_segment containing base_class (EL/HL/LL) and z scorebar_threshold_dbpsThe classification framework in this skill extends the crate's output with FD-binning, three-pivot analysis, and market regime labeling.
For ASCII visualizations, worked examples, and implementation pseudocode, read these reference files as needed:
| File | Contents |
|---|---|
references/notation-definitions.md | Single source of truth: all symbols, formulas, abbreviations, pattern classes |
references/two-pivot-variants.md | All 9 two-pivot ASCII diagrams, trading rules, flag examples |
references/three-pivot-variants.md | All 9 three-pivot ASCII diagrams, 27-way extension, HL+LH granular sub-variants |
references/epsilon-tolerance-detail.md | Complete ε formula, worked calculation, sensitivity analysis, pseudocode |
references/binning-methodology.md | Freedman-Diaconis algorithm details, FD vs quantile comparison, worked example |
references/data-pipeline.md | 11-step end-to-end pipeline: raw quotes → OHLC → ATR → pivots → classify → output |
references/eurusd-validation-scenarios.md | 3 worked market scenarios (Normal, Volatile, Crash) validating ε and τ |
After this skill completes, check before closing:
Only update if the issue is real and reproducible — not speculative.
references/binning-methodology.md (opens in a new tab)references/data-pipeline.md (opens in a new tab)references/epsilon-tolerance-detail.md (opens in a new tab)references/eurusd-validation-scenarios.md (opens in a new tab)references/notation-definitions.md (opens in a new tab)references/three-pivot-variants.md (opens in a new tab)references/two-pivot-variants.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
8 skills in this plugin
/adaptive-wfo-epochAdaptive epoch selection for Walk-Forward Optimization. TRIGGERS - WFO epoch, epoch selection, WFE optimization, overfitting epochs./backtesting-py-oraclebacktesting.py configuration for SQL oracle validation and range bar pattern backtesting. Use when running backtesting.py against./evolutionary-metric-rankingMulti-objective evolutionary optimization for per-metric percentile cutoffs and intersection-based config selection./exchange-session-detectorDST-aware exchange session detection using exchange_calendars. Holiday & lunch break handling. TRIGGERS - exchange session, trading hours/odb-microstructure-forensicsInvestigate why ODB bars are oversized, have zero duration, or show anomalous price ranges by forensically analyzing Parquet./opendeviation-eval-metricsevaluating open deviation bar signal quality, computing Sharpe ratios with non-IID bars, running PSR/MinTRL statistical tests, or assessing ODB strategy performance./quant-research:zigzag-pattern-classifierfrom quant-research
npx claudepluginhub terrylica/cc-skills --plugin quant-researchOther plugins' skills for the same job