Detrended Price Oscillator
A naive "price minus its own moving average" oscillator does not actually remove the trend - it just re-expresses it on a different scale, because both the price and the average it is compared against are trending together at the same point in time. The Detrended Price Oscillator fixes this by comparing an OLDER close - from X bars ago - against TODAY's n-period average: DPO = Close[X bars ago] - SMA(n), where X = floor(n/2)+1. Offsetting which bar the price comes from is what actually breaks the trend correlation between the two terms, which is the entire point of the tool. The result oscillates around zero and is read for the spacing between its peaks and troughs - the classic use is eyeballing how many bars apart the market's recent cycles have run, as an input to picking cycle-based tools elsewhere, not as a directional trend or momentum signal. Notes and limitations - Non-repainting: every plotted value only ever reads closes at or before its own bar - this implementation deliberately does NOT apply the visual chart-shift some DPO implementations use to align the plot under the price it was detrended from; the value at bar i is Close[i+shift] - SMA(i), drawn at bar i, not shifted left on the chart. Say this plainly because a trader comparing this against a shifted DPO from another platform will see the same values at different x positions. - Needs InpPeriod + floor(InpPeriod/2) + 1 completed bars of history before it starts plotting; earlier bars are left empty. - Designed for cycle-length estimation as originally published (Martin Pring, Technical Analysis Explained) - it is not intended as a standalone entry signal.
Indicator · MT4 · v1.0 · Free
About Detrended Price Oscillator
Detrended Price Oscillator is an indicator for MetaTrader 4. It has 1 setting, such as Period. MQL source code included.
Files in the download: DetrendedPriceOscillator.ex4, DetrendedPriceOscillator.mq4, DetrendedPriceOscillator.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Period | 20 | SMA period; the backward displacement is floor(period/2)+1 bars |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the indicator from the Navigator onto a chart and adjust the settings.
Tags: Martingale · Moving Average · Oscillator · Trend · MT4 Indicator · MQL4 Source Code