DocsStrategy APIindicators

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

OptionTypeDefaultDescription
periodnumber14Lookback 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

  1. Typical Price = (High + Low + Close) / 3
  2. Money Flow = Typical Price x Volume
  3. Positive/Negative flows separated by direction
  4. Money Flow Ratio = Positive Flow / Negative Flow
  5. $MFI = 100 - \frac{100}{1 + MFR}$

Related

  • RSI - Price-only momentum oscillator
  • OBV - Cumulative volume indicator
  • VWAP - Volume Weighted Average Price
indicatormfivolumemomentumoscillatorqsl