Skip to content

Free MT5 Expert Advisor

Structure Break EA

MT5 Expert Advisor that trades the retest of a broken swing high or low in the trend direction, with a stop on every order and risk-% sizing.

Smart moneyv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Stop-loss on every trade
Strategy
Buys when a candle closes above the latest swing high in an uptrend and price then retests the broken level and closes back above it; sells on the mirror image below a swing low.
Risk model
1% of balance per trade (configurable), stop-loss on every order, one position per symbol and magic number

What it does

Structure Break EA turns a common price-action idea into fixed rules: when price closes beyond the most recent swing high or low, the old level often acts as support or resistance on the way back. The EA waits for that break, then waits again for price to return to the level, and only enters when the retest candle closes back in the break direction.

It trades one position at a time per symbol and magic number, always with a stop-loss, and sizes every trade from your risk percentage.

How it works

On every new bar the EA reads closed candles only:

  1. A swing high is a bar whose high is above the highs of the N bars on each side (N = swing strength); a swing low is the mirror image. The latest confirmed swing of each kind is used.
  2. A bullish break of structure happens when the last closed candle closes above the latest swing high and the candle before it did not. If the trend filter is on, that close must also be above the 200 EMA. Each swing can trigger only once.
  3. For up to the set number of bars, the EA waits for a retest: a candle whose low comes within the tolerance (0.2 ATR by default) of the broken level and which closes above it. A close back below the level minus the tolerance cancels the setup.
  4. On a valid retest it buys at market. The stop goes below the lower of the retest low and the level, minus a 0.3 ATR buffer. The take-profit is 2 R by default.

Sells follow the same rules below swing lows. Optional break-even and ATR trailing manage the open trade on every tick.

How to use it

The EA suits trending markets on M15 to H4. A higher swing strength finds fewer, more significant levels; a lower value reacts faster but trades more noise. Keep the trend filter on unless you want counter-trend breaks too. Check the Experts tab: the EA prints every detected break, cancellation and skip reason, which makes it easy to compare its decisions with the chart.

Settings

InputDefaultWhat it changes
Swing strength3Bars on each side needed to confirm a swing
Lookback bars150How far back the EA searches for swings
Retest bars12Time allowed for the retest
Retest tolerance (x ATR)0.2Distance counted as touching the level
Stop buffer (x ATR)0.3Extra room beyond the retest candle
Max stop (x ATR)3.0Skips trades with very wide stops
Trend EMAon, 200Direction filter
Risk % / Fixed lots1.0 / 0Position sizing
Take-profit (R)2.0Target distance (0 = none)
Max spread (points)30Skips entries when spread is wider
Trading hours7 to 20 server timeWindow for new entries
Break-even / Trailingon at 1 R / offTrade management

Limitations

Swing points are only confirmed after N bars, so breaks are recognised with a delay. In ranging markets price breaks and reverses often, which produces cancelled setups and losing retests. Fast markets can retest beyond the tolerance and never trigger an entry. Results depend on spread and on your broker's data.

Before you run it live

Run the EA on a demo account and in the Strategy Tester (with "Every tick based on real ticks" where available) across several months and symbols. Check your broker's stops level, spread and trading hours, and set the server-time hours to match. Start with a small risk percentage, and use the Position Size Calculator to understand what 1% means on your account. Trading on margin carries a substantial risk of loss.

Key inputs

Key inputs of Structure Break EA
InputDefaultDescription
Swing strength3Bars on each side a swing high or low needs to be confirmed.
Retest bars12How many bars after the break the EA waits for a retest.
Retest tolerance (x ATR)0.2How close to the broken level price must come to count as a retest.
Trend EMA period200Breaks are only traded when the close is on the EMA's trend side.
Risk per trade (%)1.0Share of balance risked between entry and stop-loss.
Take-profit (R)2.0Target as a multiple of the stop distance.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors