Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

Metatrader 5 Indicator | Market Structure from Pullback Swings — BOS, CHoCH, IDM | MetaTrader Tool

New free code from MQL5: indicators, EAs, and scripts for traders.

Image for Market Structure from Pullback Swings — BOS, CHoCH, IDM

A bullish break is on its way to publishing a high. If the newest point in the chain is already a high, a low is missing between them, so the indicator takes the lowest low between that high and the breaking candle and publishes it first. If the newest point is already a low, the chain alternates and nothing is inserted.

That one rule covers every case: your BoS in an established trend, your CHoCH, and the very first break after the seed. The bearish case is the mirror — the highest high of the swept range.

Edge cases, stated openly

Situation How it is resolved
One candle both takes the IDM and closes through the opposite level Read in that order: the extreme is confirmed first, then the break is recorded. This is precisely the sweep-then-CHoCH case, and the order matters.
A pending extreme is never confirmed, because price breaks the other way first The tracked extreme is published where it stands, then the break is processed. Nothing is lost and the chain still alternates.
The breaking candle itself returns to the IDM Confirmation can never happen on the breaking candle. The earliest it can occur is the following bar.
No pullback exists yet to serve as the IDM The current structure level on that side is used instead. This only happens on the oldest bars of the chart.

On repainting — read this before using it

The pullback layer does not repaint, and nothing has changed about it.

Trade Renko charts automatically using the advanced Renko Expert Advisors. Clean trends, better entries. Discover them here.

The structure layer does, and it is not a defect — it is what the method is. Two things move:

  • A pending extreme moves as price extends, right up until the IDM is taken. It is published live so you can see the structure forming, instead of waiting in the dark.
  • A sweep relocates a point backwards, by design. That is the whole purpose of the x.

Once an extreme is confirmed by its IDM and no sweep is pending against it, it is settled. Events — BoS, CHoCH, x, IDM — are append-only and never move.

If you build on this, treat a structure point as provisional until its IDM line exists, and treat the events as the stable record. Only closed candles are evaluated; the forming candle is ignored entirely.

Inputs

Pullback layer

Input Default What it does
Start by looking for Looking for a swing high Which side the very first leg searches for. Only affects the oldest bars on the chart.
Pullback break confirmed by Wick The sensitivity control for the whole indicator. Wick is the literal Trading Hub rule. Close gives fewer, larger pullbacks — and therefore fewer, larger structure moves. Switch to it on M1–M15 or on noisy symbols such as gold and index CFDs.

Market structure

Input Default What it does
Extreme confirmed when reference is Wick How the IDM must be taken. Wick means touched; Close requires a close through it, which confirms extremes later but filters out shallow pokes at the inducement.
Detect liquidity sweeps true Turn off for plain structure: levels are then taken by close only, no x, and points are never relocated. Useful for comparing the two readings side by side.

There is no period, depth or sensitivity setting anywhere — the structure has no parameters of its own. If you want larger structure, raise the timeframe or switch the pullback rule to Close.

Display

Group What it controls
Pullback zig-zag The faint underlying swings — colour, style, width, or off entirely.
Structure zig-zag The gold structure line.
Structure markers Arrows on the structure high / low: Wingdings codes and pixel distance from the bar. The buffers stay filled when the arrows are off, so iCustom still sees everything.
Break lines A separate colour for BoS, CHoCH, x and IDM, plus line width and the captions. Turn the captions off on dense charts and keep the colours as the key.

Alerts

Popup and push notification on a structure event. They fire only on live updates, never while history loads, and only once per event.

Using it from an EA

Five buffers. The empty value is 0.0.

Buffer Contents
0 price of a structure high
1 price of a structure low
2 trend on every bar: 1 up, -1 down, 0 none
3 price of a confirmed pullback high
4 price of a confirmed pullback low
int h = iCustom(_Symbol, _Period, "SMC_MarketStructure");
double trend[];
CopyBuffer(h, 2, 0, 1, trend);   // 1 = up, -1 = down, 0 = none

Buffer 2 is filled on every bar including the forming one, so reading it at shift 0 always returns the current trend. The other four are sparse by nature.

Both engines are self-contained classes with no buffer or chart dependencies — CPullbackDetector takes price arrays and reports confirmed swings, CMarketStructure takes bars plus those swings and reports a point chain and an event list. Both can be copied straight into an EA if you would rather not go through iCustom, which also gives you the events — they are not exposed through buffers.

What it deliberately does not do

It stops at structure. No order blocks, no fair value gaps, no premium/discount zones, no entries and no HH/HL/LH/LL labelling. Those all need a dependable trend and a dependable pair of levels first — which is what this provides, with every decision it makes visible on the chart as a line you can check.

Complement community code with advanced automation from RobotFX.

78245

Best MetaTrader Indicators + Profitable Expert Advisors