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 Initialize
method.
public class McClellanOscillatorAlgorithm : QCAlgorithm { private Symbol _symbol; private McClellanOscillator _mosc; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _mosc = MOSC(["SPY", "QQQ"]); } 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.mosc = self.MOSC(["SPY", "QQQ"]) def OnData(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 Update
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 McClellanOscillator _mosc; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _mosc = new McClellanOscillator("QQQ"]); } public override void OnData(Slice data) { if (data.Bars.TryGeValue(_symbol, out var 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.mosc = McClellanOscillator("QQQ"]) def OnData(self, slice: Slice) -> None: bar = slice.Bars.get(self.symbol) 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 McClellanOscillator _mosc; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _mosc = new McClellanOscillator("QQQ"]); RegisterIndicator(_symbol, _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.mosc = McClellanOscillator("QQQ"]) self.RegisterIndicator(self.symbol, self.mosc, Resolution.Daily) def OnData(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.
