Zero-Lag Exponential Moving Average

Technical Analysis Indicator: zlema

Fork me on GitHub

Function Prototype

/* Zero-Lag Exponential Moving Average */
/* Type: overlay */
/* Input arrays: 1    Options: 1    Output arrays: 1 */
/* Inputs: real */
/* Options: period */
/* Outputs: zlema */
int ti_zlema_start(TI_REAL const *options);
int ti_zlema(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.

Zero-Lag Exponential Moving Average modifies a Exponential Moving Average to greatly reduce lag.

It takes one parameter, the period n.

It is calculated for each bar as follows:

$$a = \frac{2}{n+1}$$
$$zlema_{t} = (1-a)zlema_{t-1} + (a)(in_{t} + (in_{t}-in_{t-(\frac{n-1}{2})}))$$

See Also

References

Example Usage

Calling From C

/* Example usage of Zero-Lag Exponential Moving Average */
/* 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]; /* zlema */

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

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

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

Calling From Lua (with Tulip Chart bindings)

-- Example usage of Zero-Lag Exponential Moving Average
zlema = ti.zlema(input, 5)

Example Calculation

period = 5

dateinputzlema
2005-11-0181.59
2005-11-0281.0681.06
2005-11-0382.8782.09
2005-11-0483.0083.04
2005-11-0783.6183.48
2005-11-0883.1583.42
2005-11-0982.8482.97
2005-11-1083.9983.59
2005-11-1184.5584.48
2005-11-1484.3684.56
2005-11-1585.5385.21
2005-11-1686.5486.38
2005-11-1786.8987.00
2005-11-1887.7787.67
2005-11-2187.2987.68

Chart

 

Other Indicators

Previous indicator: Weighted Moving Average

Random indicator: Crossany