Detrended Price Oscillator (DPO): Formula, Cycle Length and the Real-Time Lag Trap
The Detrended Price Oscillator compares each price with a moving average centered on it, which removes the trend and leaves the swings. Here is the formula, why the line stops 11 bars before the last price, what happens when a platform shifts it to the current bar, and the cycle lengths it measured on the S&P 500 ETF and Bitcoin.
On this page
The Detrended Price Oscillator (DPO) removes the trend from price by comparing each close with a simple moving average centered on it, so that only the shorter swings remain. It is not built to give real-time signals: because the average it uses is centered, the DPO stops several bars before the last price. StockCharts describes its purpose as identifying cycle highs and lows and estimating cycle length. We found no published originator for the indicator.
Detrended Price Oscillator (20) on the S&P 500 ETF
- Price, daily candles (hollow up, filled down)
- DPO(20), close minus the SMA(20) 11 bars later (solid line)
How the DPO is calculated
For a period of N bars, the DPO compares the price at the middle of the moving average's window with that average. StockCharts' example: a 20-day DPO uses a 20-day average displaced by 20/2 + 1 = 11 bars, so the value for a bar is that bar's price minus the 20-day average that ends 11 bars later.
Because the average is centered on the bar, it follows price closely and the difference keeps only swings shorter than the window. A positive value means price was above its centered average at that time; a negative value, below.
The real-time trap
The DPO can also be drawn up to the last bar. TradingView's DPO has a “Centered” input: switched off, the line “shifts back to the right to match current price”. The values do not change, only the dates they are drawn on. On our ETF data, the non-centered value on each date was exactly the centered value of 11 sessions earlier, on all 581 bars where both exist.
Centered DPO against the shifted DPO
That shift is where the trap lies. The lowest close since June 7, 2024, the start of the window used here, was 488.38 on April 8, 2025 (dividend-adjusted), and the centered DPO marks it clearly, at −38.37, its lowest value. But that value can only be computed with the close of April 24, 2025. Drawn on the current bar, the same −38.37 appears on April 24, with the ETF at 537.77, 10.11% above the low. A trough on a shifted DPO is a trough that already happened 11 sessions ago. StockCharts makes the same point: shifting “defeats the purpose of this indicator, which is to identify cycles”.
Measuring the cycle length
The DPO's use is to estimate how far apart the swings are. We marked DPO troughs (below zero) and peaks (above zero) that are strictly lower or higher than every other value within 5 bars on each side, using the bars available on the short side at the two ends of the line, then measured the distance in bars between consecutive troughs and between consecutive peaks.
Median distance between DPO swings, in bars
- Troughs
- Peaks
On both markets the typical distance between swings came out at 13 to 15 bars with a 20-bar DPO, about three weeks of sessions on the ETF and two weeks on Bitcoin, which trades every day, but the range is wide, from 6 to 27 bars. Doubling the setting to 40 barely moved the median on the ETF and widened the range. The cycle you measure depends on the rule used to pick the swings and on the DPO length, so treat it as a rough rhythm of the market over the period, not a clock.
Choosing the period
Start from the default of 20 periods and change it with the cycle you are after. StockCharts notes that the DPO “filters out the longer trends to focus on shorter cycles”, and its own example reads a cycle of about 10 days on a 20-day DPO; our reading of that example is that a period about twice the cycle you look for keeps that cycle visible. A longer period lets longer swings through but shifts the average further back (N/2 + 1 bars), and StockCharts suggests trying “shorter and longer DPO settings to find the best fit”. TradingView's DPO has two inputs, the period and the Centered switch.
Does it work?
The DPO is a measuring tool, not a signal generator, and both StockCharts and TradingView say so. Our bench measures chart patterns detected by rule against random entries, not indicators (see our methodology). To use a cycle estimate, combine it with a trend tool such as a moving average or the MACD. The Schaff Trend Cycle is another indicator built around cycles; the broader topic is covered in market cycles. More tools are listed with the trend indicators.
Frequently asked questions
What is the detrended price oscillator?
An oscillator that subtracts a centered simple moving average from price, to remove the trend and show the shorter swings. It is used to estimate cycle highs, lows and length, not to time trades.
What is the detrended price oscillator formula?
DPO = price at bar t minus the N-bar simple average that ends N/2 + 1 bars later. TradingView writes it the other way round: price N/2 + 1 bars ago minus the current N-bar average.
Why does the DPO stop before the last bar?
Because the value for a bar needs the moving average that ends N/2 + 1 bars later. With N = 20, the last 11 bars have no value yet.
Is the DPO a leading indicator?
No. Centered, it has no value on the most recent bars; shifted to the current bar, it shows each swing N/2 + 1 bars after it happened.
