Supported Indicators

Mc Clellan Summation Index

Introduction

The McClellan Summation Index (MSI) is a market breadth indicator that is based on the rolling average of difference between the number of advancing and declining issues on a stock exchange. It is generally considered as is a long-term version of the

To view the implementation of this indicator, see the LEAN GitHub repository.

Using MSI Indicator

To create an automatic indicators for McClellanSummationIndex, call the MSI helper method from the QCAlgorithm class. The MSI method creates a McClellanSummationIndex object, hooks it up for automatic updates, and returns it so you can used it in your algorithm. In most cases, you should call the helper method in the Initializeinitialize method.

public class McClellanSummationIndexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _reference;
    private McClellanSummationIndex _msi;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _reference = AddEquity("QQQ", Resolution.Daily).Symbol;
        _msi = MSI([_symbol, reference]);
    }

    public override void OnData(Slice data)
    {
        if (_msi.IsReady)
        {
            // The current value of _msi is represented by itself (_msi)
            // or _msi.Current.Value
            Plot("McClellanSummationIndex", "msi", _msi);
            // Plot all properties of msi
            Plot("McClellanSummationIndex", "mcclellanoscillator", _msi.McClellanOscillator);
        }
    }
}
class McClellanSummationIndexAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.reference = self.AddEquity("QQQ", Resolution.Daily).Symbol
        self.msi = self.MSI([self.symbol, reference])

    def on_data(self, slice: Slice) -> None:
        if self.msi.IsReady:
            # The current value of self.msi is represented by self.msi.Current.Value
            self.plot("McClellanSummationIndex", "msi", self.msi.Current.Value)
            # Plot all attributes of self.msi
            self.plot("McClellanSummationIndex", "mcclellanoscillator", self.msi.McClellanOscillator.Current.Value)

The following reference table describes the MSI method:

MSI()1/2

            McClellanSummationIndex QuantConnect.Algorithm.QCAlgorithm.MSI (
    IEnumerable<Symbol>         symbols,
    *Int32                            fastPeriod,
    *Int32                            slowPeriod,
    *Nullable<Resolution>       resolution,
    *Func<IBaseData, TradeBar>  selector
   )
        

Creates a new McClellan Summation Index indicator.

MSI()2/2

            McClellanSummationIndex QuantConnect.Algorithm.QCAlgorithm.MSI (
    Symbol>                        symbols,
    *Int32                            fastPeriod,
    *Int32                            slowPeriod,
    *Nullable<Resolution>       resolution,
    *Func<IBaseData, TradeBar>  selector
   )
        

Creates a new McClellan Summation Index indicator.

If you don't provide a resolution, it defaults 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.

For more information about plotting indicators, see Plotting Indicators.

You can manually create a McClellanSummationIndex indicator, so it doesn't automatically update. Manual indicators let you update their values with any data you choose.

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 Updateupdate method with a TradeBar. The indicator will only be ready after you prime it with enough data.

public class McClellanSummationIndexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _reference;
    private McClellanSummationIndex _msi;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _reference = AddEquity("QQQ", Resolution.Daily).Symbol;
        _msi = new McClellanSummationIndex("");
    }

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _msi.Update(bar);
        }
        if (data.Bars.TryGetValue(_reference, out bar))
        {      
            _msi.Update(bar);
        }
   
        if (_msi.IsReady)
        {
            // The current value of _msi is represented by itself (_msi)
            // or _msi.Current.Value
            Plot("McClellanSummationIndex", "msi", _msi);
            // Plot all properties of msi
            Plot("McClellanSummationIndex", "mcclellanoscillator", _msi.McClellanOscillator);
        }
    }
}
class McClellanSummationIndexAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.reference = self.AddEquity("QQQ", Resolution.Daily).Symbol
        self.msi = McClellanSummationIndex("")

    def on_data(self, slice: Slice) -> None:
        bar = slice.Bars.get(self.symbol)
        if bar:
            self.msi.Update(bar)
        bar = slice.Bars.get(self.referece)
        if bar:
            self.msi.Update(bar)
        if self.msi.IsReady:
            # The current value of self.msi is represented by self.msi.Current.Value
            self.plot("McClellanSummationIndex", "msi", self.msi.Current.Value)
            # Plot all attributes of self.msi
            self.plot("McClellanSummationIndex", "mcclellanoscillator", self.msi.McClellanOscillator.Current.Value)

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

public class McClellanSummationIndexAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _reference;
    private McClellanSummationIndex _msi;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _reference = AddEquity("QQQ", Resolution.Daily).Symbol;
        _msi = new McClellanSummationIndex("");
        RegisterIndicator(_symbol, _msi, Resolution.Daily);
        RegisterIndicator(reference, _msi, Resolution.Daily);
    }

    public override void OnData(Slice data)
    {
        if (_msi.IsReady)
        {
            // The current value of _msi is represented by itself (_msi)
            // or _msi.Current.Value
            Plot("McClellanSummationIndex", "msi", _msi);
            // Plot all properties of msi
            Plot("McClellanSummationIndex", "mcclellanoscillator", _msi.McClellanOscillator);
        }
    }
}
class McClellanSummationIndexAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.reference = self.AddEquity("QQQ", Resolution.Daily).Symbol
        self.msi = McClellanSummationIndex("")
        self.RegisterIndicator(self.symbol, self.msi, Resolution.Daily)
        self.RegisterIndicator(reference, self.msi, Resolution.Daily)

    def on_data(self, slice: Slice) -> None:
        if self.msi.IsReady:
            # The current value of self.msi is represented by self.msi.Current.Value
            self.plot("McClellanSummationIndex", "msi", self.msi.Current.Value)
            # Plot all attributes of self.msi
            self.plot("McClellanSummationIndex", "mcclellanoscillator", self.msi.McClellanOscillator.Current.Value)

The following reference table describes the McClellanSummationIndex constructor:

McClellanSummationIndex()1/2

            McClellanSummationIndex QuantConnect.Indicators.McClellanSummationIndex (
    string  name,
    *int    fastPeriod,
    *int    slowPeriod
   )
        

The slow period of EMA of advance decline difference.

McClellanSummationIndex()2/2

            McClellanSummationIndex QuantConnect.Indicators.McClellanSummationIndex (
    *int  fastPeriod,
    *int  slowPeriod
   )
        

The slow period of EMA of advance decline difference.

Visualization

The following image shows plot values of selected properties of McClellanSummationIndex using the plotly library.

McClellanSummationIndex line plot.

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: