this
Description
Exponential moving averages (EMA's) are used in technical analysis for a number of purposes. They may be used as smoothing periods to dampen volatility for input into another calculation or they may be used as signal lines to trigger buy or sell points. Most TA indicators use EMA's or other types of moving averages for various functions. An EMA is weighted moving average series of series over a specified period of time. Many believe that the EMA is more responsive than an SMA under certain circumstances. The EMA is weighted toward more recent data by a transfer function. In other words, some portion of the most recent value of a series is counted more than once when calculating an EMA.

Inputs
val
is the input series to calculate the EMA over the lookback period, p. val should be a real or double precision vector (single column) matrix. p must be an integer scalar

Output
The output will be a vector matrix of the same type as val. Note that for values prior to the lookback period, the output will be represented by the value of val up to the index p-1, since the EMA would not exist for time periods prior to p. In other words if a 20 period EMA were requested values 1 through 19 would be equal to val(1::19), since an average cannot be made over 20 periods if the data does not exist. EAS substitutes val(1::p-1) into the EMA to preserve the matrix length so that the output may be used in further calculations using matrices of the same length.

Example
Entering ([ema((1::10)^2,5),sma((1::10)^2,5)]) in the O-Matrix Command line produces the following output:

          {
          [  1.00 ,  1.00 ]
          [  4.00 ,  4.00 ]
          [  9.00 ,  9.00 ]
          [ 16.00 , 16.00 ]
          [ 11.00 , 11.00 ]
          [ 19.33 , 18.00 ]
          [ 29.22 , 27.00 ]
          [ 40.81 , 38.00 ]
          [ 54.21 , 51.00 ]
          [ 69.47 , 66.00 ]
          }

Notice that output values 1-4 are simply the first four digits of the series (1-10)^2 and ema produces different results over time than sma.