The Exponential Moving Average (EMA) is calculated using the following iterative algorithm, where
n
is the “number of days” for the moving average (starting with 1):p = 2 / (interval+1) EMA[0] = input[0] * p EMA[n] = EMA[n-1] * (1–p)For example, applying the EMA calculation to the following input sequence of values:
{335, 808, 45, 402, 732, 48, 805, 450, 385, 420, 367, 69}with the interval argument of
7
produces the following result sequence:{335.000000, 453.250000, 351.187500, 363.890625, 455.917969, 353.938477, 466.703857, 462.527893, 443.145920, 437.359440, 419.769580, 332.077185}The valid windows can be verified using the following table (built with Microsoft Excel version 2010 or later) where
p = 2/8 = 0.25
:
![]()
Note that the first 6 values for
seq_window_agg_ema_TYPE()
(highlighted above) should be ignored for this interval of 7 (see note in the Window versus Grid Aggregate page).