Supported Indicators

Absolute Price Oscillator

Introduction

This indicator computes the Absolute Price Oscillator (APO) The Absolute Price Oscillator is calculated using the following formula: APO[i] = FastMA[i] - SlowMA[i]

Create Manual Indicators

You can manually create a AbsolutePriceOscillator indicator, so it doesn’t automatically update. Manual indicators let you update their values with any data you choose. The following reference table describes the AbsolutePriceOscillator constructor.

AbsolutePriceOscillator()1/2

            AbsolutePriceOscillator QuantConnect.Indicators.AbsolutePriceOscillator (
     string              name,
     int                 slowPeriod,
     *MovingAverageType  movingAverageType
   )
        

Initializes a new instance of the AbsolutePriceOscillator class using the specified name and parameters.

AbsolutePriceOscillator()2/2

            AbsolutePriceOscillator QuantConnect.Indicators.AbsolutePriceOscillator (
     int                 slowPeriod,
     *MovingAverageType  movingAverageType
   )
        

Initializes a new instance of the AbsolutePriceOscillator class using the specified parameters.

The following table shows the MovingAverageType enumeration members and the indicator that implements each one:

MovingAverageTypeUnderlying Indicator
SimpleSimple Moving Average
ExponentialExponential Moving Average
WildersWilder Moving Average
LinearWeightedMovingAverageLinear Weighted Moving Average
DoubleExponentialDouble Exponential Moving Average
TripleExponentialTriple Exponential Moving Average
TriangularTriangular Moving Average
T3T3 Moving Average
KamaKaufman Adaptive Moving Average
HullHull Moving Average
AlmaArnaud Legoux Moving Average

Update Manual Indicators

You can update the indicator automatically or manually.

Automatic Update

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


private AbsolutePriceOscillator _apo;

// In Initialize()
_apo = new AbsolutePriceOscillator(name, fastPeriod, slowPeriod);
_apo.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _apo, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_apo.IsReady)
{
    var indicatorValue = _apo.Current.Value;
}
    
# In Initialize()
self.apo = AbsolutePriceOscillator(name, fastPeriod, slowPeriod)
self.apo.Updated += self.IndicatorUpdateMethod

self.RegisterIndicator(symbol, self.apo, Resolution.Daily)

# In IndicatorUpdateMethod()
if self.apo.IsReady:
    indicator_value = self.apo.Current.Value

To customize the data that automatically updates the indicator, see Custom Indicator Periods and Custom Indicator Values.

Manual Update

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 time/decimal pair. The indicator will only be ready after you prime it with enough data.

    
private AbsolutePriceOscillator _apo;
private Symbol symbol;

// In Initialize()
_apo = new AbsolutePriceOscillator(fastPeriod, slowPeriod);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.ContainsKey(_symbol))
{
    _apo.Update(data[symbol].EndTime, data[symbol].High);
}
if (_apo.IsReady)
{
    var indicatorValue = _apo.Current.Value;
}
    
# In Initialize()
self.apo = AbsolutePriceOscillator(fastPeriod, slowPeriod)
self.symbol = self.AddEquity("SPY").Symbol

# In OnData()
if data.ContainsKey(self.symbol):
    self.apo.Update(data[self.symbol].EndTime, data[self.symbol].High)
if self.apo.IsReady:
    indicator_value = self.apo.Current.Value

Create Automatic Indicators

The APO method creates an AbsolutePriceOscillator indicator, sets up a consolidator to update the indicator, and then returns the indicator so you can use it in your algorithm.

The following reference table describes the APO method:

APO()1/1

            AbsolutePriceOscillator QuantConnect.Algorithm.QCAlgorithm.APO (
    Symbol                           symbol,
    Int32                            fastPeriod,
    Int32                            slowPeriod,
    MovingAverageType                movingAverageType,
    *Nullable<Resolution>      resolution,
    *Func<IBaseData, Decimal>  selector
   )
        

Creates a new AbsolutePriceOscillator indicator.


The following table shows the MovingAverageType enumeration members and the indicator that implements each one:

MovingAverageTypeUnderlying Indicator
SimpleSimple Moving Average
ExponentialExponential Moving Average
WildersWilder Moving Average
LinearWeightedMovingAverageLinear Weighted Moving Average
DoubleExponentialDouble Exponential Moving Average
TripleExponentialTriple Exponential Moving Average
TriangularTriangular Moving Average
T3T3 Moving Average
KamaKaufman Adaptive Moving Average
HullHull Moving Average
AlmaArnaud Legoux Moving Average

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.

Get Indicator Values

To get the value of the indicator, use its Current.Value attribute.

private AbsolutePriceOscillator _apo;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_apo = APO(symbol, fastPeriod, slowPeriod, movingAverageType);

// In OnData()
if (_apo.IsReady)
{
    var fast = _apo.Fast.Current.Value;
    var slow = _apo.Slow.Current.Value;
    var signal = _apo.Signal.Current.Value;
    var histogram = _apo.Histogram.Current.Value;
    var current = _apo.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.apo = self.APO(symbol, fastPeriod, slowPeriod, movingAverageType)

# In OnData()
if self.apo.IsReady:
    fast = self.apo.Fast.Current.Value
    slow = self.apo.Slow.Current.Value
    signal = self.apo.Signal.Current.Value
    histogram = self.apo.Histogram.Current.Value
    current = self.apo.Current.Value

Visualization

To plot indicator values, in the OnData event handler, call the Plot method.

private AbsolutePriceOscillator _apo;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_apo = APO(symbol, fastPeriod, slowPeriod, movingAverageType);

// In OnData()
if (_apo.IsReady)
{
    Plot("My Indicators", "fast", _apo.Fast);
    Plot("My Indicators", "slow", _apo.Slow);
    Plot("My Indicators", "signal", _apo.Signal);
    Plot("My Indicators", "histogram", _apo.Histogram);
    Plot("My Indicators", "absolutepriceoscillator", _apo.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.apo = self.APO(symbol, fastPeriod, slowPeriod, movingAverageType)

# In OnData()
if self.apo.IsReady:
    self.Plot("My Indicators", "fast", self.apo.Fast)
    self.Plot("My Indicators", "slow", self.apo.Slow)
    self.Plot("My Indicators", "signal", self.apo.Signal)
    self.Plot("My Indicators", "histogram", self.apo.Histogram)
    self.Plot("My Indicators", "absolutepriceoscillator", self.apo.Current)

The following image shows the plot values in a matplotlib plot. To load algorithm plot data into the Research Environment, see Charts.

For more information about plotting indicators, see Plotting Indicators.

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: