ÿþfunction XAverage; //made by Werner Voets input price = close, Length = 20; result XAvg(series); vars SmoothingFactor = 0, i=0; begin SmoothingFactor := (2 / (Length + 1)); i := front(price); XAvg[i] := price[i]; for i := front(price)+1 to back(price) do begin XAvg[i] := XAvg[i-1] + SmoothingFactor * (price[i] - XAvg[i-1]); end; end. /* the Xaverage code is this: > > inputs: > Price( close ), //this is the value considered for the calc// > Length( 20 ) ; //This are the periods to calc the Avg// > > variables: > SmoothingFactor( 2 / ( Length + 1 ) ) ; > > if CurrentBar = 1 then > XAverage = Price > else > XAverage = XAverage[1] + SmoothingFactor * ( Price - XAverage[1] ) ; > //the [1] means "one bar ago" - it is comparable to ref in Amibroker// */