Supported Indicators

Awesome Oscillator

Introduction

The Awesome Oscillator Indicator tracks the price midpoint-movement of a security. Specifically, AO = MAfast[(H+L)/2] - MAslow[(H+L)/2] where MAfast and MAslow denote simple moving averages wherein fast has a shorter period. https://www.barchart.com/education/technical-indicators/awesome_oscillator

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

Using AO Indicator

To create an automatic indicators for AwesomeOscillator, call the AO helper method from the QCAlgorithm class. The AO method creates a AwesomeOscillator 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 AwesomeOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private AwesomeOscillator _ao;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _ao = AO(_symbol, 10, 20, MovingAverageType.Simple);
    }

    public override void OnData(Slice data)
    {
        if (_ao.IsReady)
        {
            // The current value of _ao is represented by itself (_ao)
            // or _ao.Current.Value
            Plot("AwesomeOscillator", "ao", _ao);
            // Plot all properties of ao
            Plot("AwesomeOscillator", "slowao", _ao.SlowAo);
            Plot("AwesomeOscillator", "fastao", _ao.FastAo);
        }
    }
}
class AwesomeOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.ao = self.AO(self.symbol, 10, 20, MovingAverageType.Simple)

    def OnData(self, slice: Slice) -> None:
        if self.ao.IsReady:
            # The current value of self.ao is represented by self.ao.Current.Value
            self.Plot("AwesomeOscillator", "ao", self.ao.Current.Value)
            # Plot all attributes of self.ao
            self.Plot("AwesomeOscillator", "slowao", self.ao.SlowAo.Current.Value)
            self.Plot("AwesomeOscillator", "fastao", self.ao.FastAo.Current.Value)

The following reference table describes the AO method:

AO()1/1

            AwesomeOscillator QuantConnect.Algorithm.QCAlgorithm.AO (
    Symbol                                symbol,
    Int32                                 slowPeriod,
    Int32                                 fastPeriod,
    MovingAverageType                     type,
    *Nullable<Resolution>           resolution,
    *Func<IBaseData, IBaseDataBar>  selector
   )
        

Creates a new Awesome Oscillator from the specified periods.

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 AwesomeOscillator 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 or QuoteBar. The indicator will only be ready after you prime it with enough data.

public class AwesomeOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private AwesomeOscillator _ao;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _ao = new AwesomeOscillator(10, 20, MovingAverageType.Simple);
    }

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _ao.Update(bar);
        }
   
        if (_ao.IsReady)
        {
            // The current value of _ao is represented by itself (_ao)
            // or _ao.Current.Value
            Plot("AwesomeOscillator", "ao", _ao);
            // Plot all properties of ao
            Plot("AwesomeOscillator", "slowao", _ao.SlowAo);
            Plot("AwesomeOscillator", "fastao", _ao.FastAo);
        }
    }
}
class AwesomeOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.ao = AwesomeOscillator(10, 20, MovingAverageType.Simple)

    def OnData(self, slice: Slice) -> None:
        bar = slice.Bars.get(self.symbol)
        if bar:
            self.ao.Update(bar)
        if self.ao.IsReady:
            # The current value of self.ao is represented by self.ao.Current.Value
            self.Plot("AwesomeOscillator", "ao", self.ao.Current.Value)
            # Plot all attributes of self.ao
            self.Plot("AwesomeOscillator", "slowao", self.ao.SlowAo.Current.Value)
            self.Plot("AwesomeOscillator", "fastao", self.ao.FastAo.Current.Value)

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

public class AwesomeOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private AwesomeOscillator _ao;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Daily).Symbol;
        _ao = new AwesomeOscillator(10, 20, MovingAverageType.Simple);
        RegisterIndicator(_symbol, _ao, Resolution.Daily);
    }

    public override void OnData(Slice data)
    {
        if (_ao.IsReady)
        {
            // The current value of _ao is represented by itself (_ao)
            // or _ao.Current.Value
            Plot("AwesomeOscillator", "ao", _ao);
            // Plot all properties of ao
            Plot("AwesomeOscillator", "slowao", _ao.SlowAo);
            Plot("AwesomeOscillator", "fastao", _ao.FastAo);
        }
    }
}
class AwesomeOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.ao = AwesomeOscillator(10, 20, MovingAverageType.Simple)
        self.RegisterIndicator(self.symbol, self.ao, Resolution.Daily)

    def OnData(self, slice: Slice) -> None:
        if self.ao.IsReady:
            # The current value of self.ao is represented by self.ao.Current.Value
            self.Plot("AwesomeOscillator", "ao", self.ao.Current.Value)
            # Plot all attributes of self.ao
            self.Plot("AwesomeOscillator", "slowao", self.ao.SlowAo.Current.Value)
            self.Plot("AwesomeOscillator", "fastao", self.ao.FastAo.Current.Value)

The following reference table describes the AwesomeOscillator constructor:

AwesomeOscillator()1/2

            AwesomeOscillator QuantConnect.Indicators.AwesomeOscillator (
    int  fastPeriod,
    int  slowPeriod
   )
        

Creates a new Awesome Oscillator from the specified periods.

AwesomeOscillator()2/2

            AwesomeOscillator QuantConnect.Indicators.AwesomeOscillator (
    string  name,
    int     fastPeriod,
    int     slowPeriod
   )
        

Creates a new Awesome Oscillator from the specified periods.

Visualization

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

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