Technical indicators

Detrended Price Oscillator (DPO): Cycle Reading Without Trend

The detrended price oscillator (DPO) is a price oscillator that compares a past close with a simple moving average calculated at a later bar, so the average is displaced in time. TA-Lib and StockCharts use 20 as the default period, giving a displacement of 11 bars. It is used to study cycle lengths in past bars, not to forecast.

By RTX5 Editorial TeamLast updated: Editorial methodology
Illustration of assumed closes for bars 1 to 10, with a 4-bar simple moving average drawn three bars to the left. DPO bars show the close minus that average. The bar 8 value, +0.50, is drawn at position 5, and no DPO is drawn at positions 8 to 10.
Illustration only: the closes are assumed. Each DPO bar matches the 4-period worked example table and is drawn three positions to the left of its bar. Open full-size diagram (opens in a new tab)

In brief

What is the detrended price oscillator?

The DPO is a cycle tool, not a trend line. This guide sets out its formula and displacement, a worked example with assumed closes, how platforms differ, and what the indicator cannot show.

Key takeaways

  • The DPO at bar i is the close t bars back minus the N-period simple moving average at bar i, where t = N/2 + 1 with integer division. TA-Lib's default N is 20, so t is 11.
  • The displacement removes a longer trend from the comparison. It also means the newest 11 bars on a 20-period chart carry no displayed DPO value.
  • Platforms do not all write the same formula. Some references use N/2 + 1 as the moving-average length rather than as the shift, so check the code before you compare lines.
  • Set N to a cycle you have measured on your own chart. A cycle length in the past does not fix the length of the next cycle.
  • The DPO describes past closes. Zero-line crosses are conventions rather than signals, and no RTX5 release record confirms a DPO feature.

What the detrended price oscillator measures

The detrended price oscillator, usually shortened to DPO, compares a closing price with a simple moving average (SMA) that has been displaced in time. StockCharts describes it as the closing price less the value of a displaced moving average, and TradingView's support article describes the same construction.

The purpose is to remove a longer trend from the comparison. It asks how far a past close sits from an average built around the bars near it. The exponential moving average guide covers a different averaging method.

Detrended price oscillator formula and the displacement rule

At bar i, the DPO equals the price t bars back minus the N-period simple moving average at bar i. N is the period, and t equals N/2 + 1, using integer division. TA-Lib sets the default N at 20.

TradingView writes the same calculation as the price from N/2 + 1 periods ago minus the N-period SMA, with N chosen by the user.

  • Period (N): the length of the average. TA-Lib's default is 20 and its accepted range runs from 2 to 100,000.
  • Displacement (t): N/2 + 1, with integer division. For N = 20 the displacement is 11 bars. For N = 21, integer division gives 10, plus 1, so the displacement is also 11 bars.
  • Price input: the StockCharts and MQL5 references use the close. Check your platform's input before comparing charts.

The cycle-length idea: setting N to match a cycle

StockCharts' Stock Market Cycles page says it often helps to set the DPO in line with the cycle being studied, for example a 10-period DPO for 10-day cycle lows. For a different long-cycle tool, see the Coppock curve guide.

A reader counts the bars between two cycle peaks or troughs and compares that count with N. The count describes past bars only and does not fix the next cycle's length.

Detrended price oscillator worked example with a 4-period average

This is an Example with assumed closes, not market data. A 20-period DPO needs more bars than fit in a table, so the example uses N = 4. The displacement is then 4/2 + 1 = 3 bars. Each DPO value compares the close three bars back with the 4-bar SMA ending at the current bar.

The assumed closes for bars 1 to 10 are 10.0, 10.4, 10.2, 10.8, 11.5, 11.0, 10.6, 10.9, 11.4 and 11.8. The first DPO value is at bar 4, the first bar with four closes available for the average.

Check one row. At bar 8 the SMA is (11.5 + 11.0 + 10.6 + 10.9) / 4 = 44.0 / 4 = 11.00. The compared close is bar 5, which is 11.5. The DPO is 11.5 - 11.00 = +0.50. The bar-8 close of 10.9 is inside the average, but it is not the price compared.

Example: 4-period DPO with a 3-bar displacement, using assumed closes
Bar (i)Compared close (bar i - 3)4-bar SMA ending at bar iDPO at bar i
410.010.350-0.35
510.410.725-0.325
610.210.875-0.675
710.810.975-0.175
811.511.000+0.50
911.010.975+0.025
1010.611.175-0.575

Example arithmetic. Assumed closes for bars 1 to 10: 10.0, 10.4, 10.2, 10.8, 11.5, 11.0, 10.6, 10.9, 11.4, 11.8. Each DPO is the compared close minus the SMA.

The DPO values are negative for bars 4 to 7 and bar 10, and positive for bars 8 and 9. This describes these ten closes only and does not show what bar 11 will do.

Why the DPO is not aligned to the latest bar

TA-Lib says charting packages usually draw each value t bars to the left, a display convention rather than a different series.

The practical effect is at the right-hand edge. For N = 20, the value drawn at the newest bar's position is the DPO of the bar 11 places later. That value needs a 20-bar average over 11 bars that have not printed yet, so the newest 11 positions carry no displayed value. The most recent calculable DPO belongs to the newest bar and is drawn 11 bars to the left. It compares the close 11 bars back with today's 20-bar average.

Platform variants: the N/2 + 1 reading that needs checking

The references do not all write the same formula, so the table sets each one out.

Detrended price oscillator formula and defaults by reference
ReferenceFormula as writtenDefault periodDisplacement and notes
TA-Lib function referenceDPO[i] = P[i - t] - SMA(P, N)[i], with t = N/2 + 1 (integer division)20; accepted range 2 to 100,000Charts usually draw the value t bars to the left, which TA-Lib calls a display convention.
TA-Lib causal variant, same function referenceP[i] - SMA(P, N)[i - t]Same N as the main seriesDisplaces the average into the past instead of the price. TA-Lib describes it and says it is not implemented there.
StockCharts ChartSchool, Stock Market CyclesClosing price less the displaced N-period moving average20 (SharpCharts default parameter)Average displaced to the past by N/2 + 1; a 20-day DPO is displaced 11 days. The StockCharts DPO article's formula line says 'in the future', a conflict this page does not follow.
TradingView support articlePrice from (N/2 + 1) periods ago minus the N-period SMAN is user-defined; no default statedHas a Centered input. When it is off, the line shifts right to match current price.
MQL5 Code Base, DPO (code 27)CLOSE - SMA(CLOSE, N/2 + 1), with N the cycle periodNo default; recommends 21 or lessWrites N/2 + 1 inside the SMA term. The page states no displacement rule.

The MetaTrader 5 help pages for oscillators and trend indicators list no Detrended Price Oscillator, so this page states no MetaTrader 5 default.

The safe comparison is to fix N, record the platform and its version, and confirm whether the moving-average length and the displacement are both applied. Two lines with the same N can differ if one platform uses N/2 + 1 as the average length.

The MQL5 code page says, in its definition of N, 'if N is equal 12, then DPO corresponds to the DiNapoli Detrend Oscillator'. That is MQL5's claim. The other references on this page name no originator, so this page does not confirm who devised the DPO.

How the DPO is read, and what it cannot show

Readers look at whether the line sits above or below zero, and at the spacing of peaks and troughs against the chosen period. The TradingView support article says the indicator is not necessarily intended to generate signals.

This page does not treat a zero-line cross as a signal. A DPO line records past closes against a displaced average. The arithmetic can be checked, but the next cycle cannot be read from it. For another average-based tool with its own construction, see the MACD guide.

A sensible next step is to choose a period from a cycle you have measured on your own chart, write down the platform's formula, and reproduce the table's arithmetic in a spreadsheet before you rely on any line.

Risk disclosure and limits

  • The DPO describes past closes. It does not forecast a cycle, a turning point or a price level, and a cycle length from the past does not fix the next one.
  • Zero-line crosses and peaks are conventions. The TradingView support article says the indicator is not necessarily intended to generate signals.
  • The worked example uses assumed closes. It is not market data and shows no result that a live market would produce.
  • This page is educational and is not personal financial advice. Trading can lose money, and no indicator removes that risk.

RTX5 status

This guide explains detrended price oscillator in general and does not describe an RTX5 feature. No RTX5 release record confirms which indicators, chart types or alerts the product includes. RTX5 is Orrnn's trading terminal and broker-technology product. Its Windows desktop client is in preview, and the web and mobile clients are planned. A Google Play listing for Android is published, but the mobile client has no approved release record yet; check the product-availability record before relying on any RTX5 feature.

Check RTX5 product availability

Trust and methodology

How this research was prepared

We want you to be able to identify who owns the page, inspect the evidence, understand how tools were used, and challenge anything that looks wrong or out of date.

Accountable publisher

Published under the RTX5 Editorial Team byline. It identifies the responsible publishing organization; it does not imply that a named lawyer, regulator, financial adviser, or licensed expert approved this page.

Evidence you can inspect

5 primary references are listed on this page with context about what each one supports. The source set was checked on .

Assistance is disclosed

Automation and AI may help organize research, outline a page, or edit language. They are not treated as sources, are not presented as human experts, and do not remove the publisher's responsibility for the final page.

Primary references

Sources were checked on 10 November 2026. They explain market rules and concepts; they do not certify RTX5 or provide individual financial advice.

StockCharts ChartSchool: Stock Market CyclesChecked 10 November 2026. Defines DPO as the closing price less a moving average displaced to the left by N/2 + 1 periods; a 20-day DPO is displaced 11 days. Says it often helps to set the DPO in line with the cycle length, for example a 10-period DPO for 10-day cycle lows.StockCharts ChartSchool: Detrended Price Oscillator (DPO) articleChecked 10 November 2026. Gives the default parameter of 20 periods (SharpCharts) and a 20-day SMA displaced by 11 periods. Says DPO is not a momentum oscillator. Its formula line says 'in the future', which conflicts with its text on displacement to the past.TA-Lib: DPO function referenceChecked 10 November 2026. Gives DPO[i] = P[i - t] - SMA(P, N)[i], default period 20, accepted range 2 to 100,000, and t = N/2 + 1 with integer division. Says charting packages usually draw the value t bars to the left, and that the causal variant is not implemented.TradingView support: Detrended Price Oscillator (DPO)Checked 10 November 2026. Gives the price from (N/2 + 1) periods ago minus the N-period SMA, with N user-defined and no default stated in the text. Describes the Centered input and says DPO is not necessarily intended to be a signal-generating indicator.MQL5 Code Base: Detrended Price Oscillator (DPO), code 27Checked 10 November 2026. Gives the formula CLOSE - SMA(CLOSE, N/2 + 1) and recommends a period of 21 or less. States no displacement rule and no default. In its definition of N it says 'if N is equal 12, then DPO corresponds to the DiNapoli Detrend Oscillator', and a comment thanks Di Napoli for the idea.

Questions readers ask

What is the default period for the detrended price oscillator?

TA-Lib uses 20 as the default period, and the StockCharts DPO example also uses 20. With N = 20, the displacement is 11 bars, because N/2 + 1 with integer division gives 11. The TradingView support article uses a user-defined N and states no default. Check your own platform's default before you compare values.

What is the displacement in the DPO formula?

The displacement is N/2 + 1, using integer division, so an even period and the odd number after it share the same shift. For N = 20 and N = 21 the displacement is 11 bars. The close being compared sits t bars before the average calculated at the current bar.

Is the detrended price oscillator a buy or sell signal?

No single reading is a buy or sell signal, and this page does not treat zero-line crosses as signals. The TradingView support article says the DPO is not necessarily intended to be a signal-generating indicator. Use the DPO to describe the spacing of past cycles, not to expect what price will do next.

Why does the DPO not show the newest bars?

On a chart that draws each value t bars to the left, a bar's value needs an average from t bars later. The newest t bars have no such average yet. For N = 20, the last 11 bars have no displayed DPO value.

Does RTX5 offer a detrended price oscillator?

This guide explains the detrended price oscillator in general and does not describe an RTX5 feature. No RTX5 release record confirms which indicators or chart types the product includes. The Windows desktop client is in preview, and the web and mobile clients are planned. A Google Play listing for Android is published, but the mobile client has no approved release record yet. Check the product-availability record before you rely on any RTX5 feature.

How can I check a DPO on my platform against the worked example?

Set the period to 4 and confirm that the platform uses the close, an SMA whose length equals the period, and a displacement of 3 bars. The example uses assumed closes, so a live chart will not reproduce its numbers. Test the arithmetic on the ten closes in the table in a spreadsheet first, then compare the platform's output with that result.