strategy · own pane · open source
Money Flow Index (MFI) mean reversion strategy (14, 20 / 80)
Money Flow Index (14) mean reversion: buy when MFI drops below 20, exit above 80, with a 2%/6% bracket. Plain-English rules, code and a costed backtest. Deepwick Script runs a subset of Pine Script.
What the MFI Mean Reversion strategy does
Money Flow Index mean reversion long-only: enter when MFI drops below 20 (volume-weighted oversold), exit when it climbs above 80.
- MFI combines price action with volume; signals are rarer than RSI but higher-quality.
- 14-period is standard; longer lengths (21+) are steadier on daily charts.
- Combine with an RSI divergence for stronger confirmations.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
MFI Length | 14 | 5 | 50 |
Stop Loss % | 2 | 0.5 | 10 |
Take Profit % | 6 | 0 | 20 |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("MFI Mean Reversion", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
len = input.int(14, "MFI Length", minval=5, maxval=50, step=1)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
colorMid = input.color("color.orange", "Color Mid")
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
colorNeutral = input.color("color.gray", "Color Neutral")
m = ta.mfi(close, len)
longSignal = strategy.position_size == 0 and m < 20
exitSignal = strategy.position_size > 0 and m > 80
if longSignal
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
strategy.close("Long", comment="MFI exit")
hline(80, "Overbought", color=colorNeutral, linestyle=hline.style_dashed)
hline(20, "Oversold", color=colorNeutral, linestyle=hline.style_dashed)
hline(50, "Midline", color=colorNeutral, linestyle=hline.style_dotted)
p_MFI = plot(m, "MFI", color=colorMid, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
alertcondition(longSignal, "MFI long entry", "MFI dropped below 20")
alertcondition(exitSignal, "MFI exit", "MFI climbed above 80")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
What is the difference between MFI and RSI?
MFI is a volume-weighted RSI: it uses price × volume, so oversold readings need selling volume, not just falling prices. Compare this page with the RSI mean reversion page.
Does the script use typical price?
It passes close to ta.mfi. The textbook MFI uses the typical price (hlc3); switch the source to test it.
Why are trades rare?
MFI below 20 is usually rarer than RSI below 30, and the exit needs MFI above 80. Many trades will end at the bracket first; check the trade count.
No comments yet.
Sign in to comment.