Description
Simple moving averages (SMA'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 SMA's or other types of moving averages for various functions. An
SMA is simply a running series of an average value of another series over a specified
period of time.
Inputs
val is the input series to calculate the SMA 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 SMA would not exist for time periods
prior to p. In other words if a 20 period SMA 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 SMA to
preserve the matrix length so that the output may be used in further calculations using
matrices of the same length.
Example
Entering sma((1::10),5) in the O-Matrix Command line
produces the following output:
{
1
2
3
4
3
4
5
6
7
8
}
Notice that output values 1-4 are simply the first four digits of the series 1-10.