zigzag-pattern-classifier
ZigZag swing pattern classification for algorithmic trading. UP-DOWN and UP-DOWN-UP patterns. TRIGGERS - zigzag, swing classification
What this skill does
# ZigZag Swing Pattern Classifier
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.
## When to Use
- Classifying a confirmed L₀→H₁→L₂ (two-pivot) or L₀→H₁→L₂→H₃ (three-pivot) swing
- Looking up market regime implications of a specific pattern
- Answering "how many distinct patterns exist?" and proving exhaustiveness
- Implementing pattern labeling in code (Rust `qta` crate, Python pipelines)
- Understanding the epsilon tolerance band that defines "equal"
- Applying Freedman-Diaconis binning for sub-classification depth
## Notation (Single Source of Truth)
| 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 |
### Price Level Comparisons
| 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₁ − ε |
---
## Part 1: Two-Pivot Patterns (UP-DOWN)
Pattern: **L₀ → H₁ → L₂** (one up-leg, one down-leg)
### Base Classification (3 Classes)
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% |
### Granular Classification: 9 FD-Binned Variants
HL and LL each decompose into 4 sub-classes using Freedman-Diaconis binning on normalized coordinates:
- **HL bins** use z = (L₂ − L₀) / (H₁ − L₀), ranging 0 to 1
- **LL bins** use o = (L₀ − L₂) / ATR₁₄, ranging 0 to ∞
| 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% |
### Trading Implications
| 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 |
### Optional Sub-Classification Flags
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`
---
## Part 2: Three-Pivot Patterns (UP-DOWN-UP)
Pattern: **L₀ → H₁ → L₂ → H₃** (up-leg, down-leg, up-leg)
### 9 Exhaustive Variants
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 |
### Exhaustiveness Proof
All variants satisfy these mandatory constraints:
- L₀ < H₁ (first uptrend exists)
- L₂ < H₁ (retracement doesn't exceed peak)
- H₃ > L₂ (second uptrend exists)
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.
### Natural Groupings
- **Bullish** (4): HL+HH, EL+HH, HL+EH, LL+HH
- **Neutral** (3): HL+LH, EL+EH, LL+EH
- **Bearish** (2): EL+LH, LL+LH
### Regime Assignments
| 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 |
---
## Part 3: 27-Way Extension
Adding **H₃ vs L₀** as a third independent dimension:
- **L₂ vs L₀**: {HL, EL, LL}
- **H₃ vs H₁**: {HH, EH, LH}
- **H₃ vs L₀**: {Above, Equal, Below}
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 Epsilon Tolerance Band
The tolerance band ε determines what "equal" means. It adapts to volatility and microstructure.
### Core Formula
```Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.