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 still tested the simplest signal traders take from the shifted line, a zero-line cross, across markets after costs (see our methodology): it showed no edge in either direction. The results are in the section below. 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.
Data from our test bench
Tested on our bench
We coded the 2 strategies taught on this page, buy and sell side, and ran them on stocks, ETFs, indices, forex, crypto and commodities. With all markets pooled (daily bars): 2 showed no edge.
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bullishNo edge found
Entry: DPO(20), lagged version (close 11 bars ago minus the current SMA 20) closes above 0 after a close at or below it. Exit: Opposite signal (stop and reverse).
Several published formulas exist for this indicator; the result holds for the one written in the rule above.
In detail, all markets pooled
On daily bars, the rule fired 978,893 times on 2,360 assets (stocks, ETFs, indices, currency pairs, crypto pairs and commodity futures) between 1970 and 2026, about once every 9 bars on each asset.
The average trade returned +0.25% before costs and the median trade +0.26%; 54% of trades made money, and the gains added up to 1.16 times the losses.
A trade lasted 3 bars at the median, half of them between 1 and 6 bars.
Over exactly the same bars, compared with an equal-weight basket of the other assets of the same market, the trades ended −0.09% per trade after costs (95% interval −0.11% to −0.07%).
- Signals
- 978,8932,360 assets, 1970 to 2026
- Average trade
- +0.25%before costs; median +0.26%
- Winning trades
- 54%profit factor 1.16
- Median hold
- 3 barshalf between 1 and 6
- Vs the market, after costs
- −0.09%95% interval −0.11% to −0.07%
After the signal, bar by bar
Share of signals where the price had moved in the signal’s direction after N bars, against the same assets at random dates (before costs).
| Bars after | 1 | 3 | 5 | 10 | 20 |
|---|---|---|---|---|---|
| After the signal | 51.2% | 52.1% | 52.7% | 53.7% | 54.5% |
| Random dates | 50.6% | 51.9% | 52.5% | 53.5% | 54.5% |
Over time
The history cut into three periods with the same number of signals: gap per trade against the rest of the market, before costs.
| Period | Signals | Vs market, before costs |
|---|---|---|
| 1970 to 2012 | 326,354 | +0.03% |
| 2012 to 2021 | 326,308 | +0.004% |
| 2021 to 2026 | 326,231 | 0.00% |
With the trade we run on chart patterns instead (stop at 2 ATR, target at twice the risk, entry at the signal close), 38% of 974,213 trades hit the target first, for +0.15 R per trade on average against +0.15 R for the same trade at random dates of the same assets: no measurable difference from random dates.
Worst single trade of the whole test: −95.6% on SUNE, signal of 2025-03-31.
Real trades from the test
Taken from the test itself on well-known assets: the indicator lines are the values the bench computed for that signal, the shaded zone is the time in the trade, from the signal close to the exit. Best and worst are chosen among these assets, not over the whole test.




