Indicator Reference

Money Flow Index

Introduction

The Money Flow Index (MFI) is an oscillator that uses both price and volume to measure buying and selling pressure Typical Price = (High + Low + Close)/3 Money Flow = Typical Price x Volume Positive Money Flow = Sum of the money flows of all days where the typical price is greater than the previous day's typical price Negative Money Flow = Sum of the money flows of all days where the typical price is less than the previous day's typical price Money Flow Ratio = (14-period Positive Money Flow)/(14-period Negative Money Flow) Money Flow Index = 100 x Positive Money Flow / ( Positive Money Flow + Negative Money Flow)

Create Manual Indicators

You can manually create a MoneyFlowIndex indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the MoneyFlowIndex constructor.

MoneyFlowIndex()1/2

            MoneyFlowIndex QuantConnect.Indicators.MoneyFlowIndex (
     int  period
   )
        

Initializes a new instance of the MoneyFlowIndex class.

MoneyFlowIndex()2/2

            MoneyFlowIndex QuantConnect.Indicators.MoneyFlowIndex (
     string  name,
     int     period
   )
        

Initializes a new instance of the MoneyFlowIndex class.

Update Manual Indicators

You can update the indicator automatically or manually.

Automatic Update

To register a manual indicator for automatic updates with the security data, call the RegisterIndicator method.


private MoneyFlowIndex _mfi;

// In Initialize()
_mfi = new MoneyFlowIndex(name, period);
_mfi.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _mfi, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_mfi.IsReady)
{
    var indicatorValue = _mfi.Current.Value;
}
    
# In Initialize()
self.mfi = MoneyFlowIndex(name, period)
self.mfi.Updated += self.IndicatorUpdateMethod

self.RegisterIndicator(symbol, self.mfi, Resolution.Daily)

# In IndicatorUpdateMethod()
if self.mfi.IsReady:
    indicator_value = self.mfi.Current.Value

To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.

Manual Update

Updating your indicator manually enables you to control when the indicator is updated and what data you use to update it. To manually update the indicator, call the Update method with a TradeBar. The indicator will only be ready after you prime it with enough data.

    
private MoneyFlowIndex _mfi;
private Symbol symbol;

// In Initialize()
_mfi = new MoneyFlowIndex(period);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.Bars.ContainsKey(_symbol))
{
    _mfi.Update(data.Bars[symbol]);
}
if (_mfi.IsReady)
{
    var indicatorValue = _mfi.Current.Value;
}
    
# In Initialize()
self.mfi = MoneyFlowIndex(period)
self.symbol = self.AddEquity("SPY").Symbol

# In OnData()
if data.Bars.ContainsKey(self.symbol):
    self.mfi.Update(data.Bars[self.symbol])
if self.mfi.IsReady:
    indicator_value = self.mfi.Current.Value

Create Automatic Indicators

The MFI method creates an MoneyFlowIndex indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.

The following reference table describes the MFI method:

MFI()1/1

            MoneyFlowIndex QuantConnect.Algorithm.QCAlgorithm.MFI (
    Symbol                            symbol,
    Int32                             period,
    *Nullable<Resolution>       resolution,
    *Func<IBaseData, TradeBar>  selector
   )
        

Creates a new MoneyFlowIndex indicator. The indicator will be automatically updated on the given resolution.


If you don't provide a resolution, it defauls to the security resolution. If you provide a resolution, it must be greater than or equal to the resolution of the security. For instance, if you subscribe to hourly data for a security, you should update its indicator with data that spans 1 hour or longer.

For more information about the selector argument, see Alternative Price Fields.

Get Indicator Values

To get the value of the indicator, use its Current.Value attribute.

private MoneyFlowIndex _mfi;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_mfi = MFI(symbol, period);

// In OnData()
if (_mfi.IsReady)
{
    var positiveMoneyFlow = _mfi.PositiveMoneyFlow.Current.Value;
    var negativeMoneyFlow = _mfi.NegativeMoneyFlow.Current.Value;
    var previousTypicalPrice = _mfi.PreviousTypicalPrice.Current.Value;
    var current = _mfi.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.mfi = self.MFI(symbol, period)

# In OnData()
if self.mfi.IsReady:
    positive_money_flow = self.mfi.PositiveMoneyFlow.Current.Value
    negative_money_flow = self.mfi.NegativeMoneyFlow.Current.Value
    previous_typical_price = self.mfi.PreviousTypicalPrice.Current.Value
    current = self.mfi.Current.Value

Visualization

To plot indicator values, in the OnData event handler, call the Plot method.

private MoneyFlowIndex _mfi;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_mfi = MFI(symbol, period);

// In OnData()
if (_mfi.IsReady)
{
    Plot("My Indicators", "positivemoneyflow", _mfi.PositiveMoneyFlow);
    Plot("My Indicators", "negativemoneyflow", _mfi.NegativeMoneyFlow);
    Plot("My Indicators", "previoustypicalprice", _mfi.PreviousTypicalPrice);
    Plot("My Indicators", "moneyflowindex", _mfi.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.mfi = self.MFI(symbol, period)

# In OnData()
if self.mfi.IsReady:
    self.Plot("My Indicators", "positivemoneyflow", self.mfi.PositiveMoneyFlow)
    self.Plot("My Indicators", "negativemoneyflow", self.mfi.NegativeMoneyFlow)
    self.Plot("My Indicators", "previoustypicalprice", self.mfi.PreviousTypicalPrice)
    self.Plot("My Indicators", "moneyflowindex", self.mfi.Current)

For more information about plotting indicators, see Plotting Indicators.

You can also see our Videos. You can also get in touch with us via Discord.

Did you find this page helpful?

Contribute to the documentation: