Skip to content
StatePath
Tool Atlasmarket.zigzag

Tool

Zigzag

market.zigzag

MarketStructure

Inputs

No typed inputs.

Outputs

Event list

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.

Zigzag overview diagramzz.lowzz.highzz.lowzz.highzz.low

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

Percent reversalpercent

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.

Percent reversal diagramzz.lowzz.highzz.lowzz.high

When to use: When you want portable, scale-independent swings — one percent threshold behaves the same on EURUSD and on gold.

MT5 (points)mt5

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.

MT5 (points) diagramzz.lowzz.highzz.lowzz.highzz.low

When to use: When you need pivots that match the MT5 ZigZag indicator exactly for parity with a MetaTrader strategy.

Configuration

modeenum

How the reversal threshold is measured: 'percent' uses a percent of price (threshold_pct); 'mt5' uses MetaTrader's depth / deviation_points / backstep point rules.

Choices:percentmt5
threshold_pctscalar

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.

depthscalar

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.

deviation_pointsscalar

MT5 mode: the minimum reversal in points required to register a new pivot. Ignored in percent mode.

backstepscalar

MT5 mode: the minimum number of bars that must separate two consecutive pivots, preventing pivots from clustering. Ignored in percent mode.

point_valuescalar

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

Feeds into

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.

See also