Detrended Price Oscillator (DPO) Calculator
Technical indicators
- Displacement: for a 20-period setting the close is taken 11 periods back - half the window plus one - which strips the trend lag out of the average.
- Detrending: that shifted close is 178.90 and the current 20-period simple moving average is 182.45.
- Difference: 178.90 - 182.45 = -3.55, or -1.95% of the average - what remains is the cycle component alone.
- DPO result: -3.55 - below zero (price lagged the average), read as cycle phase rather than trend direction.
A moving average is a trend line with a built-in flaw: it lags. A 20-period average describes where price was centred about ten periods ago, not where it is centred now, so subtracting it from today's close mixes trend, cycle and lag into one muddy number. The detrended price oscillator fixes the alignment before subtracting.
The fix is a displacement. For a period of n, take the close from (n/2 + 1) periods ago - for the standard 20-period setting, 11 periods back - and subtract the current n-period moving average from it. The shifted close and the lagging average now describe roughly the same moment, the trend cancels, and what remains is the cycle: in the first worked example, a shifted close of 178.90 against an average of 182.45 leaves a DPO of -3.55.
This calculator takes the period, the current moving average and the displaced close, and returns the DPO with the displacement it used and the reading as a percentage of the average, so cycle analysis from any chart package can be reproduced exactly.
Worked examples
DPO in a below-trend phase (20-period)
(20 · 182.45 · 178.9)
| Detrended price oscillator | -3.55 |
| Displacement (periods) | 11 |
| DPO as % of SMA | -1.95 |
| Cycle position | Below zero (price lagged the average) |
DPO in an above-trend phase (14-period)
(14 · 96.3 · 101.15)
| Detrended price oscillator | 4.85 |
| Displacement (periods) | 8 |
| DPO as % of SMA | 5.04 |
| Cycle position | Above zero (price led the average) |
DPO deep below trend (30-period)
(30 · 245.8 · 238.25)
| Detrended price oscillator | -7.55 |
| Displacement (periods) | 16 |
| DPO as % of SMA | -3.07 |
| Cycle position | Below zero (price lagged the average) |
Why the close is shifted
The lag of a simple moving average is half its window: the average of the last 20 closes is centred on the midpoint of those 20 bars. Shifting the price series back by that same half-window, plus one bar by convention, lines the two series up in time. What survives the subtraction is the component of price that oscillates around the trend - the cycle that trend-following indicators are specifically designed to ignore.
The displacement is integer arithmetic: the period divided by 2, rounded down, plus 1. A 14-period setting displaces by 8, a 30-period setting by 16, as the second and third worked examples show. Odd periods behave the same way after the rounding, which is why the calculator prints the displacement it used rather than leaving you to guess the convention your platform chose.
| Period n | Displacement | Best suited cycle |
|---|---|---|
| 14 | 8 periods | Short swings of roughly two to three weeks |
| 20 | 11 periods | The standard intermediate cycle window |
| 30 | 16 periods | Longer cycles in slow-moving instruments |
Reading cycle phase and length
The DPO's peaks and troughs mark cycle highs and lows, and the distance between successive peaks of the same kind is the practical estimate of the cycle length - the number traders actually extract from this indicator. Once the length is known, the phase follows: a rising DPO below zero is a cycle bottoming, a falling DPO above zero is a cycle topping, and entries can be timed to the cycle while the trend, identified separately, supplies direction.
Amplitude carries information too, which is why the calculator expresses the reading as a percentage of the average: the first example's -3.55 is -1.95 percent, a shallow below-trend phase, while the third example's -7.55 on a larger base is -3.07 percent. Comparing raw DPO values across years of a rising instrument overstates old cycles and understates new ones; the percentage form keeps the comparison honest.
- The DPO measures cycle phase, not trend direction - the trend was deliberately removed, so pair it with a trend tool.
- Because the newest value uses an old close, the DPO's right edge is historical; it cannot react to the latest bars.
- Estimate cycle length peak-to-peak over several repetitions before trusting it for timing.
- The strong second example reads 4.85, or 5.04 percent above the average - a pronounced above-trend phase.
- Displacement conventions differ slightly between platforms; this calculator prints the one it used.
Worked examples
Example 1: Period n 20; Current n-period moving average 182.45; Close (n/2 + 1) periods ago 178.9. Detrended price oscillator = -3.55. Supporting values: Displacement (periods) 11; DPO as % of SMA -1.95; Cycle position Below zero (price lagged the average). Displacement: for a 20-period setting the close is taken 11 periods back - half the window plus one - which strips the trend lag out of the average. Detrending: that shifted close is 178.90 and the current 20-period simple moving average is 182.45. Difference: 178.90 - 182.45 = -3.55, or -1.95% of the average - what remains is the cycle component alone. DPO result: -3.55 - below zero (price lagged the average), read as cycle phase rather than trend direction.
Example 2: Period n 14; Current n-period moving average 96.3; Close (n/2 + 1) periods ago 101.15. Detrended price oscillator = 4.85. Supporting values: Displacement (periods) 8; DPO as % of SMA 5.04; Cycle position Above zero (price led the average). Displacement: for a 14-period setting the close is taken 8 periods back - half the window plus one - which strips the trend lag out of the average. Detrending: that shifted close is 101.15 and the current 14-period simple moving average is 96.30. Difference: 101.15 - 96.30 = 4.85, or 5.04% of the average - what remains is the cycle component alone. DPO result: 4.85 - above zero (price led the average), read as cycle phase rather than trend direction.
Example 3: Period n 30; Current n-period moving average 245.8; Close (n/2 + 1) periods ago 238.25. Detrended price oscillator = -7.55. Supporting values: Displacement (periods) 16; DPO as % of SMA -3.07; Cycle position Below zero (price lagged the average). Displacement: for a 30-period setting the close is taken 16 periods back - half the window plus one - which strips the trend lag out of the average. Detrending: that shifted close is 238.25 and the current 30-period simple moving average is 245.80. Difference: 238.25 - 245.80 = -7.55, or -3.07% of the average - what remains is the cycle component alone. DPO result: -7.55 - below zero (price lagged the average), read as cycle phase rather than trend direction.
DPO vs MACD
Both indicators subtract a moving average from price-like input, and the resemblance ends there. MACD subtracts one exponential average from another, both computed on current data, and its whole purpose is trend momentum - it keeps the trend and throws away the cycle's clean phase picture. The DPO does the opposite surgery: it sacrifices the trend, and the timeliness, to isolate the cycle.
A useful mental model is a filter bank. The trend is the low-frequency component, the cycle the band in the middle, noise the high frequency. MACD is a low-pass momentum gauge; the DPO is a band-pass lens aimed at the middle. Asking the DPO whether to be long or short is a category error - it can only tell you where inside its cycle the instrument currently sits.
Detrended price oscillator in practice
Cycle work rewards patience. The robust workflow is to measure several peak-to-peak distances, take the median as the working cycle length, and then use the DPO mainly to locate the current phase within that length. When the measured length keeps changing, the instrument is not cycling cleanly and the DPO's output should be discounted - not every series has a tradeable cycle, and the indicator cannot manufacture one.
Within a confirmed trend, the DPO earns its keep as a timing overlay: in an uptrend, cycle lows (DPO troughs turning up while still in the trend's favour) are the natural entry windows, and cycle highs are where partial profits make sense. The trend decides the side; the cycle decides the moment.
Reading the three examples
The first example is the gentle case: -3.55, less than 2 percent below the average, a cycle in its lower half but nowhere near an extreme - the sort of reading that fills most of a chart. The second, at 4.85 with a displacement of 8 on a 14-period setting, is a shorter-cycle instrument near a cycle high.
The third example pairs the longest window (30 periods, displacement 16) with the deepest reading, -7.55. Long windows isolate slow cycles, and a deep negative on a slow cycle describes an instrument well below its trend centre with, historically, a long climb of phase ahead of it - context for patience, not a buy signal in itself.
Choosing the period deserves one more word, because it is the only real decision the indicator asks of you. The period should be set near the cycle you intend to trade - the displacement and the average both derive from it - so the honest workflow runs backwards: measure the instrument's dominant cycle from several peak-to-peak spans on the DPO itself, then set the period to that length and let the detrending sharpen what you already found. Setting the period by habit, to 20 because 20 is standard, tunes the lens to a cycle the instrument may not possess.
FAQs
What DPO does the first example give?
-3.55: the close from 11 periods ago (178.90) minus the current 20-period average (182.45), leaving price in a below-trend cycle phase.
What displacement does a 20-period setting use?
11 periods - half the window by integer division, plus one - which aligns the close with the centre of the average's window.
What percentage of the average is the first reading?
-1.95 percent, the scale-free form that lets cycle amplitude be compared across price levels and years.
What DPO does the strong example give?
4.85 on a 14-period setting with a displacement of 8 - a pronounced above-trend phase at 5.04 percent of the average.
Can the detrended price oscillator predict turning points?
It locates cycle phase and estimates cycle length from peak spacing; it does not predict, and its right edge is historical because the newest value uses a displaced close.
What DPO does the 30-period example give?
-7.55 with a displacement of 16 - the deepest below-trend reading of the three, on the slowest cycle window.