AB=CD Harmonic Pattern Indicator: Equal Legs Within Tolerance

Written by Dominic Walsh · Published · Last updated

AB=CD is the simplest harmonic pattern and the foundation of most others. Two price legs of roughly equal length, separated by a retracement. The ab=cd harmonic pattern indicator finds the pivots, measures the two legs, and marks the bar where CD finishes close enough to AB to count.

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

Platforms MT4 (.ex4) + MT5 (.ex5)
Chart window Main price chart
Plots 3: Pattern, Buy, Sell
Alerts popup, push notification, email, sound
Inputs 9

What the AB=CD Harmonic Pattern Indicator renders

Pattern joins the four pivots with a dodger blue zigzag so you can see the shape it matched.

Buy places a wide lime arrow when the pattern completes at a low.

Sell places a wide red arrow when it completes at a high.

Both arrows draw at width 4, which keeps them visible against the pattern line.

  • Pattern: zigzag, dodger blue, width 2
  • Buy: arrow, lime, width 4, arrow code 233
  • Sell: arrow, red, width 4, arrow code 234
AB=CD harmonic pattern indicator on EURUSD H4 with matched legs and completion arrows
AB=CD harmonic pattern indicator on EURUSD H4 with matched legs and completion arrows

Behind the plots

Finding the pivots

IsFractalHigh and IsFractalLow scan for turning points using `Depth` as the half-window. Each confirmed pivot records px, taken from high[i] on a high or low[i] on a low, along with whether it was a high. The tool keeps the last four, which is exactly what an AB=CD needs.

Measuring the two legs

ab takes MathAbs(pP[3] – pP[2]) and cd takes MathAbs(pP[1] – pP[0]). Using absolute distances means the same comparison works whether the pattern is rising or falling. Nothing about direction enters this step, only length.

Applying the tolerance

valid requires ab above zero and MathAbs(cd – ab) / ab at or below `Tolerance`. Expressing the difference as a fraction of AB rather than in pips is what lets one setting work across instruments. The completion pivot then decides direction: a finish at a low writes BuyArrow, a finish at a high writes SellArrow, each `ArrowOffsetPoints` clear of the candle.

Making it useful

The zigzag shows the exact four pivots the tool matched, which is worth checking before acting on an arrow.

Direction comes from where CD ended, not from the shape of the legs.

A tight tolerance produces textbook patterns and very few of them.

Completion happens at the fourth pivot, so the arrow arrives once that pivot confirms.

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

Four channels sit under `EnableAlerts`: a popup dialog, a mobile push notification, SMTP email configured in Tools then Options, and a sound file from the MT4 Sounds folder. Popup starts on and the other three start off, with `SoundFile` naming the clip. One message goes out per closed bar.

Every AB=CD Harmonic Pattern Indicator input

Core settings

Setting What it does Default
Depth Half-window for the fractal pivot scan, default `5`. Larger values give fewer, cleaner pivots and coarser patterns. 5
Tolerance How far CD may differ from AB, as a fraction, default `0.2`. That allows a 20% mismatch. Tighten it to 0.1 for stricter patterns. 0.2

Display settings

Setting What it does Default
ArrowOffsetPoints Distance between candle and arrow, default `45` points, set wide because the arrows draw at width 4. 45

Alert settings

Setting What it does Default
EnableAlerts master toggle. on
EnablePopup MT4 popup dialog. on
EnablePushNotify mobile MT4 push notification. off
EnableEmail SMTP email (Tools > Options > Email). off
EnableSound play sound file from MT4/Sounds/. off
SoundFile (see inputs panel) alert.wav
AB=CD harmonic pattern indicator inputs showing Depth, Tolerance and alert switches
AB=CD harmonic pattern indicator inputs showing Depth, Tolerance and alert switches

Which markets and timeframes suit it

Harmonic work needs legs that are clearly separated, which is why the screenshot note for this build calls for EURUSD on H4. That timeframe gives well-spaced pivots and patterns that take days rather than minutes to form. On M15 a depth of 5 finds pivots constantly and most matched patterns are too small to trade. The daily chart works well if you are patient.

What this one cannot tell you

A 0.2 tolerance is generous. Two legs differing by a fifth still qualify, and some of those will not look like an AB=CD to the eye.

The tool measures length alone. It never checks the retracement ratio between the legs, which most harmonic traders treat as part of the definition.

Fractal pivots confirm late, so the tool names a pattern after its completion rather than as one approaches.

Copy the compiled AB=CD Harmonic Pattern 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.

Background reading on the method behind the AB=CD Harmonic Pattern Indicator: Support And Resistance at StockCharts ChartSchool, Support at Investopedia.

Download the AB=CD Harmonic Pattern Indicator for MT4 and MT5

The zip holds the compiled AB=CD Harmonic Pattern 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

What does Tolerance at 0.2 permit?

A 20% difference between the two legs. The code computes MathAbs(cd – ab) divided by ab and accepts anything at or below the setting. Expressing it as a fraction rather than pips is what makes one value work on EURUSD and gold alike. Tighten it to 0.1 if the matched patterns look too loose.

How does Depth change the patterns found?

It sets the half-window for the fractal scan, default `5`. A larger depth means a pivot must stand out across more bars, so you get fewer pivots and the AB=CD legs span more of the chart. A smaller depth finds micro-patterns that are usually noise on anything below H1.

Why does the Buy arrow depend on where CD ends?

Because the completion pivot is the trade point. If the fourth pivot is a low, the pattern finished with a downward CD leg and the setup reads bullish, so BuyArrow prints. A finish at a high gives the mirror case. The leg lengths decide whether a pattern exists; the completion decides its direction.

Does the Pattern zigzag repaint?

Pivots come from a fractal test needing bars on both sides, so a confirmed pivot does not move. Its connecting line can still extend as new pivots confirm, which every zigzag does. Arrows print on completion and stay put.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the AB=CD Harmonic Pattern Indicator as one input. Always backtest before trading live.

Category: this is part of our Support and Resistance collection. Next, browse more Support and Resistance 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