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 On-Balance Volume 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 OBV — the cumulative running total of volume added on up-closes and subtracted on down-closes — is also printing its own new N-bar high over the identical lookback window. Price and OBV are two completely different calculations built from the same raw bars, so when both independently agree that "this is the highest point in 20 bars," that agreement is meaningful: real volume was actually behind the move that produced the new price high, not just a light print that happened to tick above the recent range. If price makes a new high but OBV 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 OBV at that same bar is also the highest OBV value over the sameConfirmPeriod-bar lookback window. - SELL — the just-closed bar's close is the lowest close of the last
ConfirmPeriodbars, and OBV at that same bar is also the lowest OBV value over the same lookback window — the mirrored setup.
If price prints a new N-bar high or low but OBV 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 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 20260732), 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 OBV 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.
- AppliedPrice / AppliedVolume — the price/volume basis OBV is calculated from (MT4 exposes
AppliedPrice, MT5 exposesAppliedVolume, defaulting to tick volume — the only volume data forex brokers actually provide). - ATRPeriod (default 14) — the lookback used to calculate ATR for Stop Loss sizing.
- ATRMultiplier (default 2.0) — Stop Loss distance = ATR × this multiplier.
- RiskRewardRatio (default 2.0) — Take Profit distance = Stop Loss distance × this ratio.
- UseFixedLot — switches position sizing from risk-based to a constant lot size.
- FixedLotSize (default 0.01) — the lot size used when
UseFixedLotis enabled. - RiskPercent (default 1.0) — percentage of account balance risked per trade, used to calculate lot size when
UseFixedLotis disabled. - MaxSpreadPoints (default 30) — skips new entries while the spread is wider than this, to avoid opening trades at a bad price during illiquid conditions.
- MagicNumber (default 20260732) — tags every order this EA places so its position-management logic never touches trades opened by hand or by a different EA.
- EnableTrading — a master on/off switch, useful for pausing the EA without removing it from the chart.
Why Require Volume 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.
OBV solves this because it measures something a price breakout alone cannot: whether the volume behind the move actually agrees with it. Because OBV only rises when up-closes outweigh down-closes bar after bar, a genuine new OBV high requires sustained buying pressure accumulated over the entire lookback window — not just one large print on the breakout bar itself. Requiring OBV 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 participation. The tradeoff is that this EA will occasionally sit out a fast, thin-volume breakout that turns out to be genuine — OBV 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" OBV 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 OBV 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.
Installation and Setup
EAs install into a different folder than indicators, and this is the step people miss most often.
- Download the file below for your platform.
- Open MetaTrader → click
File→Open Data Folder. - Place the file in
MQL4/Experts(MetaTrader 4) orMQL5/Experts(MetaTrader 5) — not the Indicators folder. - Restart MetaTrader, then drag the EA from the Navigator window onto a chart.
- 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.
- 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 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 OBV 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 by volume right up until it reversed anyway. Remember too that OBV 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.
Download the EA
How to Install — MetaTrader 4
- Download the
obv-trend-confirmation-ea.mq4file below. - Open MetaTrader 4 → click
File→Open Data Folder. - Place the file in the
MQL4/Expertsfolder. - Restart MetaTrader 4, then drag the EA from the Navigator window onto the chart.
How to Install — MetaTrader 5
- Download the
obv-trend-confirmation-ea.mq5file below. - Open MetaTrader 5 → click
File→Open Data Folder. - Place the file in the
MQL5/Expertsfolder. - 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.