An indicator only plots a line or fires an alert — an Expert Advisor (EA) actually sends orders on your behalf. This free EA trades Chaikin Money Flow crossing decisively past a threshold, but only in the direction an EMA trend filter already agrees with: when accumulation takes over on a pair that is already trading above its long-term average, it opens a BUY, with Stop Loss, Take Profit, and position size all calculated automatically from ATR and account risk.
How the Strategy Works
The entry signal starts with the same CMF calculation covered in the Chaikin Money Flow lesson: every bar's volume is weighted by where price closed inside that bar's own range, summed over CMFPeriod bars, and divided by total volume for the same window. The result is a line bounded roughly between −1 and +1 that reads positive when volume has been landing on the buying side and negative when it has been landing on the selling side. There is no built-in CMF function in either MetaTrader 4 or MetaTrader 5, so the EA computes all three steps internally rather than calling a platform indicator.
Where this EA differs from a plain zero-line-cross system is that it demands two things at once. First, CMF must cross past CMFThreshold (default 0.05) rather than merely nicking zero — that band around zero is where CMF spends much of its time in a balanced market, and crosses inside it are mostly noise. Second, the just-closed bar must be on the correct side of an EMA (default 100 periods) for the direction of the trade. A BUY needs CMF crossing above +0.05 and the close above the EMA; a SELL needs CMF crossing below −0.05 and the close below it.
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 the pair is actually moving right now. 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) — 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, keeping the dollar amount at risk roughly constant even as the ATR-based stop distance changes with volatility. See Lot Sizes Explained for how that lot size is then normalized to the broker's minimum, maximum, and step lot constraints before the order is sent. UseFixedLot is available as an escape hatch for a constant lot size regardless of account risk.
Entry Conditions
- BUY — CMF crosses above
+CMFThresholdon the just-closed bar, and that bar closed above theTrendMAPeriodEMA. - SELL — CMF crosses below
−CMFThresholdon the just-closed bar, and that bar closed below the EMA — the mirrored condition.
Three safety mechanics govern every trade this EA can place, matching the standard used across every EA on this site: 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 entries 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 when the spread is too wide to trade at a reasonable price. Every order is tagged with MagicNumber (default 20260824), so the EA's position-counting logic never touches a trade opened manually or placed by a different EA on the same account.
Parameters
- CMFPeriod (default 20) — the look-back window CMF is summed over. Shorter (10-14) reacts to a handful of strong bars quickly and produces far more crossings; longer (30-50) gives a slow line that crosses rarely but with more weight behind each signal.
- CMFThreshold (default 0.05) — how far past zero CMF must cross for the signal to count, applied symmetrically as
+0.05for BUY and−0.05for SELL. Raising it toward 0.15-0.20 demands real conviction and trades much less often; setting it to 0 turns the EA back into a plain zero-line-cross system. - UseTrendFilter (default true) — when disabled, the EA takes every threshold cross regardless of where price sits relative to the EMA.
- TrendMAPeriod (default 100) — the EMA period used as the trend filter. Longer means a slower, higher-level bias that changes rarely; shorter lets the filter flip with the medium-term swing.
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 20260824.
Why This EA Needs a Trend Filter
Chaikin Money Flow measures pressure, not direction. That distinction sounds academic until you watch a zero-line cross fire during a deep pullback inside a strong downtrend: buyers genuinely did step in for a stretch of bars, CMF genuinely did turn positive, and the pair genuinely did keep falling afterwards. The indicator was not wrong — it reported real accumulation. It simply has no way of knowing that the accumulation was a temporary bounce inside a larger move, because nothing in the CMF calculation looks further back than CMFPeriod bars.
The EMA filter supplies exactly the missing piece. By requiring the close to sit above a 100-period EMA before any BUY, the EA converts CMF from a two-way reversal signal into a one-way continuation signal: it only buys accumulation that is happening inside an existing uptrend, and only sells distribution inside an existing downtrend. That is a deliberate trade-off, not a free improvement — it means the EA will systematically miss the genuine bottom of every reversal, because at a true turning point the trend filter still points the old way. Traders who want the EA to trade both directions freely can set UseTrendFilter to false, and should expect substantially more signals with a materially lower proportion of them working out.
A Word of Caution
Test on a demo account first, across different market conditions and multiple pairs, before risking real money — a good backtest or demo run never guarantees future results. This EA can and will lose on individual trades. It carries one caveat that most EAs on this site do not: spot forex has no real volume, so every CMF value it calculates is derived from tick volume, the count of price updates during the bar, as reported by your specific broker. That figure can differ between brokers for the same pair at the same moment, which means backtest results on one broker's data are not automatically transferable to another's — check both before committing. 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 lesson exists to explain the mechanics, not to advise you on your own trading decisions.