Detrended Price Oscillator

Technical Analysis Indicator: dpo

Fork me on GitHub

Function Prototype

/* Detrended Price Oscillator */
/* Type: indicator */
/* Input arrays: 1    Options: 1    Output arrays: 1 */
/* Inputs: real */
/* Options: period */
/* Outputs: dpo */
int ti_dpo_start(TI_REAL const *options);
int ti_dpo(int size,
      TI_REAL const *const *inputs,
      TI_REAL const *options,
      TI_REAL *const *outputs);

Description

This documentation is still a work in progress. It has omissions, and it probably has errors too. If you see any issues, or have any general feedback, please get in touch.

The Detrended Price Oscillator helps identify cycles.

It takes one option, the period n.

It is calculated as follows:

$$m = \lfloor \frac{n}{2}+1 \rfloor$$
$$dpo_{t} = in_{t-m} - (\frac{1}{n} \sum_{i=0}^{n-1} in_{t-i}) $$

Some recommend plotting the Detrended Price Oscillator shifted to the left by n amount. This does make a nice chart, but I find it to be nonsense since you're incorporating data from the future into the past.

See Also

References

Example Usage

Calling From C

/* Example usage of Detrended Price Oscillator */
/* Assuming that 'input' is a pre-loaded array of size 'in_size'. */
TI_REAL *inputs[] = {input};
TI_REAL options[] = {5}; /* period */
TI_REAL *outputs[1]; /* dpo */

/* Determine how large the output size is for our options. */
const int out_size = in_size - ti_dpo_start(options);

/* Allocate memory for output. */
outputs[0] = malloc(sizeof(TI_REAL) * out_size); assert(outputs[0] != 0); /* dpo */

/* Run the actual calculation. */
const int ret = ti_dpo(in_size, inputs, options, outputs);
assert(ret == TI_OKAY);

Calling From Lua (with Tulip Chart bindings)

-- Example usage of Detrended Price Oscillator
dpo = ti.dpo(input, 5)

Example Calculation

period = 5

dateinputdpo
2005-11-0181.59
2005-11-0281.06
2005-11-0382.87
2005-11-0483.00
2005-11-0783.61-1.37
2005-11-0883.150.13
2005-11-0982.84-0.09
2005-11-1083.990.29
2005-11-1184.55-0.48
2005-11-1484.36-0.94
2005-11-1585.53-0.26
2005-11-1686.54-0.44
2005-11-1786.89-1.21
2005-11-1887.77-0.69
2005-11-2187.29-0.26

Chart

 

Other Indicators

Previous indicator: Directional Movement

Next indicator: Directional Movement Index

Random indicator: Vector Arccosine