◆ New — Strategy Validator, Code Fixer & Prop Compliance Checker are live. Try one free →
Home / Strategies / SMA Crossover + MFI Filter
Combination strategy

SMA Crossover + MFI Filter

A combination strategy that uses a SMA crossover to define trend direction and MFI as a filter on those signals. The idea: only act on crossovers that agree with momentum, to skip some of the false signals a crossover alone produces. Educational only — not predictive, and trading involves risk of loss.

How it works

Trend trigger — SMA crossover. A moving average (MA) takes the average price over a chosen number of bars and plots it as a single line that updates each bar. Two SMAs of different lengths (e.g. 9 and 21) are plotted; the fast one crossing above the slow one is read as upward momentum, and below as downward.

Filter — MFI. The Money Flow Index (MFI) is a momentum oscillator that combines price and volume to gauge buying and selling pressure over a chosen lookback period. Here it is used to use MFI (a volume-weighted oscillator) to filter out overbought longs and oversold shorts.

Why combine them. A moving-average crossover defines direction but fires on every cross, including in choppy conditions; adding a MFI filter tries to skip crossovers that trigger into already-stretched momentum. Both components are lagging by construction, so this reduces some false signals at the cost of entering later — it does not remove risk or guarantee anything.

Entry rules

Exit rules

Risk notes

Pine v6 example

//@version=6
strategy("SMA Crossover + MFI Filter (Educational)", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10, process_orders_on_close=true)

fastLen = input.int(9, "Fast SMA length", minval=1)
slowLen = input.int(21, "Slow SMA length", minval=1)

fast = ta.sma(close, fastLen)
slow = ta.sma(close, slowLen)
oscVal = ta.mfi(hlc3, 14)

longCond  = ta.crossover(fast, slow)  and oscVal < 80
shortCond = ta.crossunder(fast, slow) and oscVal > 20

if longCond
    strategy.entry("Long", strategy.long)
if shortCond
    strategy.entry("Short", strategy.short)

plot(fast, "Fast SMA", color.aqua)
plot(slow, "Slow SMA", color.orange)

// Educational only. Not financial advice. Validate for look-ahead bias &
// repainting before trusting any backtest. Past results do not predict future.

Pitfalls

FAQ

Does adding MFI improve a SMA crossover?

It can reduce some false signals by skipping crossovers that fire into stretched momentum, but it also delays or removes some good entries, and it does not make the strategy predictive. Test it out-of-sample and account for costs. This is educational, not advice.

What settings should I use?

9/21 for the SMAs and standard MFI settings are common starting points, but there is no universally correct value — choose lengths that fit your timeframe and validate out-of-sample rather than tuning to past data.

Educational & software only — not financial advice, not a recommendation to trade. Backtests are illustrative; past performance does not predict future results. Trading involves substantial risk of loss.

Catch the bug that compiles.Run auditGet Pro