Emovavg
Contents
Description
This function is for calculating exponential moving averages, where the weight factors decrease exponentially. The degree of weighting decrease is defined as
, where n = timeperiod. Two methods involved to start the calculation.
- Method I: starts from point = n
/math-cb4674a0247744be000499a97eb99cfa.png)
- Method II: starts from point = 1
/math-2704b153731968a5242634bf655320b2.png)
Syntax
vector emovavg(vector vd, int n[, int method=0])
Parameters
vd
- The data vector used to calculate exponential moving average.
n
- is the timeperiod.
method
- is the method controller.If we set method = 1, then we use Method II described above. And by default method = 0, which means using Method I.
Return
Return the exponential moving average vector.
Example
// Col(2) will be filled with exponential moving average value at each point, //with stating point = 10. // Col(3) will be filled with exponential moving average value at each point, //with stating point = 1. for(ii=1;ii<=30;ii++) col(1)[ii] = ii; col(2)=emovavg(col(1),10); //method I col(3)=emovavg(col(1),10, 1); //method II