Detrended price oscillator
All indicators

LibraryMomentum

Indicator

Detrended price oscillator

How far price stands above or below its moving average with the trend taken out, to show the shorter cycles and their length.

MomentumOwn pane2 inputsDPO

How it is calculated

This is the causal form, with n the length: the price n // 2 + 1 bars ago minus the SMA of the last n prices, written on the current bar. The textbook DPO pairs the same price and average but draws the value half a window back, which needs bars that come later. Here no value depends on a later bar; the line is the textbook one moved n // 2 + 1 bars to the right.

Reference: Detrended price oscillator, causal form

How to read it

Above zero the price of half a window ago stood above the average, below zero under it. Its peaks and troughs show the cycle, and the distance between them estimates its length. It is built to remove the trend, so it says nothing about trend direction, and each value describes the market half a window ago, not now.

In a strategy

Cycle timing for swing trades in a market without a strong trend: ctx.ind("dpo", length=21) read each bar, entering after it turns up from a trough. Each trough shows up length // 2 + 1 bars late, so measure the cycle first and allow for that delay.

Inputs

InputTypeDefaultRange or choices
LengthlengthWhole number21min 2, max 5000
SourcesourcePrice"close"close, open, high, low, hl2, hlc3, ohlc4, hlcc4

What it draws

LineDrawn as
DPOLine

Guide lines at 0.

Used in

No strategy template reads it yet.

OrionQuant