Money Flow Index MFI 14 (20/80) — Pine Script v5 strategy
The Money Flow Index looks like the RSI but weights each bar by its volume. This script buys when the 14-period MFI leaves the low zone by moving back above 20, and sells when it enters the high zone above 80.
Full code (free to copy)
//@version=5
strategy("MFI 14 Volume Oversold 20/80", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
len = input.int(14, "MFI Length", minval=5, maxval=35)
lowB = input.int(20, "Oversold", minval=10, maxval=35)
highB = input.int(80, "Overbought", minval=65, maxval=90)
m = ta.mfi(hlc3, len)
if ta.crossover(m, lowB)
strategy.entry("Long", strategy.long)
if ta.crossover(m, highB)
strategy.close("Long")
plot(m, "MFI", color=color.teal)Judge this code on BTCUSDT 1D →Free, in your browser, on the same candles as the table below.
Online judge verdict on BTCUSDT (measured 29 November 2026)
| Timeframe | Sealed period | Trades | Return | Buy & hold | Verdict |
|---|---|---|---|---|---|
| 1d | The judge does not open the sealed period: 9 trades on the training part, at least 10 are needed. No return is shown. | Not enough trades to judge yet | |||
| 4h | 2026-03-12 → 2026-10-17 | 6 | 4.38 % | 15.83 % | Not enough trades to judge yet |
| 1h | 2026-08-05 → 2026-10-17 | 10 | 16.44 % | 27.14 % | No evidence of an edge, for now |
Past data, 10 bps per fill, last 20% of the bars sealed. Windows: full history on 1d, last 3 years on 4h, last year on 1h. Research, not advice: no result is promised.
This reading has not been compared with a real TradingView run.
Measured on 29 November 2026 with the online judge’s Pine v5 engine (sa-pine-vm 0.2.0), on Binance BTCUSDT candles up to 16/10/2026 on 1D and up to 17/10/2026 on 4h and 1h. Differences with TradingView’s Strategy Tester remain possible. Binance data, CC BY-NC-SA 4.0.
Open this code in the free judge (1 click) →
Replay each verdict yourself, in your browser: 1d · 4h · 1h. The script is filled in; nothing runs until you click “Judge”.
How the script works
m = ta.mfi(hlc3, len) with len = 14, computed on the typical price and the volume of each bar. The levels lowB = 20 and highB = 80 are inputs.
ta.crossover(m, lowB) opens the long position; ta.crossover(m, highB) closes it. The code has no stop: a position stays open until the MFI reaches 80.
Parameters in the code
| Parameter | Value | Role |
|---|---|---|
len | 14 | Input "MFI Length" created with input.int, from 5 to 35. |
lowB | 20 | Input "Oversold" created with input.int, from 10 to 35. |
highB | 80 | Input "Overbought" created with input.int, from 65 to 90. |
initial_capital | 10000 | Starting capital declared in strategy(). |
default_qty_type | percent_of_equity, 100 | Each entry commits 100% of available equity. |
commission_value | 0.1 (%) | 0.10% commission per order declared in the script; the judge applies it (10 bps per fill). |
process_orders_on_close | not set | Orders fill at the open of the next bar, the Pine default. |
Known limits of this rule
- In a downtrend, the MFI can leave the low zone and come back to it while price keeps falling.
- The 20 and 80 levels are strict: signals are rare on the daily timeframe, hence "not enough trades" verdicts.
- The volume of a single exchange does not reflect all the volume traded on the asset.
Before you trust it: test it on data it never saw
A backtest in TradingView's Strategy Tester shows one past path with the settings you picked. Strategy Arena Lab (free, Windows and Linux) replays this Pine on your PC, compares its trades one by one with TradingView's for supported Pine, counts the variants you try, then judges the rule on a period kept sealed during the search: survives, no evidence of an edge or inconclusive.
FAQ
What does the online judge say about this script?
On BTCUSDT, with 10 bps fees per fill, measured on 29 November 2026: 1D: "Not enough trades to judge yet" (sealed period not opened, 9 training trades); 4h: "Not enough trades to judge yet" (6 trades, 4.38% on the sealed period); 1h: "No evidence of an edge, for now" (10 trades, 16.44% on the sealed period). No timeframe reaches "Survives". These verdicts concern past data and say nothing certain about the future.
Why does the judge show no return on 1D?
On 1D, this rule makes fewer than 10 trades on the training part. The judge then does not open the sealed period and shows no return: it answers "not enough trades".
Can I change the script's settings?
Yes, the settings are inputs you can edit in TradingView. Each setting you try is one more trial: a setting chosen after seeing the sealed period is no longer a test on unseen data. The judge and the Lab count trials for this reason.
Other free Pine Script v5 strategies
More TradingView paths
Educational code on past data. No investment advice; no result is promised.