VariablePeriodMFI
Background
The Money Flow Index (MFI) is a momentum oscillator that brings volume into the picture. It works much like the RSI, but instead of looking at price changes alone it weights each bar by the raw money flow (price multiplied by volume). Because of this it is sometimes called a "volume-weighted RSI." Readings run from 0 to 100, and the oscillator is used to gauge buying and selling pressure behind a move.
A standard MFI uses a fixed look-back. VariablePeriodMFI takes a
period for each bar, letting the window adapt to market conditions.
The per-bar periods normally come from an adaptor such as the
DominantCycle. This implementation uses the current chart's
volume internally, so only price and the periods array are passed in.
Included formula
The toolbox ships a ready-made Adaptive Smoothed MFI indicator built on this function, so you can use it without writing any code. In AmiBroker open the Charts window, expand the WiseTraderToolbox group and drag Adaptive Smoothed MFI onto a chart.
It plots the Money Flow Index in its own pane below price. The Adaptor you pick is what produces the per-bar period this function needs — so the look-back adapts to the market — and an optional Smoother cleans up the input first. The adaptor's bounds, the smoothing and the colours are all set from the indicator's parameters.
The exported function
If you would rather build your own formula, the toolbox exports the calculation as a single AFL function you can call directly — it is the engine inside that indicator.
VariablePeriodMFI(Price, Periods)
| Parameter | Description |
|---|---|
| Price | The price array the indicator is calculated on. The typical price
(High + Low + Close) / 3 is a common choice. |
| Periods | An array (or value) giving the MFI period to use at each bar. Most often this
is fed from an adaptor such as the DominantCycle. |
Usage
periods = DominantCycle( Close );
mfi = VariablePeriodMFI( ( High + Low + Close ) / 3, periods );
Plot( mfi, "Adaptive MFI", colorRed );
Plot( 80, "", colorGrey40, styleDashed | styleNoLabel );
Plot( 20, "", colorGrey40, styleDashed | styleNoLabel );
A reading of 80 is generally considered overbought and 20 oversold. Divergences are also watched: if price makes a new high but the MFI high is lower than its previous peak, that may signal a weak advance that is likely to reverse.