Volume / MomentumPine Script v6

Money Flow Index Pine Script — Complete TradingView Guide

The Money Flow Index (MFI) is a volume-weighted momentum oscillator built into Pine Script v6 via ta.mfi(source, length). It ranges from 0 to 100 and combines typical price (hlc3) with volume to measure buying and selling pressure — making it a more comprehensive signal than RSI, which ignores volume entirely. MFI readings above 80 indicate overbought conditions, while readings below 20 indicate oversold conditions. Developed by Gene Quong and Avrum Soudack, MFI works across stocks, crypto, and futures on timeframes from 1H to Daily. This guide provides the complete Pine Script v6 implementation, a full parameter table, three concrete trading strategies using MFI divergence and threshold crossovers, and a step-by-step walkthrough for generating a customised MFI indicator instantly with Pineify.

What Is the Money Flow Index?

The Money Flow Index (MFI) is a volume-weighted oscillator that measures buying and selling pressure on a 0–100 scale, used to identify overbought/oversold conditions and price divergence. MFI was developed by Gene Quong and Avrum Soudack and first published in the early 1990s. Unlike the RSI — which relies solely on price — MFI weights each period's money flow by the trading volume, giving a fuller picture of market conviction behind a price move.

The calculation begins with the Typical Price: TP = (High + Low + Close) / 3. Raw Money Flow for each bar is RMF = TP × Volume. Bars where TP is higher than the previous bar's TP contribute to Positive Money Flow; bars where TP is lower contribute to Negative Money Flow. Over the lookback period: MFR = Sum(Positive MF, length) / Sum(Negative MF, length), and finally MFI = 100 − (100 / (1 + MFR)).

In Pine Script v6, the entire formula is encapsulated in the built-in function ta.mfi(source, length), where source is typically hlc3 (the built-in typical price series) and length is the lookback period in bars (default 14). The function automatically accesses the current bar's volume series — no separate volume argument is needed.

MFI is most effective in markets with genuine volume reporting: US equities, equity futures, and crypto on centralised exchanges. For forex spot, tick volume is used as a proxy and signals are less reliable. The sweet spot for timeframes is 1H to Daily. On shorter timeframes (1m–5m), the 14-bar window spans too few price events; on weekly charts it covers 14 weeks and is better suited to longer-horizon position analysis.

Best Markets

Stocks · Crypto · Futures

Best Timeframes

1H, 4H, Daily

Oscillator Range

0–100 (OB: 80, OS: 20)

Money Flow Index Pine Script Code

The code below calculates MFI using ta.mfi(hlc3, 14) and plots it in a separate pane with overbought (80) and oversold (20) horizontal reference lines and a shaded background. To add it to TradingView, open the Pine Script editor with Alt+P, paste the code, and click Add to chart. Change the 14 to any period that fits your trading style.

Pine Script v6
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify

//@version=6
indicator(title="Money Flow Index", overlay=false, max_labels_count=500)

// MFI — calculated on typical price (hlc3) with a 14-bar period
p_ind_1 = ta.mfi(hlc3, 14) // MFI

// Plot the MFI line
plot(p_ind_1, "MFI", color.rgb(126, 87, 194, 0), 1)

