Trend indicators

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.

· Founder of PatternsWizard
Checked 6 min read
DPO(20) on S&P 500 ETF, dividend-adjusted prices, daily, August 5, 2026 to October 28, 2026. Illustration of how the indicator reads, not a backtest.
On this page
  1. How the DPO is calculated
  2. The real-time trap
  3. Measuring the cycle length
  4. Choosing the period
  5. Does it work?
  6. Tested on our bench
  7. Frequently asked questions

Every pattern's results on one sheet

The only pattern cheat sheet with tested stats: 153 patterns, what the textbook says and what really happened on 6 markets. Free PDF, sent to your inbox.

The PDF by email, plus our newsletter: new tests and results that change. Unsubscribe anytime. Privacy.

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

DPO(20) on S&P 500 ETF, dividend-adjusted prices, daily, May 8, 2026 to October 28, 2026. Illustration of how the indicator reads, not a backtest.
  • Price, daily candles (hollow up, filled down)
  • DPO(20), close minus the SMA(20) 11 bars later (solid line)
DPO(20) on S&P 500 ETF, dividend-adjusted prices, daily, May 8, 2026 to October 28, 2026. Illustration of how the indicator reads, not a backtest.

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

Centered DPO against the shifted DPO: an upper solid line, the centered DPO, stops some bars before a vertical line marked today; the gap is labeled no value yet. A lower dashed line has the same shape moved to the right so that it reaches today. The same trough appears on its own bar on the centered line and N/2 + 1 bars later on the shifted one.
Schematic, not market data.

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

Median distance between DPO swings, in bars. S&P 500 ETF, DPO(20): 39 troughs, 42 peaks: Troughs 15 (7 to 27), Peaks 14 (6 to 22); Bitcoin, DPO(20): 44 troughs, 39 peaks: Troughs 13 (6 to 25), Peaks 15 (6 to 27); S&P 500 ETF, DPO(40): 37 troughs, 35 peaks: Troughs 13.5 (7 to 36), Peaks 13.5 (9 to 36); Bitcoin, DPO(40): 32 troughs, 31 peaks: Troughs 13 (6 to 38), Peaks 18.5 (6 to 35). Our computation; the inputs and the method are in the text.
  • Troughs
  • Peaks
Our computation; the inputs and the method are in the text.Centered DPO on daily closes, from June 7, 2024 (ETF, dividend-adjusted) and March 8, 2025 (Bitcoin) to the last value available in October 2026. In brackets, the shortest and the longest distance.

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 after1351020
After the signal51.2%52.1%52.7%53.7%54.5%
Random dates50.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.

PeriodSignalsVs market, before costs
1970 to 2012326,354+0.03%
2012 to 2021326,308+0.004%
2021 to 2026326,2310.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.

DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bullish: real trade on FIL/USDT, 2026-07-20, daily chart
Most recentFIL 2026-07-20 daily chartBought at the close of 2026-07-20 (0.7350), sold 2 bars later, when the exit rule fired (0.7624): +3.7% before costs.Against the other crypto pairs over the same bars, after costs: +4.1%.DPO
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bullish: real trade on DOGE/USDT, 2021-01-25, daily chart
Best tradeDOGE 2021-01-25 daily chartBought at the close of 2021-01-25 (0.008351), sold 3 bars later, when the exit rule fired (0.0365): +337.1% before costs.Against the other crypto pairs over the same bars, after costs: +319.7%.DPO
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bullish: real trade on SUNE, 2025-03-31, daily chart
Worst tradeSUNE 2025-03-31 daily chartBought at the close of 2025-03-31 (66.00), sold 16 bars later, when the exit rule fired (2.88): −95.6% before costs.Against the other stocks over the same bars, after costs: −95.5%.DPO
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bullish: real trade on BALL, 2013-09-04, daily chart
Typical tradeBALL 2013-09-04 daily chartBought at the close of 2013-09-04 (19.49), sold 6 bars later, when the exit rule fired (19.54): +0.3% before costs.Against the other stocks over the same bars, after costs: −2.1%.DPO

Market by market

