Indicator Reference

Detrended Price Oscillator

Introduction

The Detrended Price Oscillator is an indicator designed to remove trend from price and make it easier to identify cycles. DPO does not extend to the last date because it is based on a displaced moving average. Is estimated as Price {X/2 + 1} periods ago less the X-period simple moving average. E.g.DPO(20) equals price 11 days ago less the 20-day SMA.

Create Manual Indicators

You can manually create a DetrendedPriceOscillator 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 DetrendedPriceOscillator constructor.

DetrendedPriceOscillator()1/2

            DetrendedPriceOscillator QuantConnect.Indicators.DetrendedPriceOscillator (
     string  name,
     int     period
   )
        

Initializes a new instance of the DetrendedPriceOscillator class.

DetrendedPriceOscillator()2/2

            DetrendedPriceOscillator QuantConnect.Indicators.DetrendedPriceOscillator (
     int  period
   )
        

Initializes a new instance of the DetrendedPriceOscillator class.

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 DetrendedPriceOscillator _dpo;

// In Initialize()
_dpo = new DetrendedPriceOscillator(name, period);
_dpo.Updated += IndicatorUpdateMethod;

RegisterIndicator(symbol, _dpo, Resolution.Daily);

// In IndicatorUpdateMethod()
if (_dpo.IsReady)
{
    var indicatorValue = _dpo.Current.Value;
}
    
# In Initialize()
self.dpo = DetrendedPriceOscillator(name, period)
self.dpo.Updated += self.IndicatorUpdateMethod

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

# In IndicatorUpdateMethod()
if self.dpo.IsReady:
    indicator_value = self.dpo.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 DetrendedPriceOscillator _dpo;
private Symbol symbol;

// In Initialize()
_dpo = new DetrendedPriceOscillator(period);
symbol = AddEquity("SPY").Symbol;

// In OnData()
if (data.ContainsKey(_symbol))
{
    _dpo.Update(data[symbol].EndTime, data[symbol].High);
}
if (_dpo.IsReady)
{
    var indicatorValue = _dpo.Current.Value;
}
    
# In Initialize()
self.dpo = DetrendedPriceOscillator(period)
self.symbol = self.AddEquity("SPY").Symbol

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

Create Automatic Indicators

The DPO method creates an DetrendedPriceOscillator 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 DPO method:

DPO()1/1

            DetrendedPriceOscillator QuantConnect.Algorithm.QCAlgorithm.DPO (
    Symbol                           symbol,
    Int32                            period,
    *Nullable<Resolution>      resolution,
    *Func<IBaseData, Decimal>  selector
   )
        

Creates a new DetrendedPriceOscillator" indicator.


If you don't provide a resolution, it defauls 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 DetrendedPriceOscillator _dpo;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_dpo = DPO(symbol, period);

// In OnData()
if (_dpo.IsReady)
{
    var current = _dpo.Current.Value;
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.dpo = self.DPO(symbol, period)

# In OnData()
if self.dpo.IsReady:
    current = self.dpo.Current.Value

Visualization

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

private DetrendedPriceOscillator _dpo;

// In Initialize()
var symbol = AddEquity("SPY").Symbol;
_dpo = DPO(symbol, period);

// In OnData()
if (_dpo.IsReady)
{
    Plot("My Indicators", "detrendedpriceoscillator", _dpo.Current);
}
# In Initialize()
symbol = self.AddEquity("SPY").Symbol
self.dpo = self.DPO(symbol, period)

# In OnData()
if self.dpo.IsReady:
    self.Plot("My Indicators", "detrendedpriceoscillator", self.dpo.Current)

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: