Variable Index Dynamic Average

Technical Analysis Indicator: vidya

Fork me on GitHub

Function Prototype

/* Variable Index Dynamic Average */
/* Type: overlay */
/* Input arrays: 1    Options: 3    Output arrays: 1 */
/* Inputs: real */
/* Options: short period, long period, alpha */
/* Outputs: vidya */
int ti_vidya_start(TI_REAL const *options);
int ti_vidya(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 Variable Index Dynamic Average indicator modifies the Exponential Moving Average by varying the smoothness based on recent volatility.

It takes three parameters: a short period n, a long period m, and a smoothing factor a. a is usually 0.2.

It is built up using a ratio of a long Standard Deviation Over Period to a short Standard Deviation Over Period as as smoothing factor.

The calculation is as follows:

$$\text{short_ma}_{t} = \frac{1}{n} \sum_{i=0}^{n-1} in_{t-i}$$
$$\text{short_stddev}_{t} = \sqrt {\frac{1}{n} \sum_{i=0}^{n-1} (in_{t-i}-\text{short_ma}_{t})^{2}}$$
$$\text{long_ma}_{t} = \frac{1}{m} \sum_{i=0}^{m-1} in_{t-i}$$
$$\text{long_stddev}_{t} = \sqrt {\frac{1}{m} \sum_{i=0}^{m-1} (in_{t-i}-\text{long_ma}_{t})^{2}}$$
$$s = a \cdot \frac{\text{short_stddev}_{t}}{\text{long_stddev}_{t}}$$
$$\text{vidya}_{t} = (1-s)\text{vidya}_{t-1} + (s)in_{t}$$

Alternately, it can be expressed in terms of Standard Deviation Over Period like this:

$$s = a \cdot \frac{\text{stddev}_{t}(in,n)}{\text{stddev}_{t}(in,m)}$$
$$\text{vidya}_{t} = (1-s)vidya_{t-1} + (s)in_{t}$$

See Also

References

Example Usage

Calling From C

/* Example usage of Variable Index Dynamic Average */
/* Assuming that 'input' is a pre-loaded array of size 'in_size'. */
TI_REAL *inputs[] = {input};
TI_REAL options[] = {2, 5, .2}; /* short period, long period, alpha */
TI_REAL *outputs[1]; /* vidya */

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

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

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

Calling From Lua (with Tulip Chart bindings)

-- Example usage of Variable Index Dynamic Average
vidya = ti.vidya(input, 2, 5, .2)

Example Calculation

short period = 2, long period = 5, alpha = .2

dateinputvidya
2005-11-0181.59
2005-11-0281.06
2005-11-0382.87
2005-11-0483.0083.00
2005-11-0783.6183.04
2005-11-0883.1583.05
2005-11-0982.8483.02
2005-11-1083.9983.29
2005-11-1184.5583.40
2005-11-1484.3683.43
2005-11-1585.5383.71
2005-11-1686.5484.02
2005-11-1786.8984.12
2005-11-1887.7784.39
2005-11-2187.2984.58

Chart

 

Other Indicators

Previous indicator: Vertical Horizontal Filter

Next indicator: Annualized Historical Volatility

Random indicator: Balance of Power