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

Re: Local variable initialization



PureBytes Links

Trading Reference Links

The Xaverage pseudocode is something like:

factor = 2/(1 + length)
avg = (avg[1] * (1 - factor)) + (factor * price)

If you initialize avg at 0, it will take forever to creep up to the
(nearly) correct value if length is large. Rather it should be
initialized to the price so it starts closer to the correct value:

input: price(close), length(200);
var: factor(2/(1+length)), avg(price);

Joel Reymont wrote:
> 
> Bob,
> 
> What is wrong with the code then? You mentioned it as an example of
> an initialization error and said that Avg hundreds of bars to reach
> near the correct value.

-- 
  Dennis