Detrended Price Oscillator — price against a moving average taken from half a
cycle ago, which strips the trend and leaves the cycle.
barsback = period/2 + 1 indexes a series, so it has to be a whole number:
the reference integer division truncates, and this floors, which agrees for both odd
and even lengths (21 -> 11, 20 -> 11).
The centered mode is the awkward one. the reference computes close[barsback] - ma
and then draws it with offset = -barsback, i.e. shifted back in time.
Plots here have no per-plot offset, so the shift is folded into the column
itself: the value drawn at bar i is the one the reference computed on bar
i + barsback, which reduces to close[i] - ma[i + barsback]. The picture
matches the reference platform exactly, including the fact that the centered line stops
barsback bars short of the right edge. The non-centered mode needs no such
trick and is implemented straight.
Detrended Price Oscillator — price against a moving average taken from half a cycle ago, which strips the trend and leaves the cycle.
barsback = period/2 + 1indexes a series, so it has to be a whole number: the reference integer division truncates, and this floors, which agrees for both odd and even lengths (21 -> 11, 20 -> 11).The
centeredmode is the awkward one. the reference computesclose[barsback] - maand then draws it withoffset = -barsback, i.e. shifted back in time. Plots here have no per-plot offset, so the shift is folded into the column itself: the value drawn at bariis the one the reference computed on bari + barsback, which reduces toclose[i] - ma[i + barsback]. The picture matches the reference platform exactly, including the fact that the centered line stopsbarsbackbars short of the right edge. The non-centered mode needs no such trick and is implemented straight.