Tool
Zigzag
market.zigzag
Inputs
No typed inputs.
Outputs
A list of confirmed swing pivots (alternating highs and lows with their bar and price), the building blocks for legs, retracements, patterns, and market-structure tools downstream.
Zigzag strips out the small noise and connects only the meaningful swing highs and lows with straight legs, so you can see the market's underlying up/down structure at a glance.
How it works
It walks the bars tracking the running extreme and only commits a new pivot once price reverses by more than a chosen threshold, then draws a leg to it. The mode setting picks how that reversal threshold is measured — a percentage of price, or MetaTrader's depth/deviation/backstep point rules.
Modes
A new pivot is confirmed when price reverses by at least threshold_pct percent from the last extreme, so the same setting scales naturally across symbols of any price.
When to use: When you want portable, scale-independent swings — one percent threshold behaves the same on EURUSD and on gold.
Reproduces MetaTrader's built-in ZigZag: a swing is set by depth (min bars), deviation_points (min reversal in points), and backstep (min bars between pivots), measured in raw points not percent.
When to use: When you need pivots that match the MT5 ZigZag indicator exactly for parity with a MetaTrader strategy.
Configuration
How the reversal threshold is measured: 'percent' uses a percent of price (threshold_pct); 'mt5' uses MetaTrader's depth / deviation_points / backstep point rules.
In percent mode, the minimum reversal (as a percent of price) needed to confirm a new pivot; larger values draw fewer, bigger swings. Ignored in MT5 mode.
MT5 mode: the minimum number of bars a swing must span before a new pivot can form, filtering out short-lived wiggles. Ignored in percent mode.
MT5 mode: the minimum reversal in points required to register a new pivot. Ignored in percent mode.
MT5 mode: the minimum number of bars that must separate two consecutive pivots, preventing pivots from clustering. Ignored in percent mode.
The price size of one point for this symbol, used to convert the MT5 point settings into an actual price distance (e.g. 0.0001 for a 5-digit FX pair).
Connects to
Examples
- Feed the pivots into market.fibonacci_anchor to auto-draw retracement levels on the latest leg.
- Use mode 'mt5' with matching depth/deviation/backstep to mirror a MetaTrader ZigZag-based strategy.
Common mistakes
- Reading the most recent leg as fixed — the last pivot can repaint until price has reversed far enough to confirm it.
- Setting threshold_pct too small so the zigzag chases noise and produces far too many tiny legs.