3.5.2.24 Mmovavg

Description

This function is for calculating modified moving averages. Average value at the starting point = n is calculated by Movavg function, and then other points are calculated by formula similar to Emovavg function with weighting factor $\alpha = 1/n$.

$M_i=\left\{\begin{matrix} m_n, & \textup{if} \; i = n;\\ (1-\alpha)M_{i-1} + \alpha x_i, & \textup{if} \; i > n, \end{matrix}\right.$

where $m_n$ is the nth point calculated by movavg(x, n-1,0).

Syntax

vector mmovavg(vector vd, int n)

Parameters

vd

The data vector used to calculate modified moving average.

n

is the timeperiod.

Return

Return the modified moving average vector.

Example

// Col(2) will be filled with modified moving average value at each point, with stating point = 10.

for(ii=1;ii<=30;ii++) col(1)[ii] = ii;
col(2)=mmovavg(col(1),10);