Forex
EA

EA: Fractals Breakout Expert Advisor

Last updated 2026-07-18

An Expert Advisor (EA) is different from every other download on this site — an indicator only plots or alerts, while an EA actually sends orders on your behalf. This free EA trades a breakout strategy built entirely around confirmed Fractals: it tracks the most recently confirmed swing high and swing low on the chart, enters when price closes beyond one of them, sizes its Stop Loss, Take Profit, and position automatically, and manages one position at a time. One thing sets it apart from most other EAs on this site: its Stop Loss isn't ATR-based at all — it's the broken Fractal level itself, for reasons explained below.

How the Strategy Works

A Fractal marks a confirmed local swing high or swing low — a five-bar pattern where the middle bar's high (or low) stands higher (or lower) than the two bars on either side of it, exactly as the site's own Fractals lesson describes. This EA runs that same detection on every completed bar and keeps two running values in memory: the most recently confirmed up-fractal price and the most recently confirmed down-fractal price. Each time a new fractal confirms, it overwrites the stored value; between confirmations, the EA simply holds onto the last one it saw.

The entry logic is a straightforward breakout against those two stored levels. A BUY fires when the most recently completed bar's close crosses above the stored up-fractal price — price breaking out above a known, confirmed swing high. A SELL fires on the mirror condition: the completed bar's close crossing below the stored down-fractal price, a breakout below a known swing low. Critically, this EA inherits the same confirmation lag the Fractals indicator itself carries: because a fractal can't be confirmed until two bars after the candidate swing point, the level the EA is trading against was always locked in a couple of bars before the breakout attempt, never in real time. The code reflects this directly — both the MT4 and MT5 versions read iFractals(...) at shift 2, the identical lag used by the site's Fractals alert indicator, so the stored level is always a genuinely confirmed swing point rather than a guess at one still forming.

Stop Loss, Take Profit, and Position Sizing

PriceStop Loss = broken fractal levelTake Profit (TP)BUYEntry: close breaks above the most recent confirmed up-fractal
Entry conditions: BUY when price closes above the last confirmed up-fractal, SL at that fractal's own level — SELL on the mirrored break below a down-fractal

This is the section that matters most for understanding this particular EA. Most other EAs on this site size their Stop Loss from ATR — a volatility-adaptive stop that widens on volatile pairs and tightens on calm ones. This EA does not do that, and it's not an oversight. A Fractal is already a concrete, price-anchored level created by the market's own structure — it marks the exact price at which a real swing high or swing low actually formed, confirmed by five real bars of price action, not a statistical estimate of how far price tends to move. Layering ATR on top of a Fractal-based system would just add a second, disconnected opinion about a stop distance the fractal has already defined directly.

So when the EA opens a BUY on a confirmed breakout, the Stop Loss is placed exactly at the broken up-fractal level — the swing high that price just closed above, now reinterpreted as new support underneath the trade. The mirrored logic applies to a SELL: the Stop Loss sits at the broken down-fractal level, the swing low that price just closed below, now treated as new resistance above the trade. Take Profit is then set at a multiple of that Stop Loss distance — RiskRewardRatio, default 2.0 — so a 2.0 setting means the target sits twice as far from entry as the stop, keeping every trade's risk and reward in a fixed, known proportion regardless of how wide or narrow that particular fractal-based stop happens to be.

Position size is calculated the same way as every other EA on this site: a RiskPercent of account balance (default 1.0%) divided by the Stop Loss distance, converted through the symbol's tick value and normalized to the broker's lot step — the exact worked-example method from Risk Management Basics. A wider fractal-based stop produces a smaller lot size, and a tighter one produces a larger lot size, so the dollar risk per trade stays consistent even though the stop distance itself varies from breakout to breakout depending on how far the broken swing point sits from the entry price. A UseFixedLot input with a FixedLotSize value is available as an escape hatch for traders who'd rather trade a constant lot size regardless of risk. There's also a built-in safety check: if the computed Stop Loss distance comes out to zero or negative, the EA skips the trade entirely rather than opening a position with no meaningful stop.

Entry Conditions

  • BUY — the most recently completed bar's close crosses from at-or-below to above the stored up-fractal level. The Stop Loss is placed at that up-fractal level.
  • SELL — the most recently completed bar's close crosses from at-or-above to below the stored down-fractal level. The Stop Loss is placed at that down-fractal level.

