Supported Indicators

Mc Clellan Oscillator

Introduction

The McClellan Oscillator is a market breadth indicator which was developed by Sherman and Marian McClellan. It is based on the difference between the number of advancing and declining periods.

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

Using MOSC Indicator

To create an automatic indicators for McClellanOscillator, call the MOSC helper method from the QCAlgorithm class. The MOSC method creates a McClellanOscillator 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 McClellanOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _reference;
    private McClellanOscillator _mosc;

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

    public override void OnData(Slice data)
    {
        if (_mosc.IsReady)
        {
            // The current value of _mosc is represented by itself (_mosc)
            // or _mosc.Current.Value
            Plot("McClellanOscillator", "mosc", _mosc);
            // Plot all properties of mosc
            Plot("McClellanOscillator", "emafast", _mosc.EMAFast);
            Plot("McClellanOscillator", "emaslow", _mosc.EMASlow);
            Plot("McClellanOscillator", "addifference", _mosc.ADDifference);
        }
    }
}
class McClellanOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.reference = self.AddEquity("QQQ", Resolution.Daily).Symbol
        self.mosc = self.MOSC([self.symbol, reference])

    def on_data(self, slice: Slice) -> None:
        if self.mosc.IsReady:
            # The current value of self.mosc is represented by self.mosc.Current.Value
            self.plot("McClellanOscillator", "mosc", self.mosc.Current.Value)
            # Plot all attributes of self.mosc
            self.plot("McClellanOscillator", "emafast", self.mosc.EMAFast.Current.Value)
            self.plot("McClellanOscillator", "emaslow", self.mosc.EMASlow.Current.Value)
            self.plot("McClellanOscillator", "addifference", self.mosc.ADDifference.Current.Value)

The following reference table describes the MOSC method:

MOSC()1/2

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

Creates a new McClellan Oscillator indicator.

MOSC()2/2

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

Creates a new McClellan Oscillator 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 McClellanOscillator 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 McClellanOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _reference;
    private McClellanOscillator _mosc;

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

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

    def on_data(self, slice: Slice) -> None:
        bar = slice.Bars.get(self.symbol)
        if bar:
            self.mosc.Update(bar)
        bar = slice.Bars.get(self.referece)
        if bar:
            self.mosc.Update(bar)
        if self.mosc.IsReady:
            # The current value of self.mosc is represented by self.mosc.Current.Value
            self.plot("McClellanOscillator", "mosc", self.mosc.Current.Value)
            # Plot all attributes of self.mosc
            self.plot("McClellanOscillator", "emafast", self.mosc.EMAFast.Current.Value)
            self.plot("McClellanOscillator", "emaslow", self.mosc.EMASlow.Current.Value)
            self.plot("McClellanOscillator", "addifference", self.mosc.ADDifference.Current.Value)

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

public class McClellanOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private Symbol _reference;
    private McClellanOscillator _mosc;

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

    public override void OnData(Slice data)
    {
        if (_mosc.IsReady)
        {
            // The current value of _mosc is represented by itself (_mosc)
            // or _mosc.Current.Value
            Plot("McClellanOscillator", "mosc", _mosc);
            // Plot all properties of mosc
            Plot("McClellanOscillator", "emafast", _mosc.EMAFast);
            Plot("McClellanOscillator", "emaslow", _mosc.EMASlow);
            Plot("McClellanOscillator", "addifference", _mosc.ADDifference);
        }
    }
}
class McClellanOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.reference = self.AddEquity("QQQ", Resolution.Daily).Symbol
        self.mosc = McClellanOscillator("")
        self.RegisterIndicator(self.symbol, self.mosc, Resolution.Daily)
        self.RegisterIndicator(reference, self.mosc, Resolution.Daily)

    def on_data(self, slice: Slice) -> None:
        if self.mosc.IsReady:
            # The current value of self.mosc is represented by self.mosc.Current.Value
            self.plot("McClellanOscillator", "mosc", self.mosc.Current.Value)
            # Plot all attributes of self.mosc
            self.plot("McClellanOscillator", "emafast", self.mosc.EMAFast.Current.Value)
            self.plot("McClellanOscillator", "emaslow", self.mosc.EMASlow.Current.Value)
            self.plot("McClellanOscillator", "addifference", self.mosc.ADDifference.Current.Value)

The following reference table describes the McClellanOscillator constructor:

McClellanOscillator()1/2

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

The slow period of EMA of advance decline difference.

McClellanOscillator()2/2

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

The slow period of EMA of advance decline difference.

Visualization

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

McClellanOscillator 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: