Supported Indicators

Percentage Price Oscillator

Introduction

This indicator computes the Percentage Price Oscillator (PPO) The Percentage Price Oscillator is calculated using the following formula: PPO[i] = 100 * (FastMA[i] - SlowMA[i]) / SlowMA[i]

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

Using PPO Indicator

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

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

    public override void OnData(Slice data)
    {
        if (_ppo.IsReady)
        {
            // The current value of _ppo is represented by itself (_ppo)
            // or _ppo.Current.Value
            Plot("PercentagePriceOscillator", "ppo", _ppo);
            // Plot all properties of ppo
            Plot("PercentagePriceOscillator", "fast", _ppo.Fast);
            Plot("PercentagePriceOscillator", "slow", _ppo.Slow);
            Plot("PercentagePriceOscillator", "signal", _ppo.Signal);
            Plot("PercentagePriceOscillator", "histogram", _ppo.Histogram);
        }
    }
}
class PercentagePriceOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.ppo = self.PPO(self.symbol, 10, 20, MovingAverageType.Simple)

    def on_data(self, slice: Slice) -> None:
        if self.ppo.IsReady:
            # The current value of self.ppo is represented by self.ppo.Current.Value
            self.plot("PercentagePriceOscillator", "ppo", self.ppo.Current.Value)
            # Plot all attributes of self.ppo
            self.plot("PercentagePriceOscillator", "fast", self.ppo.Fast.Current.Value)
            self.plot("PercentagePriceOscillator", "slow", self.ppo.Slow.Current.Value)
            self.plot("PercentagePriceOscillator", "signal", self.ppo.Signal.Current.Value)
            self.plot("PercentagePriceOscillator", "histogram", self.ppo.Histogram.Current.Value)

The following reference table describes the PPO method:

PPO()1/1

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

Creates a new PercentagePriceOscillator 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:

To avoid parameter ambiguity, use the resolution argument to set the Resolution.

public class PercentagePriceOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private PercentagePriceOscillator _ppo;

    public override void Initialize()
    {
        _symbol = AddEquity("SPY", Resolution.Hour).Symbol;
        _ppo = PPO(_symbol, 10, 20, MovingAverageType.Simple, resolution: Resolution.Daily);
    }
}
class PercentagePriceOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Hour).Symbol
        self.ppo = self.PPO(self.symbol, 10, 20, MovingAverageType.Simple, resolution=Resolution.Daily)

You can manually create a PercentagePriceOscillator 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 with time/number pair or an IndicatorDataPoint. The indicator will only be ready after you prime it with enough data.

public class PercentagePriceOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private PercentagePriceOscillator _ppo;

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

    public override void OnData(Slice data)
    {
        if (data.Bars.TryGetValue(_symbol, out var bar))
        {      
            _ppo.Update(bar.EndTime, bar.Close);
        }
   
        if (_ppo.IsReady)
        {
            // The current value of _ppo is represented by itself (_ppo)
            // or _ppo.Current.Value
            Plot("PercentagePriceOscillator", "ppo", _ppo);
            // Plot all properties of ppo
            Plot("PercentagePriceOscillator", "fast", _ppo.Fast);
            Plot("PercentagePriceOscillator", "slow", _ppo.Slow);
            Plot("PercentagePriceOscillator", "signal", _ppo.Signal);
            Plot("PercentagePriceOscillator", "histogram", _ppo.Histogram);
        }
    }
}
class PercentagePriceOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.ppo = PercentagePriceOscillator(10, 20, MovingAverageType.Simple)

    def on_data(self, slice: Slice) -> None:
        bar = slice.Bars.get(self.symbol)
        if bar:
            self.ppo.Update(bar.EndTime, bar.Close)
        if self.ppo.IsReady:
            # The current value of self.ppo is represented by self.ppo.Current.Value
            self.plot("PercentagePriceOscillator", "ppo", self.ppo.Current.Value)
            # Plot all attributes of self.ppo
            self.plot("PercentagePriceOscillator", "fast", self.ppo.Fast.Current.Value)
            self.plot("PercentagePriceOscillator", "slow", self.ppo.Slow.Current.Value)
            self.plot("PercentagePriceOscillator", "signal", self.ppo.Signal.Current.Value)
            self.plot("PercentagePriceOscillator", "histogram", self.ppo.Histogram.Current.Value)

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

public class PercentagePriceOscillatorAlgorithm : QCAlgorithm
{
    private Symbol _symbol;
    private PercentagePriceOscillator _ppo;

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

    public override void OnData(Slice data)
    {
        if (_ppo.IsReady)
        {
            // The current value of _ppo is represented by itself (_ppo)
            // or _ppo.Current.Value
            Plot("PercentagePriceOscillator", "ppo", _ppo);
            // Plot all properties of ppo
            Plot("PercentagePriceOscillator", "fast", _ppo.Fast);
            Plot("PercentagePriceOscillator", "slow", _ppo.Slow);
            Plot("PercentagePriceOscillator", "signal", _ppo.Signal);
            Plot("PercentagePriceOscillator", "histogram", _ppo.Histogram);
        }
    }
}
class PercentagePriceOscillatorAlgorithm(QCAlgorithm):
    def Initialize(self) -> None:
        self._symbol = self.AddEquity("SPY", Resolution.Daily).Symbol
        self.ppo = PercentagePriceOscillator(10, 20, MovingAverageType.Simple)
        self.RegisterIndicator(self.symbol, self.ppo, Resolution.Daily)

    def on_data(self, slice: Slice) -> None:
        if self.ppo.IsReady:
            # The current value of self.ppo is represented by self.ppo.Current.Value
            self.plot("PercentagePriceOscillator", "ppo", self.ppo.Current.Value)
            # Plot all attributes of self.ppo
            self.plot("PercentagePriceOscillator", "fast", self.ppo.Fast.Current.Value)
            self.plot("PercentagePriceOscillator", "slow", self.ppo.Slow.Current.Value)
            self.plot("PercentagePriceOscillator", "signal", self.ppo.Signal.Current.Value)
            self.plot("PercentagePriceOscillator", "histogram", self.ppo.Histogram.Current.Value)

The following reference table describes the PercentagePriceOscillator constructor:

PercentagePriceOscillator()1/2

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

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

PercentagePriceOscillator()2/2

            PercentagePriceOscillator QuantConnect.Indicators.PercentagePriceOscillator (
    int                 fastPeriod,
    int                 slowPeriod,
    *MovingAverageType  movingAverageType
   )
        

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

Visualization

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

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