EMA2 ( int First Bar);
First Bar: 0
Returns the exponential moving average (EMA) of
data with a
smoothing factor. The
prefetch parameter controls the number of historical data points used to initialize the EMA for the first bar. The
First Bar parameter is deprecated and should not be used.
The calculation formula of the EMA2 is the same as in ExpAverage, with the only difference that you need to explicitly specify the smoothing factor instead of length.
Note that in thinkScript®, exponential moving averages use prefetch, see the Past Offset and Prefetch article for details.
|data||-||Defines data for which the average is found.|
|prefetch||0||Defines the number of historical data points used to initialize EMA for the first bar.|
|smoothing factor||-||Defines smoothing factor for calculation of the average, see the formula.|
|First Bar||0||Deprecated parameter.|
input additionalBars = 0;
plot ExpAvg = EMA2(close, additionalBars, 0.2);
The code plots the exponential moving average of the close price with a smoothing factor of 0.2. Note that all studies using
EMA2 fetch a necessary number of additional bars for correct initialization, thus adding more initialization data by increasing
additionalBars input has little impact on the study.