Money Flow Index (mfi)
[[mfi]] (Money Flow Index) combines changes in source with traded volume over a window of length values. Each candle contributes a money flow equal to source × volume. The flow is classified as positive when source rises from its previous value and negative when it falls.
The block accumulates the two categories separately and compares them to produce the MFI series. As long as source stays positive and the result is defined, MFI follows its conventional 0 to 100 scale: high values mean positive flow dominates, low values mean negative flow dominates, and values near the midpoint mean the two flows are similar in magnitude.
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 = 14Specifying 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 = 2Parameters
| Parameter | Description |
|---|---|
idString Required | Unique name for the MFI series. |
sourceString 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" |
lengthInteger 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) |
symbolString 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. |
timeframeString 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 = 14Then:
| Variable | Description |
|---|---|
mfi or mfi[0]Decimal | Current MFI value. |
mfi[n]Decimal | MFI value from n candles ago. |
mfi.lengthDecimal | Window length in use. |
mfi.sourceString | Input series name. |
mfi.volume_sourceString | Name of the volume series used. |
mfi.symbolString | Symbol used. |
mfi.timeframeString | Timeframe used. |
Notes
- If cumulative negative flow over the window is zero, the MFI value is unavailable (
NaN). - If
sourcechanges sign, individual flow contributions can change sign as well, and the output may move outside the conventional0to100range.