An Expert Advisor (EA) is different from every other download on this site — an indicator only plots a line or fires an alert, while an EA actually sends orders on your behalf. This free EA trades a breakout strategy built around price making a new N-bar high or low, but it refuses to act on that breakout alone: it only enters once Accumulation/Distribution independently confirms the same new high or low on its own running total. Stop Loss, Take Profit, and position size are then all handled automatically using the same volatility- and risk-based tools taught elsewhere on this site.
How the Strategy Works
The raw entry signal here is the simplest kind of breakout there is: has the just-closed bar's close printed the highest close of the last ConfirmPeriod bars (default 20)? If so, price has broken out to a new short-term high, and in theory that's a bullish signal — buyers have pushed price further than they have in the last 20 bars, and a breakout trader would normally jump on that. The mirrored case — the just-closed bar's close is the lowest close of the last ConfirmPeriod bars — is the equivalent bearish signal.
The problem with trading that signal on its own is well known to anyone who has traded breakouts: plenty of new N-bar highs happen on a handful of thin, lightly-traded prints rather than genuine buying pressure, and those breakouts fail and reverse right back into the range they came from. This EA's answer is to demand a second, independent witness before it believes the breakout. At the exact same bar where price is printing its new N-bar high, the EA also checks whether A/D — the cumulative running total that weights each bar's volume by how strongly its close landed within that bar's own range — is also printing its own new N-bar high over the identical lookback window. Price and A/D are two different calculations built from the same raw bars, so when both independently agree that "this is the highest point in 20 bars," that agreement means something more specific than a plain volume count would: not only was volume behind the move, but the closes driving it were landing strong, near the top of their own ranges, the entire way up. If price makes a new high but A/D does not, the EA treats that as a red flag and does nothing at all — this is the core idea the rest of this lesson builds on.
Stop Loss, Take Profit, and Position Sizing
Both Stop Loss and Take Profit are sized from ATR rather than a fixed pip distance, so the stop always reflects how much a pair is actually moving right now instead of a number picked once and left unchanged. Stop Loss distance is ATRMultiplier × ATR (default multiplier 2.0, ATR calculated over ATRPeriod, default 14), and Take Profit is then set at RiskRewardRatio × Stop Loss distance (default 2.0) — so a BUY placed with a 20-pip ATR-based stop automatically gets a 40-pip target, and every trade this EA opens, on any pair or timeframe, carries the same fixed reward-to-risk proportion.
Position size follows the exact worked-example method from Risk Management Basics: RiskPercent (default 1.0%) of account balance is divided by the Stop Loss distance to produce a lot size, so the dollar amount at risk stays roughly constant trade to trade even though the ATR-based stop distance itself changes as volatility changes. A wide stop on a volatile pair yields a smaller lot; a tight stop on a calm pair yields a larger one. The calculated lot is normalized to the broker's minimum, maximum, and step lot size before the order is sent. UseFixedLot is available as an escape hatch for traders who would rather trade a constant lot size regardless of account risk — useful for testing, or for small accounts where percentage-based sizing would otherwise round down to the broker's minimum lot anyway.
Entry Conditions
- BUY — the just-closed bar's close is the highest close of the last
ConfirmPeriodbars, and A/D at that same bar is also the highest A/D value over the sameConfirmPeriod-bar lookback window. - SELL — the just-closed bar's close is the lowest close of the last
ConfirmPeriodbars, and A/D at that same bar is also the lowest A/D value over the same lookback window — the mirrored setup.
If price prints a new N-bar high or low but A/D does not agree at that same bar, the EA simply does nothing — the price breakout is logged internally as "seen" but never acted on, because volume-weighted close strength hasn't confirmed it. Beyond the dual-confirmation requirement itself, three safety mechanics govern every trade this EA can place: it evaluates entry conditions once per new bar only (tracked via the bar's open time), so a single qualifying bar can't trigger repeated trades within the same candle; it opens only one position at a time, checked by counting open trades filtered to this EA's own symbol and magic number before any new entry is considered; and it checks the current spread against MaxSpreadPoints (default 30) before sending an order, skipping the entry entirely if the spread is too wide to trade at a reasonable price. Every order is tagged with MagicNumber (default 20260803), so the EA's position-counting logic — and any future management logic — never touches a trade you opened manually or a trade placed by a different EA running on the same account.
Parameters
- ConfirmPeriod (default 20) — the lookback window, in bars, used for both the price high/low check and the A/D high/low check. A shorter window (e.g. 10) reacts to smaller, more frequent breakouts; a longer window (e.g. 40-50) waits for a more significant price move before considering an entry, at the cost of fewer signals.
- AppliedVolume (MT5 only, default
VOLUME_TICK) — the volume basis A/D is calculated from. MQL4'siAD()always uses tick volume directly, with no equivalent input.
The rest of the inputs belong to the shared risk engine every EA here uses: stop and target sizing, position sizing, the spread filter, and the master switch. They are documented once on the EA hub page rather than repeated on every lesson. Orders from this EA carry the magic number 20260803.
Why Require A/D to Confirm the Breakout
This is the single design choice this whole EA is built around, so it's worth spelling out why it exists rather than treating it as a throwaway detail. A price breakout — a new N-bar high or low — only tells you that the most recent close is more extreme than anything in the recent lookback window. It says nothing about how that close got there. A thinly-traded market can print a new high on a single large order, a stop run, or a brief burst of illiquid price action, and then snap right back into the range a bar or two later once the imbalance clears. That pattern — often called a false breakout — is one of the most common ways a naive breakout strategy loses money: it buys the top of a spike that had no real demand behind it, and the reversal that follows hits the stop almost immediately.
A/D solves this because it measures something a price breakout alone cannot: whether the closes behind the move were actually landing strong within their own bars, not just outnumbering down-closes the way a simpler volume tally would count them. Because A/D only rises when closes land consistently near the top of their range on real volume, a genuine new A/D high requires sustained, high-quality buying pressure accumulated over the entire lookback window — not just one large print on the breakout bar itself, and not just a string of weak up-closes that a cruder volume measure would still count as bullish. Requiring A/D to independently reach its own new high at the exact same bar as the price high is effectively asking two unrelated calculations, built from the same raw data in different ways, to agree before the EA trusts the move. This filters out a large share of the thin, unconvincing breakouts that make up most false starts, and lets through the breakouts that arrive alongside real, sustained, strongly-closing participation. The tradeoff is that this EA will occasionally sit out a fast breakout that turns out to be genuine — A/D confirmation, by construction, can only recognize participation that has already accumulated, not a move that is about to develop. And it's worth repeating a caveat that matters specifically for forex: the "volume" A/D uses on most retail forex feeds is tick volume (the number of price changes per bar), not the true traded volume you'd get on an exchange-listed instrument, so A/D here is a proxy for participation rather than an exact measurement of it. No confirmation filter, volume-based or otherwise, can promise a confirmed breakout continues; it can only raise the odds that a signal reflects real participation rather than noise — the same idea behind requiring ADX to confirm a directional cross before acting on it, just applied to a breakout instead of a crossover.
A Word of Caution
Test on a demo account first, across different market conditions and multiple pairs, before risking real money — a backtest or a good run on a demo account never guarantees future results. This EA can and will lose on individual trades; the A/D confirmation filter reduces the number of false breakouts it acts on, but it cannot eliminate them, and it does nothing to protect against a breakout that was genuinely well-supported right up until it reversed anyway. Remember too that A/D on a forex feed is built from tick volume, not true traded volume, so "confirmation" here means proxy participation agreed with price, not a guarantee drawn from exchange-verified order flow. Consider combining this EA with other reads on trend quality (price structure, a higher-timeframe direction check, or Trend vs Range) rather than trading the signal in isolation. Both the MT4 and MT5 files below are source code — open and read them fully, and understand exactly what every parameter does, before attaching this EA to a live account. This content is general education, not personalized investment advice.