Detrended Price Oscillator (DPO)
Summary
Detrended Price Oscillator: the price a half-cycle back, less the moving average that spans the cycle. Removing the average removes the trend, leaving the shorter oscillation that the trend was hiding.
It crosses zero as price crosses its own average, so peaks and troughs mark the cycle rather than the direction of the market. The distance between successive peaks estimates the cycle length, and the amplitude is in price units, so it is comparable across time only for one instrument.
Formula
Let t = optInTimePeriod / 2 + 1, an integer division, so a period and its odd successor share the same displacement.
DPO[i] = P[i - t] - SMA(P, optInTimePeriod)[i]
Notes
- The value is emitted at the bar whose moving average produced it. Charting packages usually draw it
tbars to the left instead, which is a plotting convention rather than a different series; a caller wanting that view shiftsoutRealitself. - A causal variant,
P[i] - SMA(P, optInTimePeriod)[i - t], displaces the average instead of the price. It is a genuinely different series, not a re-indexing of this one, and is not implemented here.
Inputs
inReal— Source price/value series, canonically the close
Outputs
outReal— Detrended Price Oscillator value, in the units of the input
Parameters
| Parameter | Type | Default | Accepted values | Description |
|---|---|---|---|---|
optInTimePeriod | integer | 20 | 2–100000 | Number of bars spanned by the moving average being removed; the displacement is derived from it |
Properties
Numerical Stability: Start-Independent
| ☐ Overlap Input |
| ✅ Independent Y-Axis i |
| ☐ Candlestick |
| ☐ Can Output NaN or ±Inf |
| ☐ Identity at Period 1 |
Implementation
TA-Lib Definition: dpo.c · dpo.yaml
| Native | File |
|---|---|
| C | ta_DPO.c |
| Rust | dpo.rs |
| Java | Core_DPO.java |
TA-Lib is also available for Python, R and more using a wrapper.
Aliases
Detrended Price Oscillator
See Also
References
- Steven B. Achelis, Technical Analysis from A to Z, McGraw-Hill (p. 119)
- StockCharts ChartSchool: Detrended Price Oscillator