ExpAverage

ExpAverage ( int length );

Default values:

length: 12

Description

Returns the exponential moving average (EMA) of data with length.

The formula for the calculation of the exponential moving average is recursively defined as follows:

EMA1 = price1;

EMA2 = α*price2 + (1 - α)*EMA1;

EMA3 = α*price3 + (1 - α)*EMA2;

EMAN = α*priceN + (1 - α)*EMAN-1;

where α is a smoothing coefficient equal to 2/(length + 1).

Note that in thinkScript®, exponential moving averages use prefetch, see the Past Offset and Prefetch article for details.

Input parameters

Parameter Default value Description
data - Defines data for which the average is found.
length 12 Defines period on which the average is found.

Example

input price = close;
input length = 12;
plot ExpAvg = ExpAverage(price, length);

The example plots an exponential moving average of a security's Close price.