ZigZag Trend Line Indicator for MT4 and MT5

Written by Dominic Walsh · Published · Last updated

The zigzag trend line indicator draws the lines you would draw by hand. Two pivot highs make a descending ray. Two pivot lows make an ascending one. When a close pushes through either, an arrow marks it. Every step is a rule rather than a judgement call.

This build ships as a compiled .ex4 for MT4 and .ex5 for MT5; the screenshots below come from EURUSD H1.

Platforms MT4 (.ex4) + MT5 (.ex5)
Chart window Main price chart
Plots 2: TrendLine Break BUY, TrendLine Break SELL
Alerts popup, push notification, email, sound
Inputs 16

The plots this build puts on screen

Two arrow plots plus chart objects.

`TrendLine Break BUY` uses arrow 233 in lime.

`TrendLine Break SELL` uses arrow 234 in red.

`ResistanceColor` draws the descending ray deep pink.

`SupportColor` draws the ascending ray spring green.

`ShowPivotLabels` marks each pivot with a tag.

  • TrendLine Break BUY: arrow, lime, width 2, arrow code 233
  • TrendLine Break SELL: arrow, red, width 2, arrow code 234
zigzag trend line indicator: Pivot rays and a break arrow on the EURUSD H1 chart.
Pivot rays and a break arrow on the EURUSD H1 chart.

How it builds its numbers

Finding a pivot

It is a fractal test. `Depth` `12` bars either side must stay under a high, or over a low, for that bar to count. Twelve is a wide window, so pivots are few.

Two filters

Not every pivot qualifies. `MinSwingPoints` `120` demands real distance from the opposite pivot. `MinPivotGap` `5` stops two of the same type sitting side by side.

Drawing and breaking

Two pivots make a ray. It runs forward until a close clears it by `MinBreakPoints` `0` points. `MinBarsBetweenSig` `5` then holds off the next same-side mark.

Interpreting what you see

Each ray needs two confirmed pivots behind it.

A break is a close through the line, not a touch.

The pink ray falls and the green one rises.

Pivot labels let you check which two made a line.

Wide `Depth` means fewer, larger structures.

`ArrowOffsetPoints` `40` lifts marks clear of the bar.

Alert channels in this build: popup, push notification, email and sound, one message per closed bar.

`EnableAlerts` sits over the break alerts and ships true with `EnablePopup`. Set `EnablePushNotify` for a phone, `EnableEmail` for mail, or `EnableSound` to sound `SoundFile`. Those three arrive off, and breaks report once a bar.

Every Zigzag trend line Indicator input

Core settings

Setting What it does Default
Depth Fractal half-window for swing detection. Bars each side of a pivot, `12`. 12
MinSwingPoints Minimum swing amplitude vs opposite pivot (points). Distance from the opposite pivot, `120`. 120
MinPivotGap Minimum bars between two same-type pivots. Bars between same-type pivots, `5`. 5
MinBreakPoints Extra distance beyond the line to confirm (points). Extra distance past the ray, `0`. 0
MinBarsBetweenSig Cooldown bars between same-side signals. Quiet bars after a mark, `5`. 5

Display settings

Setting What it does Default
ResistanceColor Descending resistance ray colour. Falling ray colour, `clrDeepPink`. deep pink
SupportColor Ascending support ray colour. Rising ray colour, `clrSpringGreen`. spring green
LineWidth Trend line width. Ray thickness, `2`. 2
ShowPivotLabels Show H1/H2/L1/L2 pivot markers. Tag each pivot, `true`. on
ArrowOffsetPoints Arrow offset from bar high/low (points). Points from mark to bar, `40`. 40

Alert settings

Setting What it does Default
EnableAlerts (see inputs panel) on
EnablePopup (see inputs panel) on
EnablePushNotify (see inputs panel) off
EnableEmail (see inputs panel) off
EnableSound (see inputs panel) off
SoundFile (see inputs panel) alert.wav
zigzag trend line indicator: Inputs panel with Depth, MinSwingPoints and MinBreakPoints.
Inputs panel with Depth, MinSwingPoints and MinBreakPoints.

Which chart to load it on

A twelve-bar half-window needs a chart where swings last. EURUSD H1 is the reference chart. A ray there spans a day or two. On M5 the pivots are noise. On H4 each line covers a fortnight of trade.

Where it comes unstuck

A pivot needs twelve bars after it, so lines appear late.

The newest leg can still move until those bars close.

A zero break distance lets a marginal close count.

Rays drawn as objects stay behind after a chart change.

Copy the compiled Zigzag trend line Indicator file into your MQL4/Indicators folder, and the MT5 build into MQL5/Indicators, then restart the terminal and drag it onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.

Download the Zigzag trend line Indicator for MT4 and MT5

The zip holds the compiled Zigzag trend line Indicator build for MT4 and MT5, plus a short README. Compiled files only, no source. Enter your email below and the download link arrives in your inbox.

Download this indicator free

Enter your email and the file is yours. You also get the full MT4 and MT5 library.

  • 1,380+ indicators
  • MT4 and MT5 files
  • No spam, unsubscribe any time

FAQ

Why does Depth 12 make lines appear late?

Because a pivot is only confirmed once twelve bars have printed on both sides of it. The high itself is where it always was, but the ray cannot be drawn until that right-hand window has closed.

What does MinSwingPoints 120 reject?

Pivots too close to the opposite one. A hundred and twenty points is twelve pips on a five-digit major, so a small wobble inside a range never becomes an anchor for a trend line.

Should MinBreakPoints stay at 0?

It depends on the symbol. Zero means any close past the ray counts, including one that clears it by a fraction of spread. Adding twenty or thirty points asks for a break with something behind it.

What do the ShowPivotLabels tags mark?

The two highs or two lows that a ray was drawn through. They let you check the structure rather than assume it, which matters when a line looks wrong against the chart.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Zigzag trend line Indicator as one input. Always backtest before trading live.

Category: this is part of our Trend collection. Browse more Trend for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.

External references

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment