[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XAverage on Array



PureBytes Links

Trading Reference Links

> >I thought he was after an xaverage of the 20 elements in his array,
> >not a 20 bar xaverage of the [0] element of the array...  Your code
> >gives him the xaverage of the [0] element over 20 bars and ignores
> >the other 19 elements of the array on each bar... 
> 
> Dennis' code is probably what you really want.  

I agree, Dennis has the right idea.

You can take the **average** of the elements in a 20-element array, 
but OM is right that it doesn't make a lot of sense to take the 
**xaverage** of the array.  You could run the xaverage calculation on 
just the 20 elements of the array, as JimO showed, but I doubt that's 
what you want.  That gives you the equivalent of an xaverage on the 
first 20 bars of a chart, and discards all information about the 
previous data.  It certainly wouldn't give the same results as a 
"real" xaverage.

average uses ONLY the data in the last N bars, which is why e.g. a 
spike or gap will suddenly drop out of your average N bars later.  
xaverage is an ongoing calculation that depends on the previous data 
fed into it, including data more than N bars ago.  That's why 
xaverage doesn't have the N-bars-later-dropout problem.  Instead of 
dropping out abruptly like in a simple average, the spike fades out 
gradually with an exponential decay.  And you only need one data 
point (the [0] element in your case) to compute the xaverage of the 
"last N elements" -- because xaverage has already incorporated the 
previous N-1 elements (and, actually, ALL previous elements) into the 
previous xaverage value.


Gary