Money Flow Index (mfi)

[[mfi]] is a momentum oscillator that combines price and volume to identify potential overbought and oversold conditions.

It compares the sum of positive money flow and the sum of negative money flow over a window of length bars. It returns values between zero and one hundred.

The implementation follows precise rules for direction, windowing, and unavailable values. The default source is hlc3.

Block declaration

A strategy can contain multiple [[mfi]] blocks. Each block outputs one numeric series: the MFI value.

Examples

Minimal setup

[[mfi]]
id     = "mfi"
source = "hlc3"
length = 14

Specifying symbol and timeframe

This block computes MFI on daily candles for BINANCE:BTCUSDT.

[[mfi]]
id        = "mfi"
source    = "hlc3"
length    = 14
symbol    = "BINANCE:BTCUSDT"
timeframe = "D"

Finding the optimal length

This block explores a range of values for length to identify the best-performing length.

[[mfi]]
id           = "mfi"
source       = "hlc3"
length.start = 10
length.stop  = 30
length.step  = 2

Parameters

ParameterDescription
id
 String
 Required
Unique name for the MFI series.
source
 String
 or Array
 Optional
Input series used for the calculation.
Accepted forms: source = "hl2" or source = ["close", "hl2"].
Each value can be either a standard price source (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume) or the id of another indicator.
Default value: "hlc3"
length
 Integer
 Required
Window length; must be ≥ 1.

Usage:
• Fixed: length = value
• Grid search:
 – length.start = min_value
 – length.stop = max_value
 – length.step = value (optional, default 1)
symbol
 String or Array
 Optional
Market symbol(s) used when source only consists of standard prices (open, close, high, low, hl2, hlc3, ohlc4, hlcc4, volume).
If source mixes standard prices and indicator ids, symbol is applied only to combinations based on standard prices.
If source contains only indicator ids, symbol is ignored.
If omitted, the block inherits the [backtest] symbol.
For symbol format, arrays, and alignment rules, see Exchanges, Symbols and Timeframes.
timeframe
 String or Array
 Optional
Timeframe on which this indicator is computed.
If timeframe is omitted, the computation uses the grid’s main timeframe defined in [backtest].
For accepted formats and timeframe alignment rules, see Exchanges, Symbols and Timeframes.

Available variables

Use the identifiers below directly in your expressions. The MFI block exposes its numeric series and input metadata.

Assume the block is configured as:

[[mfi]]
id     = "mfi"
source = "hlc3"
length = 14

Then:

VariableDescription
mfi or mfi[0]
Decimal
Current MFI value.
mfi[n]
Decimal
MFI value from n candles ago.
mfi.length
Decimal
Window length in use.
mfi.source
String
Input series name.
mfi.symbol
String
Symbol used.
mfi.timeframe
String
Timeframe used.