Market by market
| Market | Bars | Signals | Avg trade | Winners | Vs market, after costs | Result |
|---|---|---|---|---|---|---|
| Stocks | daily | 843,642 | +0.26% | 54% | −0.10% | No edge found |
| ETFs | daily | 30,433 | +0.19% | 56% | −0.04% | No edge found |
| Indices | daily | 16,022 | +0.19% | 58% | n/a | Not measured |
| Forex | daily | 10,545 | +0.004% | 52% | −0.03% | No edge found |
| Crypto | daily | 69,413 | +0.23% | 50% | −0.10% | Inconclusive |
| Commodities | daily | 8,838 | +0.24% | 54% | −0.03% | No edge found |
| All markets | 4-hour | 480,334 | −0.03% | 50% | −0.14% | Inconclusive |
| Forex | 4-hour | 60,447 | +0.003% | 53% | −0.03% | No edge found |
| Crypto | 4-hour | 419,887 | −0.03% | 49% | −0.15% | Inconclusive |
| All markets | weekly | 179,513 | +1.17% | 57% | −0.06% | No edge found |
| Stocks | weekly | 159,683 | +1.18% | 57% | −0.05% | No edge found |
| ETFs | weekly | 6,094 | +0.63% | 60% | −0.01% | No edge found |
| Indices | weekly | 3,277 | +0.55% | 59% | −0.11% | No edge found |
| Forex | weekly | 2,067 | +0.02% | 51% | −0.03% | No edge found |
| Crypto | weekly | 6,575 | +3.20% | 47% | n/a | Not measured |
| Commodities | weekly | 1,817 | +0.54% | 54% | −0.06% | No edge found |
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bearishNo edge found
Entry: DPO(20), lagged version (close 11 bars ago minus the current SMA 20) closes below 0 after a close at or above it. Exit: Opposite signal (stop and reverse).
Several published formulas exist for this indicator; the result holds for the one written in the rule above.
In detail, all markets pooled
On daily bars, the rule fired 977,958 times on 2,356 assets (stocks, ETFs, indices, currency pairs, crypto pairs and commodity futures) between 1970 and 2026, about once every 9 bars on each asset.
The average trade returned −0.20% before costs and the median trade −0.01%; 49% of trades made money, and the gains added up to only 0.89 times the losses. For this sell signal, a trade gains when the price falls (a short sale).
A trade lasted 3 bars at the median, half of them between 1 and 7 bars.
Over exactly the same bars, compared with an equal-weight basket of the other assets of the same market, the trades ended −0.08% per trade after costs (95% interval −0.10% to −0.06%). For a sell signal, a positive number means the asset did worse than the others, as the signal announced.
- Signals
- 977,9582,356 assets, 1970 to 2026
- Average trade
- −0.20%before costs; median −0.01%
- Winning trades
- 49%profit factor 0.89
- Median hold
- 3 barshalf between 1 and 7
- Vs the market, after costs
- −0.08%95% interval −0.10% to −0.06%
After the signal, bar by bar
Share of signals where the price had moved in the signal’s direction after N bars, against the same assets at random dates (before costs).
| Bars after | 1 | 3 | 5 | 10 | 20 |
|---|---|---|---|---|---|
| After the signal | 48.5% | 47.6% | 47.0% | 46.4% | 45.4% |
| Random dates | 48.2% | 47.5% | 47.0% | 46.2% | 45.3% |
Over time
The history cut into three periods with the same number of signals: gap per trade against the rest of the market, before costs.
| Period | Signals | Vs market, before costs |
|---|---|---|
| 1970 to 2012 | 326,012 | +0.05% |
| 2012 to 2021 | 325,972 | +0.01% |
| 2021 to 2026 | 325,974 | −0.004% |
With the trade we run on chart patterns instead (stop at 2 ATR, target at twice the risk, entry at the signal close), 28% of 971,774 trades hit the target first, for −0.15 R per trade on average against −0.16 R for the same trade at random dates of the same assets: no measurable difference from random dates.
Worst single trade of the whole test: −632.1% on DENT/USDT, signal of 2021-03-10.
Real trades from the test
Taken from the test itself on well-known assets: the indicator lines are the values the bench computed for that signal, the shaded zone is the time in the trade, from the signal close to the exit. Best and worst are chosen among these assets, not over the whole test.




Market by market
| Market | Bars | Signals | Avg trade | Winners | Vs market, after costs | Result |
|---|---|---|---|---|---|---|
| Stocks | daily | 843,224 | −0.23% | 49% | −0.09% | No edge found |
| ETFs | daily | 30,428 | −0.11% | 47% | −0.03% | No edge found |
| Indices | daily | 16,021 | −0.13% | 47% | n/a | Not measured |
| Forex | daily | 10,535 | −0.01% | 52% | −0.03% | No edge found |
| Crypto | daily | 68,913 | −0.01% | 57% | −0.12% | Inconclusive |
| Commodities | daily | 8,837 | −0.06% | 51% | −0.04% | No edge found |
| All markets | 4-hour | 479,826 | −0.07% | 52% | −0.14% | Inconclusive |
| Forex | 4-hour | 60,556 | 0.000% | 52% | −0.03% | No edge found |
| Crypto | 4-hour | 419,270 | −0.08% | 52% | −0.16% | Inconclusive |
| All markets | weekly | 178,528 | −1.19% | 46% | +0.03% | Beat the market, fragile |
| Stocks | weekly | 158,653 | −1.01% | 46% | +0.03% | Inconclusive |
| ETFs | weekly | 6,070 | −0.70% | 43% | −0.01% | No edge found |
| Indices | weekly | 3,273 | −0.90% | 42% | −0.11% | No edge found |
| Forex | weekly | 2,069 | +0.005% | 51% | +0.002% | No edge found |
| Crypto | weekly | 6,624 | −9.66% | 59% | n/a | Not measured |
| Commodities | weekly | 1,839 | −0.89% | 49% | −0.12% | No edge found |
Each strategy enters at the close of the signal bar and exits at the exit it teaches, without a stop. The test compares the asset with an equal-weight basket of the other assets of its market over exactly the same bars, net of trading costs; for a sell signal, beating the market means the asset did worse than the others. A result is shown as beating or lagging the market only when it survives a correction for the number of tests and holds in both halves of the history; it is marked fragile when entering at the next open, doubling costs or trimming extreme trades removes it. Daily index bars are not compared with other indices, because their closes fall at different hours; “Not measured” also covers samples too small to test. Rules were fixed before any result was seen. How we test
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.
