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]
To view the implementation of this indicator, see the LEAN GitHub repository.
Using APO Indicator
To create an automatic indicators for AbsolutePriceOscillator
, call the APO
helper method from the QCAlgorithm
class. The APO
method creates a AbsolutePriceOscillator
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 AbsolutePriceOscillatorAlgorithm : QCAlgorithm { private Symbol _symbol; private AbsolutePriceOscillator _apo; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _apo = APO(_symbol, 10, 2, MovingAverageType.Simple); } public override void OnData(Slice data) { if (_apo.IsReady) { // The current value of _apo is represented by itself (_apo) // or _apo.Current.Value Plot("AbsolutePriceOscillator", "apo", _apo); // Plot all properties of apo Plot("AbsolutePriceOscillator", "fast", _apo.Fast); Plot("AbsolutePriceOscillator", "slow", _apo.Slow); Plot("AbsolutePriceOscillator", "signal", _apo.Signal); Plot("AbsolutePriceOscillator", "histogram", _apo.Histogram); } } }
class AbsolutePriceOscillatorAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.apo = self.APO(self.symbol, 10, 2, MovingAverageType.Simple) def OnData(self, slice: Slice) -> None: if self.apo.IsReady: # The current value of self.apo is represented by self.apo.Current.Value self.Plot("AbsolutePriceOscillator", "apo", self.apo.Current.Value) # Plot all attributes of self.apo self.Plot("AbsolutePriceOscillator", "fast", self.apo.Fast.Current.Value) self.Plot("AbsolutePriceOscillator", "slow", self.apo.Slow.Current.Value) self.Plot("AbsolutePriceOscillator", "signal", self.apo.Signal.Current.Value) self.Plot("AbsolutePriceOscillator", "histogram", self.apo.Histogram.Current.Value)
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.
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.
The following table describes the MovingAverageType
enumeration members:
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.
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/number pair, or an IndicatorDataPoint
. The indicator will only be ready after you prime it with enough data.
public class AbsolutePriceOscillatorAlgorithm : QCAlgorithm { private Symbol _symbol; private AbsolutePriceOscillator _apo; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _apo = new AbsolutePriceOscillator(10, 20, MovingAverageType.Simple); } public override void OnData(Slice data) { if (data.Bars.TryGeValue(_symbol, out var bar)) { _apo.Update(bar.EndTime, bar.Close); } if (_apo.IsReady) { // The current value of _apo is represented by itself (_apo) // or _apo.Current.Value Plot("AbsolutePriceOscillator", "apo", _apo); // Plot all properties of apo Plot("AbsolutePriceOscillator", "fast", _apo.Fast); Plot("AbsolutePriceOscillator", "slow", _apo.Slow); Plot("AbsolutePriceOscillator", "signal", _apo.Signal); Plot("AbsolutePriceOscillator", "histogram", _apo.Histogram); } } }
class AbsolutePriceOscillatorAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.apo = AbsolutePriceOscillator(10, 20, MovingAverageType.Simple) def OnData(self, slice: Slice) -> None: bar = slice.Bars.get(self.symbol) if bar: self.apo.Update(bar.EndTime, bar.Close) if self.apo.IsReady: # The current value of self.apo is represented by self.apo.Current.Value self.Plot("AbsolutePriceOscillator", "apo", self.apo.Current.Value) # Plot all attributes of self.apo self.Plot("AbsolutePriceOscillator", "fast", self.apo.Fast.Current.Value) self.Plot("AbsolutePriceOscillator", "slow", self.apo.Slow.Current.Value) self.Plot("AbsolutePriceOscillator", "signal", self.apo.Signal.Current.Value) self.Plot("AbsolutePriceOscillator", "histogram", self.apo.Histogram.Current.Value)
To register a manual indicator for automatic updates with the security data, call the RegisterIndicator
method.
public class AbsolutePriceOscillatorAlgorithm : QCAlgorithm { private Symbol _symbol; private AbsolutePriceOscillator _apo; public override void Initialize() { _symbol = AddEquity("SPY", Resolution.Daily).Symbol; _apo = new AbsolutePriceOscillator(10, 20, MovingAverageType.Simple); RegisterIndicator(_symbol, _apo, Resolution.Daily); } public override void OnData(Slice data) { if (_apo.IsReady) { // The current value of _apo is represented by itself (_apo) // or _apo.Current.Value Plot("AbsolutePriceOscillator", "apo", _apo); // Plot all properties of apo Plot("AbsolutePriceOscillator", "fast", _apo.Fast); Plot("AbsolutePriceOscillator", "slow", _apo.Slow); Plot("AbsolutePriceOscillator", "signal", _apo.Signal); Plot("AbsolutePriceOscillator", "histogram", _apo.Histogram); } } }
class AbsolutePriceOscillatorAlgorithm(QCAlgorithm): def Initialize(self) -> None: self.symbol = self.AddEquity("SPY", Resolution.Daily).Symbol self.apo = AbsolutePriceOscillator(10, 20, MovingAverageType.Simple) self.RegisterIndicator(self.symbol, self.apo, Resolution.Daily) def OnData(self, slice: Slice) -> None: if self.apo.IsReady: # The current value of self.apo is represented by self.apo.Current.Value self.Plot("AbsolutePriceOscillator", "apo", self.apo.Current.Value) # Plot all attributes of self.apo self.Plot("AbsolutePriceOscillator", "fast", self.apo.Fast.Current.Value) self.Plot("AbsolutePriceOscillator", "slow", self.apo.Slow.Current.Value) self.Plot("AbsolutePriceOscillator", "signal", self.apo.Signal.Current.Value) self.Plot("AbsolutePriceOscillator", "histogram", self.apo.Histogram.Current.Value)
The following reference table describes the AbsolutePriceOscillator
constructor:
AbsolutePriceOscillator()1/2
AbsolutePriceOscillator QuantConnect.Indicators.AbsolutePriceOscillator (string
name,int
fastPeriod,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
fastPeriod,int
slowPeriod,*MovingAverageType
movingAverageType )
Initializes a new instance of the AbsolutePriceOscillator
class using the specified parameters.
Visualization
The following image shows plot values of selected properties of AbsolutePriceOscillator
using the plotly library.
