{_xStdDev Exponential moving standard deviation
by Alex Matulich alex@unicorn.us.com 5/2003
_xStdDev(x,n) returns a good approximation of the standard deviation
of n values of x. In _xStdDev the terms have exponential weight so
the function reacts faster, and recovers from outliers more quickly
than the traditional standard deviation. This makes it well-suited
for use in time series analysis.
}
Inputs:
x(NumericSeries), {price data}
length(NumericSimple); {"lookback" length; can change mid-stream}
Vars:
w0(0), w1(0), {exponential weights}
n(0), {used as sample size}
avx(0); {average of x and average of x^2}
if n <> length or CurrentBar <= 1 then begin {initialize things}
n = length;
w0 = 2/(n+1);
w1 = 1 - w0;
if Currentbar <= 1 then avx = x;
end;
avx = w0*x + w1*avx[1];
_xStdDev = SquareRoot(w0*(x-avx)*(x-avx) + w1*_xStdDev[1]*_xStdDev[1])