In EasyLanguage the DPO is an Average referenced back in time and subtracted from the
current close. The history-referencing syntax makes the displacement clean. See
the explainer.
What you’ll need
- TradeStation or MultiCharts
- The EasyLanguage / PowerLanguage Editor, a new Indicator
The source
{ AlgoGen Detrended Price Oscillator — TradeStation / MultiCharts }
inputs:
Price( Close ),
Length( 20 );
variables:
Shift( 0 ),
DPOVal( 0 );
Shift = Length / 2 + 1; { displacement = N/2 + 1 }
DPOVal = Price - Average( Price, Length )[Shift]; { close - SMA from Shift bars ago }
Plot1( DPOVal, "DPO" );
Plot2( 0, "Zero" );
Average( Price, Length ) is the N-period SMA; the [Shift] reads its value Shift bars
ago; and Price - ... gives the detrended cycle, the line around zero in the output
chart. For a 20-period DPO, Shift is 11.
The displacement, spelled out
The one subtlety is Average( Price, Length )[Shift]. In EasyLanguage, appending [n]
to any expression reads its value n bars back — so this is the N-period average as it
stood Shift bars ago. Subtracting that displaced average, rather than the current one,
is what re-aligns the average with its data and strips the trend. Drop the [Shift] and
you’d just have price minus a lagging average, which is not the DPO.
A centered variant
For the classic centered display, plot the DPO shifted into the past:
{ Centered: compute plainly, then displace the plot back }
DPOVal = Price - Average( Price, Length );
Plot1[Shift]( DPOVal, "DPO" ); { draw it Shift bars back }
Plot1[Shift](...) draws the value Shift bars in the past, centring the oscillator on
its window at the cost of a blank right edge.
Gotchas
Shift = Length / 2 + 1. Integer division plus one; it’s the standard offset.[Shift]on the Average, not the Price. You’re displacing the average, keeping the current price.- Not a momentum tool. The DPO reveals cycle spacing; don’t trade its latest value as a trend read.
Average= SMA. The standard DPO uses a simple, not exponential, average.
Same indicator elsewhere: Python, MQL5, Pine Script, NinjaScript. Then backtest it in AlgoGen.
This post is educational, not financial advice. Indicators describe the past; they don’t predict the future. Backtest anything before you risk real money on it.
Sources and further reading
- What is EasyLanguage? (TradeStation)
