Basic Harmonic Pattern Indicator: Four Legs, Three Ratio Tests

Written by Dominic Walsh · Published · Last updated

A full harmonic pattern has five points and four legs, and what makes it a pattern rather than a squiggle is the ratios between those legs. The basic harmonic pattern indicator checks three of them against bands you can set. Only when all three land inside their range does it mark the completion point.

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: XABCD, Buy, Sell
Alerts popup, push notification, email, sound
Inputs 16

What the Basic Harmonic Pattern Indicator draws on the chart

XABCD joins the five pivots with a teal zigzag, showing the shape that matched.

Buy places a wide lime arrow when point D completes at a swing low.

Sell places a wide red arrow when D completes at a swing high.

Text objects label the pattern on the chart beside its completion.

  • XABCD: zigzag, teal, width 2
  • Buy: arrow, lime, width 4, arrow code 233
  • Sell: arrow, red, width 4, arrow code 234
Basic harmonic pattern indicator on EURUSD H4 with the XABCD zigzag and completion arrows
Basic harmonic pattern indicator on EURUSD H4 with the XABCD zigzag and completion arrows

How the Basic Harmonic Pattern Indicator calculates its values

Collecting the pivots

IsFractalHigh and IsFractalLow scan with `Depth` as the half-window, defaulting to `7`. Each pivot stores px, taken from high[i] or low[i], and whether it was a high. `MaxPivots` caps the stored list at `40`, which is enough history for the pattern search without carrying the whole chart.

Measuring four legs

Working back from the newest pivot the code takes XA, AB, BC and CD as absolute distances between consecutive stored prices. Using MathAbs throughout means the same arithmetic covers bullish and bearish patterns, since only the lengths matter at this stage.

Testing three ratios

ab becomes AB / XA, bc becomes BC / AB and cd becomes CD / BC. Each must fall inside its own band widened by `RatioTol`: ab between `AbLo` and `AbHi`, and so on for the other two. Failing any one test discards the candidate. bullish then reads the completion pivot, and a D at a swing low writes BuyArrow while a D at a high writes SellArrow.

How to read the signals

The zigzag shows exactly which five pivots matched, which is worth checking before acting on an arrow.

Direction comes from where point D landed, not from the shape of the legs.

All three ratio tests must pass together, so widening one band alone rarely changes the count much.

The default bands describe one particular harmonic shape. Change them and you are searching for a different pattern.

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

Four channels sit under `EnableAlerts`: popup, push notification, email and sound, with `SoundFile` naming the clip. Popup ships on and the other three ship off. The guard compares against the stored bar time, so one closed bar yields at most one message.

Every Basic Harmonic Pattern Indicator input

Core settings

Setting What it does Default
Depth Half-window for the fractal pivot scan, default `7`. Larger values give fewer, cleaner pivots. 7
MaxPivots How many pivots stay in the search list, default `40`. 40
AbLo Lower bound for the AB/XA ratio, default `0.55`, with `AbHi` at `0.65` closing the band. 0.55
AbHi (see inputs panel) 0.65
BcLo Lower bound for BC/AB, default `0.3`, with `BcHi` at `0.9`. The widest of the three bands. 0.3
BcHi (see inputs panel) 0.9
CdLo Lower bound for CD/BC, default `1.2`, with `CdHi` at `1.65`, so the final leg must extend beyond BC. 1.2
CdHi (see inputs panel) 1.65
RatioTol Slack added to every band, default `0.12`. Tighten it toward 0.05 for stricter patterns. 0.12

Display settings

Setting What it does Default
ArrowOffsetPoints Distance between candle and arrow, default `50` points. 50

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
Basic harmonic pattern indicator inputs: Depth, the three ratio bands and RatioTol
Basic harmonic pattern indicator inputs: Depth, the three ratio bands and RatioTol

Settings that fit your chart

Harmonic patterns need legs that are clearly separated, which is why the screenshot note calls for EURUSD on H4. A depth of 7 on that timeframe gives pivots days apart and patterns that take weeks to form. On M15 the same depth finds pivots constantly and most matches are too small to act on. The daily chart works well for patient traders.

When the Basic Harmonic Pattern Indicator fails

The tolerance widens every band by the same amount, so a 0.12 setting makes all three tests looser at once. Some matches will not look like the textbook shape.

Ratios are measured on pivot prices alone. The pattern’s shape in time, which many harmonic traders weigh, plays no part.

Fractal pivots confirm late, so the tool names a pattern after D has already printed rather than as price approaches it.

Copy the compiled Basic 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 Basic Harmonic Pattern Indicator: Candlestick pattern on Wikipedia, Candlesticks And Support at StockCharts ChartSchool.

Download the Basic Harmonic Pattern Indicator for MT4 and MT5

The zip holds the compiled Basic 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

Which three ratios must pass before an arrow prints?

AB divided by XA, BC divided by AB, and CD divided by BC. Each has its own band: `AbLo` to `AbHi`, `BcLo` to `BcHi`, and `CdLo` to `CdHi`, every one widened by `RatioTol`. All three have to land inside their range on the same candidate. Failing one discards the pattern entirely.

What pattern do the default bands describe?

A shape where AB retraces roughly 0.55 to 0.65 of XA, BC retraces 0.3 to 0.9 of AB, and CD extends 1.2 to 1.65 of BC. Those bands define one particular harmonic family. Changing them turns the tool into a search for something else, which is exactly why they are exposed as inputs.

How does RatioTol interact with the bands?

It widens all three at once, adding slack at both ends. At the default `0.12` a band of 0.55 to 0.65 effectively runs 0.43 to 0.77, which is generous. Tightening it toward 0.05 leaves only candidates close to the stated ratios, and the pattern count drops sharply.

Why does MaxPivots cap the list at 40?

To keep the search bounded. The code needs five consecutive pivots to test a pattern, and forty gives plenty of overlapping candidates without walking the entire chart on every bar. Raising it lets older structure into the search at some cost in speed.

Are results guaranteed?

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

Category: this is part of our Support and Resistance collection. Also, still, hence, plainly, truly, 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