// Overbought / Oversold reference lines
p_ind_1_ob = hline(80, "MFI - Overbought", color=#787B86)
hline(50, "MFI - Middle Band", color=color.new(#787B86, 50))
p_ind_1_os = hline(20, "MFI - Oversold", color=#787B86)
fill(p_ind_1_ob, p_ind_1_os, color=color.rgb(126, 87, 194, 90), title="MFI - Background")

Chart Preview

Money Flow Index indicator Pine Script code example in TradingView

MFI Parameters

ParameterDefault ValueDescriptionRecommended Range
sourcehlc3The price series used as the Typical Price. Standard convention is hlc3 = (High + Low + Close) / 3. Can also accept close or any custom series.hlc3 (standard) or close
length14Number of bars in the lookback window for summing Positive and Negative Money Flow. Smaller values produce faster, noisier signals; larger values produce smoother, slower signals.7–21 depending on timeframe
overbought80Horizontal reference line signalling potential overbought conditions. MFI crossing below this level from above is a sell signal in many strategies.75–85
oversold20Horizontal reference line signalling potential oversold conditions. MFI crossing above this level from below is a buy signal in many strategies.15–25

Tuning Guide by Trading Style

  • Scalping (1m–5m charts): length 7–10 — faster response, use tighter thresholds (75/25) to reduce false signals
  • Day trading (15m–1H charts): length 14 — the standard setting; default 80/20 thresholds work well
  • Swing trading (4H–Daily charts): length 14–21 — use 80/20 thresholds; focus on divergence signals rather than threshold touches
  • Position trading (Daily–Weekly): length 21 — fewer but more reliable signals; combine with a 200-period SMA trend filter

Trading Strategies Using the Money Flow Index

The Money Flow Index generates the most reliable signals when used as a confirmation tool rather than a standalone entry trigger. Below are three concrete strategies with specific entry and exit conditions.

Strategy 1 — MFI Oversold Bounce (Mean-Reversion)

Market environment: ranging or mildly trending · Best timeframe: 1H, 4H

This strategy buys when MFI exits oversold territory and the price structure supports a bounce. Pair ta.mfi(hlc3, 14) with a 50-period EMA to confirm the broader trend direction.

  1. Calculate MFI: mfi = ta.mfi(hlc3, 14)
  2. Calculate trend filter: ema50 = ta.ema(close, 50)
  3. Long entry: MFI crosses above 20 (from below) AND close > ema50
  4. Stop loss: below the most recent swing low (prior 5 bars)
  5. Exit: MFI reaches 70 or price touches the 50 EMA from above

Strategy 2 — MFI Bullish Divergence Entry

Market environment: downtrend nearing exhaustion · Best timeframe: 4H, Daily

Bullish divergence — price makes a lower low while MFI makes a higher low — indicates that selling volume is drying up despite lower prices. Combine with a 200-period SMA to ensure you are not fighting a strong macro downtrend.

  1. Identify a price swing low below the prior swing low: low < low[10]
  2. Confirm MFI made a higher low: ta.mfi(hlc3, 14) > ta.mfi(hlc3, 14)[10]
  3. Long entry: both conditions true AND close > 200-bar SMA for macro bullish bias
  4. Stop loss: 1 ATR(14) below the recent swing low
  5. Target: 2× risk (2:1 reward-to-risk ratio); exit if MFI crosses above 80

Strategy 3 — MFI Overbought Rejection + MACD Confirmation

Market environment: trending market near resistance · Best timeframe: 1H, 4H

MFI overbought crossovers are more reliable when confirmed by bearish MACD momentum. Combining ta.mfi(hlc3, 14) with ta.macd(close, 12, 26, 9) reduces false signals in choppy conditions.

  1. MFI crosses below 80 (from above): ta.crossunder(mfi, 80)
  2. MACD histogram turns negative: macdHist < 0
  3. Short entry: both conditions on the same bar or within 2 bars
  4. Stop loss: above the recent swing high (prior 5 bars) + 0.5 ATR buffer
  5. Exit: MFI drops below 30, or MACD histogram turns positive

Disclaimer: The strategies above are for educational purposes only and do not constitute investment advice. Past performance does not guarantee future results. Always apply proper risk management and position sizing.

How to Generate the Money Flow Index in Pineify

  1. 1

    Open Pineify

    Go to pineify.app and sign in — a free account gives you access to all built-in indicator generators including MFI.

  2. 2

    Click "New Indicator"

    Select "Indicator" as the script type from the creation menu to start with a clean Pine Script v6 template.

  3. 3

    Describe the Money Flow Index configuration you need

    Type a prompt such as: "Add a Money Flow Index with period 14 on hlc3, plot overbought at 80 and oversold at 20, and add an alert when MFI crosses below 80." Pineify's AI Coding Agent generates the complete Pine Script v6 code in seconds.

  4. 4

    Copy the generated code to TradingView

    Click "Copy to TradingView" to copy the code, then paste it into the TradingView Pine Script editor (Alt+P) and click "Add to chart". The MFI panel appears immediately below the price chart.

  5. 5

    Adjust parameters in the indicator settings

    Open the indicator settings panel in TradingView to change the MFI period, overbought/oversold thresholds, or line colours — no code editing required.

Frequently Asked Questions

Build Your Money Flow Index Indicator in Seconds

Skip the manual coding. Pineify's AI Coding Agent generates complete, ready-to-use Pine Script indicators — including MFI with divergence detection and alerts — instantly for free.

Try Pineify Free