Skip to content

Detrended Price Oscillator ​

Close minus a lagged SMA, to show cycles without the trend.

Kind indicator · Drawn in its own pane

Try it ​

On the chart, press / and choose Detrended Price Oscillator under Oscillators. To change it, copy the source below into the AlphaScript editor.

Inputs ​

InputTypeDefault
Lengthint21
Colorcolor"#43A047"

Source ​

From packages/alphascript/indicators/dpo.as.js.

js
indicator({ name: "Detrended Price Oscillator", shortTitle: "DPO", overlay: false });
const period = input.int("Length", 21, { min: 1 });
const barsback = math.floor(period / 2) + 1;
const ma = ta.sma(candle.close, period);
plot(ta.calc([candle.close, ma], (c) => c - ma.at(barsback)), { title: "Detrended Price Oscillator", color: input.color("Color", "#43A047", { group: "Style" }) });
hline(0, { title: "Zero", color: "rgba(120,123,134,0.5)", style: "dashed" });

AlphaScript language v0.1 · runtime 0.2.0