Returns the exponentially weighted moving (rolling/running) average using the previous N data points.

## Syntax

**NxEMA**(**X, Order, N, Variant, Return**)

- X
- is the univariate time series data (a one-dimensional array of cells (e.g., rows or columns)).
- Order
- is the time order in the data series (i.e., the first data point's corresponding date (earliest date = 1 (default), latest date = 0)).
Order Description 1 Ascending (the first data point corresponds to the earliest date) (default). 0 Descending (the first data point corresponds to the latest date). - N
- is the smoothing period expressed in the number of data points (e.g., days).
- Variant
- is the variant/type of the exponentially weighted moving average (i.e., 0 = Simple (default), 1 = Double, 2 = Triple, 3 = Zero-lagged). If missing or omitted, a simple exponentially weighted moving average (i.e., Variant = 0) is assumed.
Value Description 0 Plain/simple exponentially weighted moving average (EMA). 1 Double exponentially weighted moving average (D-EMA). 2 Triple exponentially weighted moving average (T-EMA). 3 Zero-lagged exponential-weighted moving average (ZLEMA). - Return
- is return type of the function: 0 = last/most recent value (default), 1 = filtered time series (array.
Value Description 0 Return smoothed value of the Last/most-recent observation. 1 Return the whole smoothed time series (array).

## Remarks

- The time series is homogeneous or equally spaced.
- The time series may include missing values (e.g., #N/A) at either end.
- The formula of exponential moving average definition is expressed in technical analysis terms as follows: $$ \textrm{EMA}_t = \textrm{EMA}_{t-1} + \alpha \times ( x_t - \textrm{EMA}_{t-1}) $$ Where:
- $\textrm{EMA}_t$ is the exponential moving average at time $t$.
- $x_t$ is the value of the time series at time $t$.
- $\alpha$ is the smoothing factor (between 0 and 1) that represents the degree of weighting decrease. For EMA, the $\alpha$ is expressed as follows: $$ \alpha = \frac{2}{N+2} $$ Where:
- $N$ is the smoothing period expressed in the number of data points (e.g., days)

- The exponential moving average with a smooth period of N data points is expressed by N-period EMA.

- The double exponential moving average (aka. DEMA or D-EMA) is expressed as follows: $$\textrm{D-EMA}_t = 2 \times \textrm{EMA}_t -\textrm{EMA}(\textrm{EMA})_t$$ Where:
- $\textrm{EMA}(\textrm{EMA})$ is the exponential moving average of the exponential moving average.

- The triple exponential moving average (aka. TEMA or T-EMA) is expressed as follows: $$\textrm{T-EMA} = 3\times \textrm{EMA}_t -3\times\textrm{EMA}(\textrm{EMA})_t + \textrm{EMA}(\textrm{EMA}(\textrm{EMA}))_t$$
- For zero-lag exponential moving average (ZLEMA), $$ k = (N-1)/2 $$ $$ Y_t = x_t + (x_t - x_{t-k})$$ $$ \textrm{ZLEMA}_t = \textrm{EMA}_t^N (Y_t) $$ Where:
- $k$ is the number of periods used to remove the cumulative effect of the moving average.
- $Y_t$ is the de-lagged data. Data is de-lagged by removing the data from k-periods ago, thus removing the cumulative effect of the moving average.

- In the case the smoothing period ($N$) is an even number, then $k$ and $Y_t$ are calculated as follows: $$ k = \frac{N}{2}$$ $$ Y_t = 2x_t - \left(\frac{x_{t-k}+x_{t-k-1}}{2}\right)$$
- The ZLEMA technical indicator was created by John Ehlers and Ric Way.
- The NxEMA function is available starting with version 1.66 PARSON.

## Files Examples

## Related Links

- Wikipedia - Moving average.
- Wikipedia - Zero lag exponential moving average.
- Wikipedia - Double exponential moving average.
- Wikipedia - Triple exponential moving average.

## References

- R.J. Hyndman, A.B. Koehler, "Another look at measures of forecast accuracy", International Journal of Forecasting, 22 (2006), pp. 679-688.
- James Douglas Hamilton; Time Series Analysis; Princeton University Press; 1st edition (Jan 11, 1994), ISBN: 691042896.
- Tsay, Ruey S.; Analysis of Financial Time Series; John Wiley & SONS; 2nd edition (Aug 30, 2005), ISBN: 0-471-690740.
- D. S.G. Pollock; Handbook of Time Series Analysis, Signal Processing, and Dynamics; Academic Press; Har/Cdr edition (Nov 17, 1999), ISBN: 125609906.

## Comments

Please sign in to leave a comment.