MarketBarsSignalsAvg tradeWinnersVs market, after costsResult
Stocksdaily843,642+0.26%54%−0.10%No edge found
ETFsdaily30,433+0.19%56%−0.04%No edge found
Indicesdaily16,022+0.19%58%n/aNot measured
Forexdaily10,545+0.004%52%−0.03%No edge found
Cryptodaily69,413+0.23%50%−0.10%Inconclusive
Commoditiesdaily8,838+0.24%54%−0.03%No edge found
All markets4-hour480,334−0.03%50%−0.14%Inconclusive
Forex4-hour60,447+0.003%53%−0.03%No edge found
Crypto4-hour419,887−0.03%49%−0.15%Inconclusive
All marketsweekly179,513+1.17%57%−0.06%No edge found
Stocksweekly159,683+1.18%57%−0.05%No edge found
ETFsweekly6,094+0.63%60%−0.01%No edge found
Indicesweekly3,277+0.55%59%−0.11%No edge found
Forexweekly2,067+0.02%51%−0.03%No edge found
Cryptoweekly6,575+3.20%47%n/aNot measured
Commoditiesweekly1,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 after1351020
After the signal48.5%47.6%47.0%46.4%45.4%
Random dates48.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.

PeriodSignalsVs market, before costs
1970 to 2012326,012+0.05%
2012 to 2021325,972+0.01%
2021 to 2026325,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.

DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bearish: real trade on ATOM/USDT, 2026-07-20, daily chart
Most recentATOM 2026-07-20 daily chartSold short at the close of 2026-07-20 (1.50), bought back 1 bar later, when the exit rule fired (1.49): +0.7% before costs.Against the other crypto pairs over the same bars, after costs: +0.2%.DPO
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bearish: real trade on AIG, 2008-09-03, daily chart
Best tradeAIG 2008-09-03 daily chartSold short at the close of 2008-09-03 (278.5), bought back 8 bars later, when the exit rule fired (58.70): +78.9% before costs.Against the other stocks over the same bars, after costs: +77.5%.DPO
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bearish: real trade on RMBS, 2000-02-04, daily chart
Worst tradeRMBS 2000-02-04 daily chartSold short at the close of 2000-02-04 (19.30), bought back 27 bars later, when the exit rule fired (105.5): −446.7% before costs.Against the other stocks over the same bars, after costs: −447.8%.DPO
DPO(20), lagged version (close 11 bars ago minus the current SMA 20) crosses 0, bearish: real trade on RDN, 2002-07-12, daily chart
Typical tradeRDN 2002-07-12 daily chartSold short at the close of 2002-07-12 (33.83), bought back 1 bar later, when the exit rule fired (33.84): 0.0% before costs.Against the other stocks over the same bars, after costs: −0.7%.DPO

Market by market

MarketBarsSignalsAvg tradeWinnersVs market, after costsResult
Stocksdaily843,224−0.23%49%−0.09%No edge found
ETFsdaily30,428−0.11%47%−0.03%No edge found
Indicesdaily16,021−0.13%47%n/aNot measured
Forexdaily10,535−0.01%52%−0.03%No edge found
Cryptodaily68,913−0.01%57%−0.12%Inconclusive
Commoditiesdaily8,837−0.06%51%−0.04%No edge found
All markets4-hour479,826−0.07%52%−0.14%Inconclusive
Forex4-hour60,5560.000%52%−0.03%No edge found
Crypto4-hour419,270−0.08%52%−0.16%Inconclusive
All marketsweekly178,528−1.19%46%+0.03%Beat the market, fragile
Stocksweekly158,653−1.01%46%+0.03%Inconclusive
ETFsweekly6,070−0.70%43%−0.01%No edge found
Indicesweekly3,273−0.90%42%−0.11%No edge found
Forexweekly2,069+0.005%51%+0.002%No edge found
Cryptoweekly6,624−9.66%59%n/aNot measured
Commoditiesweekly1,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.

Sources

  1. StockCharts ChartSchool, Detrended Price Oscillator (DPO)
  2. TradingView Help Center, Detrended Price Oscillator (DPO)
, Founder of PatternsWizard

Passionate about finance, quantitative trading and data analysis. Amaury built the PatternsWizard test bench, which detects each pattern on full price history and measures what happened next against random entries.

PatternsWizard tests chart and candlestick patterns on full market history, against random entries. How we test patterns.

179 patterns testedRandom-walk self-test passed

Related guides

All trend indicators articles