Momentum Indicators

DPO: Detrended Price Oscillator | AlfaTactix

📖 6 min read

📝 1,048 words

🏷️ Momentum Indicators

In this page: what DPO is, how it works, when to use it, a practical example with code, and a bonus tip.

Use DPO in a real strategy—no code required

Create a free account to save your progress and build strategies with this indicator and 80+ others in minutes. Backtest, then export to MQL5.


DPO on a price chart: illustration of the indicator and how it is used in technical analysis
DPO – chart illustration

DPO (Detrended Price Oscillator) Indicator Explanation

The Detrended Price Oscillator (DPO) is a momentum oscillator that removes trend from price data by subtracting a displaced moving average from the current price, helping identify short-term cycles and overbought/oversold conditions. Developed by William Blau in the 1990s, the DPO compares the current price to a moving average that has been shifted back in time by half the moving average period plus one. This displacement removes the trend component, leaving only short-term price oscillations. The indicator oscillates around a zero line, with positive values indicating upward momentum and negative values indicating downward momentum relative to the detrended average.

How DPO Works: DPO is calculated by subtracting a displaced simple moving average (SMA) from the current price. The displacement is calculated as (period / 2) + 1, where period is the moving average period (typically 20 periods). The formula is: DPO = Close - SMA(period) shifted back by (period / 2) + 1 periods. For example, with a 20-period SMA, the displacement would be (20 / 2) + 1 = 11 periods. This means the DPO compares the current price to what the SMA was 11 periods ago, effectively removing the trend and leaving only short-term price cycles. The result oscillates around zero, with positive values indicating prices are above the detrended average and negative values indicating prices are below it.

When to Use DPO:

  • Short-Term Cycle Identification: DPO is highly effective at identifying short-term price cycles by removing the trend component. The oscillator reveals cyclical patterns that may be obscured by the underlying trend, making it useful for identifying potential turning points and cycle peaks/valleys.
  • Overbought/Oversold Identification: DPO values above zero with extreme positive readings can indicate overbought conditions relative to the detrended average, while values below zero with extreme negative readings can indicate oversold conditions. However, these extremes should be used in conjunction with other indicators for confirmation.
  • Zero Line Crossovers: DPO crossovers with the zero line can generate trading signals. When DPO crosses above zero, it may indicate potential upward momentum, and when it crosses below zero, it may indicate potential downward momentum. However, DPO works best when combined with trend confirmation.

Advantages:

  • Provides clear identification of short-term price cycles by removing trend components, making it easier to identify cyclical patterns and potential turning points. The detrending reveals patterns that may be hidden by the underlying trend.
  • Works effectively across multiple timeframes and asset classes, including stocks, forex, commodities, and cryptocurrencies. The detrending makes it particularly useful for identifying cycles in trending markets.
  • Helps identify overbought and oversold conditions relative to the detrended average, providing early signals for potential price reversals in cyclical markets.

Limitations:

  • DPO does not provide information about trend direction on its own, only short-term oscillations relative to the detrended average. Traders should combine it with trend indicators for more comprehensive analysis.
  • The indicator may produce false signals in strong trending markets when cycles are less pronounced. DPO works best in markets with identifiable cyclical patterns.
  • DPO values can remain positive or negative for extended periods during strong trends, potentially leading to delayed signals. The indicator is more effective for identifying cycles than for generating precise entry and exit signals.

In summary, DPO is a valuable momentum oscillator that identifies short-term price cycles by removing trend components, making it ideal for identifying cyclical patterns and potential turning points in detrended price data. For comprehensive understanding, refer to Blau's original work on the Detrended Price Oscillator, Investopedia's DPO guide, TradingView's DPO documentation, and academic research on momentum oscillators in technical analysis published in journals such as the Journal of Financial Markets and the Review of Financial Studies.

Practical Example: Using the DPO Indicator in a Trading Strategy

The Detrended Price Oscillator (DPO) is a momentum oscillator used to identify short-term cycles and overbought/oversold conditions by removing trend components from price data. In a trading strategy, the DPO indicator helps traders make entry and exit decisions based on cyclical patterns and zero line crossovers.

Scenario: You're creating a mean-reversion strategy for EUR/USD on a 4-hour chart. You want to buy when DPO crosses below zero and then crosses back above zero (indicating potential cycle bottom and upward reversal), and sell when DPO crosses above zero and then crosses back below zero (indicating potential cycle top and downward reversal).

Strategy Logic:

  • Calculate the DPO(20) using a 20-period SMA with displacement of (20 / 2) + 1 = 11 periods. The DPO oscillates around zero, with positive values indicating prices above the detrended average and negative values indicating prices below it.
  • Buy signal: When DPO crosses below zero (indicating potential cycle bottom) and then crosses back above zero (indicating potential upward reversal).
  • Sell signal: When DPO crosses above zero (indicating potential cycle top) and then crosses back below zero (indicating potential downward reversal).

Backtrader Example:

import backtrader as bt

class DPOMeanReversionStrategy(bt.Strategy):
    params = dict(
        dpo_period=20
    )
    
    def __init__(self):
        # Calculate DPO: Close - SMA(period) shifted back by (period / 2) + 1
        displacement = (self.p.dpo_period // 2) + 1
        sma = bt.ind.SMA(period=self.p.dpo_period)
        # Shift SMA back by displacement
        shifted_sma = bt.ind.Delay(sma, period=displacement)
        self.dpo = self.data.close - shifted_sma
        
    def next(self):
        if not self.position:
            # Buy when DPO crosses back above zero (potential cycle bottom reversal)
            if (self.dpo[0] > 0 and self.dpo[-1] <= 0):
                self.buy()
        else:
            # Sell when DPO crosses back below zero (potential cycle top reversal)
            if (self.dpo[0] < 0 and self.dpo[-1] >= 0):
                self.sell()

# Usage
cerebro = bt.Cerebro()
cerebro.addstrategy(DPOMeanReversionStrategy)

Expected Outcome: By using the DPO indicator, your strategy identifies short-term cycles through detrended price analysis, helping you enter trades when prices are likely to revert to the cycle mean. This approach leads to better cycle identification, improved mean-reversion entries, and enhanced consistency in cyclical markets.

💡 Bonus Tip

Consider using DPO in combination with cycle analysis for confirmation. When DPO crosses below zero and price makes a new low within a known cycle period, it suggests potential cycle bottom with higher probability of upward reversal. This technique, documented in technical analysis literature, can significantly improve the accuracy of DPO-based trading strategies.

Using the DPO indicator ensures your strategy captures short-term cycles effectively, improving entry and exit timing based on detrended price analysis.

Use DPO in a real strategy—no code required

Create a free account to save your progress and build strategies with this indicator and 80+ others in minutes. Backtest, then export to MQL5.

Try Strategy Builder

Use this indicator in Strategy Builder — free

Create free account