backtrader.indicators.dpo module

DPO Indicator Module - Detrended Price Oscillator.

This module provides the DPO (Detrended Price Oscillator) indicator developed by Joe DiNapoli to identify cycles by removing trend effects.

Classes:

DetrendedPriceOscillator: DPO indicator (alias: DPO).

Example

class MyStrategy(bt.Strategy):
def __init__(self):

self.dpo = bt.indicators.DPO(self.data, period=20)

def next(self):
if self.dpo[0] > 0:

self.buy()

class backtrader.indicators.dpo.DetrendedPriceOscillator[source]

Bases: Indicator

Defined by Joe DiNapoli in his book “Trading with DiNapoli levels”

It measures the price variations against a Moving Average (the trend) and therefore removes the “trend” factor from the price.

Formula:
  • movav = MovingAverage(close, period)

  • dpo = close - movav(shifted period / 2 + 1)

See:
alias = ('DPO',)
plotinfo = <backtrader.metabase.plotinfo_obj object>
__init__(*args, **kwargs)
next()[source]

Calculate DPO for the current bar.

Formula: DPO = price - MA(lookback bars ago)

once(start, end)[source]

Calculate DPO in runonce mode.

frompackages = ()
packages = ()