strategy · own pane · open source
MFI Mean Reversion
Running…
Loading chart…
About
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.
Source code
//@version=5
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)
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=color.gray, linestyle=hline.style_dashed)
hline(20, "Oversold", color=color.gray, linestyle=hline.style_dashed)
hline(50, "Midline", color=color.gray, linestyle=hline.style_dotted)
p_MFI = plot(m, "MFI", color=color.orange, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=color.green, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=color.red, text="X")
alertcondition(longSignal, "MFI long entry", "MFI dropped below 20")
alertcondition(exitSignal, "MFI exit", "MFI climbed above 80")
No comments yet.
Sign in to comment.