Indicator Reference

Chaikin Money Flow

Introduction

The Chaikin Money Flow Index (CMF) is a volume-weighted average of accumulation and distribution over a specified period. CMF = n-day Sum of [(((C - L) - (H - C)) / (H - L)) x Vol] / n-day Sum of Vol Where: n = number of periods, typically 21 H = high L = low C = close Vol = volume https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/cmf

Create Manual Indicators

You can manually create a ChaikinMoneyFlow 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 ChaikinMoneyFlow constructor.

ChaikinMoneyFlow()1/1

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

Initializes a new instance of the ChaikinMoneyFlow 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 ChaikinMoneyFlow _cmf;

// In Initialize()
_cmf = new ChaikinMoneyFlow(name, period);
_cmf.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _cmf, Resolution.Daily);

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

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

# In IndicatorUpdateMethod()
if self.cmf.IsReady:
    indicator_value = self.cmf.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 ChaikinMoneyFlow _cmf;
private Symbol symbol;

// In Initialize()
_cmf = new ChaikinMoneyFlow(period);
symbol = AddEquity("SPY").Symbol;

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

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

Create Automatic Indicators

The CMF method creates an ChaikinMoneyFlow 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 CMF method:

CMF()1/1

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

Creates a new ChaikinMoneyFlow indicator.


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 ChaikinMoneyFlow _cmf;

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

// In OnData()
if (_cmf.IsReady)
{
    var current = _cmf.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.cmf = self.CMF(symbol, period)

# In OnData()
if self.cmf.IsReady:
    current = self.cmf.Current.Value

Visualization

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

private ChaikinMoneyFlow _cmf;

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

// In OnData()
if (_cmf.IsReady)
{
    Plot("My Indicators", "chaikinmoneyflow", _cmf.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.cmf = self.CMF(symbol, period)

# In OnData()
if self.cmf.IsReady:
    self.Plot("My Indicators", "chaikinmoneyflow", self.cmf.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: