What's wrong with the built-in EMA function?

Code:

// variable period EMA
function cEMA( array, period )
{ // by T.Janeczko, http://www.amibroker.com/guide/h_understandafl.html
// initialize first value
vaexp[ 0 ] = array[ 0 ];
for( i = 1; i < BarCount; i++ ) {
// calculate the value of smoothing factor
factor = 2/(period[ i ] + 1 );
// calculate the value of i-th element of array
// using this bar close ( close[ i ] ) and previous average value ( vaexp[ i - 1 ] )
vaexp[ i ] = factor * array[ i ] + ( 1 - factor ) * vaexp[ i - 1 ];
}
return vaexp;
}

Code:

// variable period EMA
function varperEMA( array, period )
{// by T.Janeczko
return AMA( array, 2 / ( period + 1 ) );
}

## Bookmarks