Money Flow Index (MFI) in Pine Script
An RSI built on volume-weighted typical price, bounded 0 to 100, so overbought and oversold readings reflect where the money has been flowing, not only where price has moved.
Definition
The Money Flow Index (MFI) is a bounded oscillator that measures the balance of volume-weighted up and down moves over a lookback, usually 14 bars. It belongs to the volume-oscillator family and is often described as a volume-weighted RSI, because it applies the same ratio of up moves to down moves, except that each bar's move is its typical price multiplied by its volume. The result runs from 0 to 100; above 80 is overbought and below 20 is oversold in the standard reading.
Volume weighting is the point. An RSI at 75 says price has risen on most recent bars; an MFI at 75 says the bars that rose carried most of the money. A rally on heavy volume pushes MFI higher than the same rally on thin volume, and a decline on heavy volume drives it lower. That makes MFI a tool for judging conviction: overbought on heavy volume near resistance is distribution, while an overbought reading on light volume in a strong trend is often just momentum.
Gene Quong and Avrum Soudack developed the indicator, and the standard settings have stayed at a 14-bar lookback with 80 and 20 as the extreme lines. Some traders use 90 and 10 to keep only the rarest readings. The implementation plots MFI in its own pane with the two levels, colours the line red above the overbought line and green below the oversold line, and marks a long when MFI climbs back above the oversold level and a short when it drops back below the overbought level.
On the chart MFI is jumpier than RSI, because it uses plain sums rather than smoothing and because one heavy bar can dominate the window. Expect readings to spend most of the time between 30 and 70, to spike into the extremes on climactic bars and to hold in the extremes for a while during strong trends. When a heavy bar leaves the 14-bar window the line steps without any change in price, which is a feature of the construction rather than a signal.
Reading the chart
Read MFI in three passes: the extreme, the exit from the extreme, and the volume behind the move.
- Check the market reports real volume. MFI is meaningless on tick-count feeds; use stocks, futures or exchange-traded crypto, and note that thin names produce erratic readings.
- Note the regime. In a range, readings above 80 and below 20 mark the edges and are faded; in a trend, the extreme in the trend's direction can persist for many bars.
- Wait for the exit from the extreme. The signal is MFI crossing back below 80 or back above 20, not the first touch, because the touch often comes on the climactic bar itself.
- Compare the swing points with price. A higher price high with a lower MFI high says the second push had less money behind it; a lower price low with a higher MFI low says downside pressure is drying up.
- Look at the bars that drove the reading. An overbought MFI built on one enormous bar will step down when that bar leaves the window; a reading built on many heavy bars is broader participation.
- Confirm on price. Use the exit from the extreme as the trigger and a level, a candle or a moving average on the price chart as the confirmation before acting.
The maths
MFI compares the sum of volume-weighted typical price on up bars with the same sum on down bars over the lookback, and scales the ratio to 0 to 100.
A bar counts as positive when its typical price is above the previous bar's typical price, negative when below, and drops out entirely when equal; the close is not used directly.
The sums are plain sums over the lookback, not Wilder's smoothing as in RSI, so the line reacts faster and steps when a heavy bar enters or leaves the window.
When there is no negative flow in the window the ratio is undefined and MFI is set to 100; the mirror case gives 0. Both happen on thin or one-directional data.
The implementation computes MFI from the typical price with a 14-bar lookback and fires on confirmed bars only, so the marks do not appear and vanish inside a bar.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| Length | 14 | A shorter lookback reaches the extremes more often and turns faster; a longer one stays in the middle of the range and flags only sustained flows. |
| Overbought | 80 | Raising it to 90 keeps only the rarest readings and cuts the number of short marks in a strong uptrend. |
| Oversold | 20 | Lowering it to 10 keeps only capitulation readings; raising it to 30 catches shallower dips at the cost of more false exits. |
In practice
- As a range fade: in a sideways market, a long is taken when MFI climbs back above 20 near the bottom of the range and a short when it drops back below 80 near the top, which is what the script marks.
- As a conviction check on breakouts: a breakout with MFI rising through 60 or 70 has money behind it; a breakout with MFI flat in the 40s is thin and treated with suspicion.
- As a divergence tool: a new price high with a lower MFI high warns that the advance is losing sponsorship, and the trade is tightened rather than added to.
- As a trend filter: readings holding above 50 keep the bias long and readings holding below 50 keep it short; entries against that bias are skipped.
- As a companion to RSI: when RSI and MFI disagree, the difference is volume, and an RSI extreme that MFI does not confirm is a move made on light participation.
- As an alert stream: the exits from the extremes are rare enough to alert on, and the script raises a long or short alert naming the level it crossed.
Where it goes wrong
- Shorting the first touch of 80 in an uptrend. The extreme can persist for many bars in a trend; wait for the drop back below the line and confirm on price.
- Using RSI levels. MFI ranges more widely than RSI, so 70 and 30 are ordinary readings; keep 80 and 20, or tighten to 90 and 10.
- Running it on tick-volume feeds. Without real volume the weighting is meaningless and the line is a rough RSI of typical price; use it on markets with traded size.
- Ignoring the window step. A big bar leaving the lookback moves MFI without any new information; check whether the change came from a new bar or an old one leaving.
Compared with
RSI. RSI measures the ratio of up closes to down closes with Wilder smoothing and no volume; MFI measures the same ratio on volume-weighted typical price with plain sums. RSI shows momentum, MFI shows momentum backed by money, and the gap between them is the volume story.
On-Balance Volume. OBV keeps an unbounded running total of signed volume with no lookback; MFI bounds the balance of flow over a fixed window between 0 and 100. OBV is read by shape and divergence, MFI by its extremes and the exits from them.
Stochastic Oscillator. The stochastic locates the close within the recent high-low range and ignores volume; MFI ignores where the close sits in the range and weights the move by volume. Both are bounded, but they measure different things and their extremes coincide only sometimes.
Relative Volume. Relative volume measures the size of one bar against its average and has no direction; MFI signs each bar's flow and balances it over a window. A relative volume spike tells you money arrived, MFI tells you which side it has been on.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
Is MFI better than RSI?
It is different, not better. RSI reads price momentum alone and is smoother; MFI weights the same moves by volume and is jumpier. When both agree the move has momentum and participation. When RSI is overbought and MFI is not, the rally is light on volume; when MFI is overbought and RSI is not, a few heavy bars did the work. Use the disagreement.
Why is MFI so much more volatile than RSI?
Two reasons. It uses plain sums over the lookback instead of Wilder's smoothing, so each new bar has full weight, and it multiplies by volume, so one heavy bar can dominate the window. That is why a big bar entering or leaving the 14-bar window moves the line without any change in price.
What are the right overbought and oversold levels?
Eighty and 20 are standard and the implementation's defaults. In strong trends the line spends long spells beyond them, so some traders move to 90 and 10 to keep only climactic readings. Test the levels on the market you trade: a volatile small stock lives in the extremes more than an index future does.
Does MFI work on forex or crypto?
On crypto, yes, where the exchange reports traded volume. On spot forex most feeds report tick counts, which turns the weighting into an activity count and makes MFI little more than a rough RSI of typical price. Currency futures have real volume and read normally.
How does an MFI rule work?
It waits for the exit from the extreme: a cross back above 20 for a long, a cross back below 80 for a short, then a confirmation on price with a level, a reversal candle or a moving average. It enters with a stop beyond the recent swing and exits as MFI returns towards 50 or price reaches the next level.
Can MFI stay overbought for a long time?
Yes. In a strong trend with volume behind it MFI can hold above 80 for many bars, and each dip below and return above the line is a continuation, not a top. Read the regime first: the extremes are reversion zones in ranges and trend confirmation in trends.