The EA evaluates these conditions once per new bar only (tracked against the time of the current bar's open), never on every tick, so a single breakout can't fire multiple trades within the same candle. It opens at most one position at a time, counted and filtered by its own magic number (MagicNumber, default 20260730), so it never confuses a position it opened with one you opened manually or one belonging to a different EA on the same account. Before opening anything, it also checks the current spread against MaxSpreadPoints and skips the entry entirely if the market is too illiquid at that moment. Finally, the degenerate-stop guard described above means a trade is only ever sent when the computed Stop Loss distance is a genuinely positive number — a signal that technically fires but produces a zero-distance or negative stop is discarded rather than sent to the broker.

Parameters

  • RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance (from the broken fractal level) × this ratio.
  • RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size against the fractal-based Stop Loss distance. Ignored if UseFixedLot is enabled.
  • UseFixedLot (default false) — when enabled, trades a constant lot size instead of calculating one from RiskPercent.
  • FixedLotSize (default 0.01) — the lot size used when UseFixedLot is enabled.
  • MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, the same concern covered in Spread and Slippage.
  • MagicNumber (default 20260730) — tags every order this EA places so its position-counting and management logic never touches trades opened manually or by a different EA.
  • EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.

Notice what's missing compared to most of the site's other EAs: there is no ATRPeriod and no ATRMultiplier here, and there's no lookback period at all for the fractal detection itself, since (as the Fractals lesson explains) the pattern is fixed at five bars by definition and isn't tunable. That's not a simplification or an oversight — it's the direct consequence of the design choice explained in the next section.

Why This EA Uses the Broken Fractal Instead of ATR

Most other EAs on this site — ea-trend-following included — calculate their Stop Loss as ATRMultiplier × ATR, a fixed distance recalculated fresh at the moment each trade opens, entirely from volatility statistics with no reference to any actual price level nearby. This EA works differently on purpose, the same way Parabolic SAR Trend EA and Ichimoku Breakout EA do, and the reasoning is worth walking through concretely.

ATR answers one question: given recent volatility, how far away should a stop sit? It has no opinion at all about where support or resistance actually is on the chart — it's a distance derived purely from a statistical average, blind to the market's own structure. A Fractal answers a completely different, and in this case more relevant, question: where did the market itself actually turn last time? The broken up-fractal on a BUY trade isn't an estimate — it's the literal price at which five real bars of price action already proved a swing high was there. Placing the Stop Loss at that exact level means the stop sits precisely where the trade's own thesis would be proven wrong: if price falls back through the level it just broke out above, the breakout has failed and the level that was supposed to act as new support didn't hold, which is exactly the moment to be out regardless of what an ATR-derived distance happens to say.

Running ATR on top of a fractal-based stop here wouldn't make the stop meaningfully better — it would just be a second, disconnected opinion about a stop distance the fractal has already defined directly, using the same price structure that produced the entry signal in the first place. There would be nothing for ATR to add: the fractal is concrete and price-anchored, while ATR is abstract and derived from an average, and reconciling the two whenever they disagreed would only add complexity without adding protection. This is precisely why the EA reuses the fractal level itself rather than reaching for a second, separate calculation.

Installation and Setup

EAs install into a different folder than indicators — this is the step people miss most often.

  1. Download the file below for your platform.
  2. Open MetaTrader → click FileOpen Data Folder.
  3. Place the file in MQL4/Experts (MetaTrader 4) or MQL5/Experts (MetaTrader 5) — not the Indicators folder.
  4. Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
  5. Enable AutoTrading (MT4) or Algo Trading (MT5) in the toolbar — the EA will not place any trades while this is off, even if it's attached to a chart.
  6. Review and adjust the input parameters in the EA's settings dialog before confirming.

A Word of Caution

Test on a demo account first, across different market conditions, before risking real money — past performance, in backtests or live, never guarantees future results. No strategy, automated or manual, wins every trade, and this EA can and will lose money on individual trades. Breakout EAs like this one whipsaw badly in choppy or ranging markets: a market that isn't trending throws off a steady stream of small, low-value fractals, and a shallow break above a weak up-fractal (or below a weak down-fractal) can trigger an entry that reverses within a few bars, stopping the trade out for a quick loss before any real move develops. A fractal formed during a quiet, narrow-range pullback is not the same quality of level as one formed at the top of a genuine multi-bar swing, even though both print an identical arrow — the EA itself can't tell the difference, since it trades every confirmed fractal level the same way. Consider combining it with a read of trend vs range before enabling it on a live account, and keep in mind the confirmation lag covered above: because a fractal locks in two bars after the fact, the level being traded is always slightly dated by the time a breakout attempt occurs. Both files are source code — open and review them fully, and understand what every parameter does, before using it. This content is general education, not personalized investment advice.

Download the EA

How to Install — MetaTrader 4

  1. Download the fractals-breakout-ea.mq4 file below.
  2. Open MetaTrader 4 → click FileOpen Data Folder.
  3. Place the file in the MQL4/Experts folder.
  4. Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.

How to Install — MetaTrader 5

  1. Download the fractals-breakout-ea.mq5 file below.
  2. Open MetaTrader 5 → click FileOpen Data Folder.
  3. Place the file in the MQL5/Experts folder.
  4. Restart MetaTrader 5, then drag the EA from the Navigator window onto the chart.

Both files are source code — open and review the full code before using it, for your own safety.

Download fractals-breakout-ea.mq4

For MetaTrader 4 — this is source code (.mq4), open and review it fully before using it.

Download File

Download fractals-breakout-ea.mq5

For MetaTrader 5 — this is source code (.mq5), open and review it fully before using it.

Download File