WildersAverage ( int length);
Returns the Wilder's Moving Average of
data with a smoothing coefficient that equals
1/length. The first value is calculated as the simple moving average and then all values are calculated as the exponential moving average.
The formula for the calculation of the average can be recursively defined as:
MAWilders1 = SMA(length);
MAWilders2 = α*price2 + (1 - α)*MAWilders1;
MAWilders3 = α*price3 + (1 - α)*MAWilders2;
MAWildersN = α*priceN + (1 - α)*MAWildersN-1;
where α is the smoothing coefficient equal to
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.|
|length||12||Defines period on which the average value is found.|
input length = 10;
plot WildersAvg = WildersAverage(close, length);
plot ExpAvg = EMA2(close, 0, 1 / length);
This code draws two plots: the first is a Wilder's average of the Close price, and the second is the exponential moving average with the corresponding smoothing factor. The two plots differ to a certain extent due to variance in initialization.