MFI (Money Flow Index)
The MFI is essentially RSI weighted by volume. It oscillates between 0 and 100, with readings above 80 suggesting overbought and below 20 suggesting oversold conditions.
Declaration
function init(ctx) { ctx.indicator('mfi', 'MFI', { period: 14 }); }
Options
| Option | Type | Default | Description |
|---|---|---|---|
period | number | 14 | Lookback period |
Output
Returns a single number[] series with values between 0 and 100.
Accessing Values
function onBar(ctx, i) { const mfi = ctx.ind.mfi[i]; }
Use Cases
Overbought / Oversold with Volume Confirmation
function onBar(ctx, i) { const mfi = ctx.ind.mfi[i]; // MFI accounts for volume, so signals carry more weight than RSI alone if (mfi < 20) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'mfi_oversold' }); } if (mfi > 80) { ctx.order.close('ASSET', { signal: 'sell', reason: 'mfi_overbought' }); } }
MFI + RSI Comparison
function init(ctx) { ctx.indicator('rsi', 'RSI', { period: 14 }); ctx.indicator('mfi', 'MFI', { period: 14 }); } function onBar(ctx, i) { const rsi = ctx.ind.rsi[i]; const mfi = ctx.ind.mfi[i]; // Both signaling oversold = stronger signal if (rsi < 30 && mfi < 20) { ctx.order.market('ASSET', 1, { signal: 'buy', reason: 'rsi_mfi_double_oversold' }); } }
Calculation
- Typical Price = (High + Low + Close) / 3
- Money Flow = Typical Price x Volume
- Positive/Negative flows separated by direction
- Money Flow Ratio = Positive Flow / Negative Flow
- $MFI = 100 - \frac{100}{1 + MFR}$
Related
indicatormfivolumemomentumoscillatorqsl