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 indicator for AwesomeOscillator, call the AOao helper method from the QCAlgorithm class. The AOao 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 Initializeinitialize 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 abands
            Plot("AwesomeOscillator", "slowao", _ao.SlowAo);
            Plot("AwesomeOscillator", "fastao", _ao.FastAo);
        }
    }
}
class AwesomeOscillatorAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
        self._ao = self.ao(self._symbol, 10, 20, MovingAverageType.SIMPLE)

    def on_data(self, slice: Slice) -> None:

        if self._ao.is_ready:
            # 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", "slow_ao", self._ao.slow_ao.current.value)
            self.plot("AwesomeOscillator", "fast_ao", self._ao.fast_ao.current.value)

For more information about this method, see the QCAlgorithm classQCAlgorithm class.

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

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

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

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
            _awesomeoscillator.Update(bar);

        if (_awesomeoscillator.IsReady)
        {
            // The current value of _awesomeoscillator is represented by itself (_awesomeoscillator)
            // or _awesomeoscillator.Current.Value
            Plot("AwesomeOscillator", "awesomeoscillator", _awesomeoscillator);
            // Plot all properties of abands
            Plot("AwesomeOscillator", "slowao", _awesomeoscillator.SlowAo);
            Plot("AwesomeOscillator", "fastao", _awesomeoscillator.FastAo);
        }
    }
}
class AwesomeOscillatorAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
        self._awesomeoscillator = AwesomeOscillator(10, 20, MovingAverageType.SIMPLE)

    def on_data(self, slice: Slice) -> None:
        bar = slice.bars.get(self._symbol)
        if bar:
            self._awesomeoscillator.update(bar)

        if self._awesomeoscillator.is_ready:
            # The current value of self._awesomeoscillator is represented by self._awesomeoscillator.current.value
            self.plot("AwesomeOscillator", "awesomeoscillator", self._awesomeoscillator.current.value)
            # Plot all attributes of self._awesomeoscillator
            self.plot("AwesomeOscillator", "slow_ao", self._awesomeoscillator.slow_ao.current.value)
            self.plot("AwesomeOscillator", "fast_ao", self._awesomeoscillator.fast_ao.current.value)

For more information about this indicator, see its referencereference.

Visualization

The following plot shows values for some of the AwesomeOscillator indicator properties:

AwesomeOscillator line plot.

Indicator History

To get the historical data of the AwesomeOscillator indicator, call the IndicatorHistoryself.indicator_history method. This method resets your indicator, makes a history request, and updates the indicator with the historical data. Just like with regular history requests, the IndicatorHistoryindicator_history method supports time periods based on a trailing number of bars, a trailing period of time, or a defined period of time. If you don't provide a resolution argument, it defaults to match the resolution of the security subscription.

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);

        var indicatorHistory = IndicatorHistory(_ao, _symbol, 100, Resolution.Minute);
        var timeSpanIndicatorHistory = IndicatorHistory(_ao, _symbol, TimeSpan.FromDays(10), Resolution.Minute);
        var timePeriodIndicatorHistory = IndicatorHistory(_ao, _symbol, new DateTime(2024, 7, 1), new DateTime(2024, 7, 5), Resolution.Minute);

        // Access all attributes of indicatorHistory
        var slowAo = indicatorHistory.Select(x => ((dynamic)x).SlowAo).ToList();
        var fastAo = indicatorHistory.Select(x => ((dynamic)x).FastAo).ToList();
    }
}
class AwesomeOscillatorAlgorithm(QCAlgorithm):
    def initialize(self) -> None:
        self._symbol = self.add_equity("SPY", Resolution.DAILY).symbol
        self._ao = self.ao(self._symbol, 10, 20, MovingAverageType.SIMPLE)

        indicator_history = self.indicator_history(self._ao, self._symbol, 100, Resolution.MINUTE)
        timedelta_indicator_history = self.indicator_history(self._ao, self._symbol, timedelta(days=10), Resolution.MINUTE)
        time_period_indicator_history = self.indicator_history(self._ao, self._symbol, datetime(2024, 7, 1), datetime(2024, 7, 5), Resolution.MINUTE)
    
        # Access all attributes of indicator_history
        indicator_history_df = indicator_history.data_frame
        slow_ao = indicator_history_df["slowao"]
        fast_ao = indicator_history_df["fastao"]

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: