---
url: /indicators/dpo.md
description: >-
  Detrended Price Oscillator depicts the difference between price and an offset
  simple moving average.  It is used to identify trend cycles and duration.
package: FacioQuo.Stock.Indicators
docs_version: v3
canonical: https://dotnet.stockindicators.dev/indicators/dpo
generated: 2026-09-30T04:41:06.055Z
commit: ae1f432eaa0b03ae9f39e032c69434b557efa4a2
---

# Detrended Price Oscillator (DPO)

[Detrended Price Oscillator](https://en.wikipedia.org/wiki/Detrended_price_oscillator) depicts the difference between price and an offset simple moving average.  It is used to identify trend cycles and duration.
[\[Discuss\] 💬](https://github.com/facioquo/stock-indicators-dotnet/discussions/551 "Community discussion about this indicator")

```csharp
// C# usage syntax
IReadOnlyList<DpoResult> results =
  bars.ToDpo(lookbackPeriods);
```

## Parameters

| param | type | description |
| ----- | ---- | ----------- |
| `lookbackPeriods` | *`int`* | Number of periods (`N`) in the moving average.  Must be greater than 0. |

### Historical price bars requirements

You must have at least `N` historical price bars to cover the warmup periods.

`bars` is a collection of generic `TBar` historical price bars.  It should have a consistent frequency (day, hour, minute, etc).  See [the Guide](/guide/getting-started.md#historical-bars) for more information.

## Response

```csharp
IReadOnlyList<DpoResult>
```

* This method returns a time series of all available indicator values for the `bars` provided.
* It always returns the same number of elements as there are in the historical price bars.
* It does not return a single incremental indicator value.
* The first `N/2-2` and last `N/2+1` periods will be `null` since they cannot be calculated.

### `DpoResult`

| property | type | description |
| -------- | ---- | ----------- |
| `Timestamp` | *`DateTime`* | Date from evaluated `TBar` |
| `Sma` | *`double`* | Simple moving average offset by `N/2+1` periods |
| `Dpo` | *`double`* | Detrended Price Oscillator (DPO) |

### Utilities

* [.Condense()](/utilities/results.md#condense)
* [.Find(lookupDate)](/utilities/results.md#find-by-date)
* [.RemoveWarmupPeriods(removePeriods)](/utilities/results.md#remove-warmup-periods)

See [Utilities and helpers](/utilities.md) for more information.

## Chaining

This indicator may be generated from any chain-enabled indicator or method.

```csharp
// example
var results = bars
    .Use(CandlePart.HL2)
    .ToDpo(..);
```

Results can be further processed on `Dpo` with additional chain-enabled indicators.

```csharp
// example
var results = bars
    .ToDpo(..)
    .ToRsi(..);
```

See [Chaining indicators](/guide/chaining.md) for more.

## Streaming

Use the buffer-style `List<T>` when you need incremental calculations without a hub:

```csharp
DpoList dpoList = new(lookbackPeriods);

foreach (IBar bar in bars)  // simulating stream
{
  dpoList.Add(bar);
}

// based on `ICollection<DpoResult>`
IReadOnlyList<DpoResult> results = dpoList;
```

Subscribe to a `BarHub` for advanced streaming scenarios:

```csharp
BarHub barHub = new();
DpoHub observer = barHub.ToDpoHub(lookbackPeriods);

foreach (IBar bar in bars)  // simulating stream
{
  barHub.Add(bar);
}

IReadOnlyList<DpoResult> results = observer.Results;
```

**Note:** DPO has a lookahead requirement (offset = N/2+1 periods), which means results are calculated when sufficient future data becomes available. This introduces a delay in real-time scenarios but maintains mathematical accuracy with the series implementation.

See [Buffer lists](/guide/styles/buffer.md) and [Stream hubs](/guide/styles/stream.md) for full usage guides.
