PureBytes Links
Trading Reference Links
|
> The problem is that this won't produce the results I expect until
> CurrentBar = 20 because (using CurrentBar = 1 as reference) Value[20]
> through Value[1] aren't initialized with C[20] through C[1] but
> instead 0.
Assuming you set MaxBarsBack to 20, then at CurrentBar = 1, you
have 20 bars of Close data. That is the FIRST bar where your
indicator is called, so it's the first bar where you can compute
your transformation on Close. You cannot have a value of Value1
before CurrentBar = 1.
So if you want a 20-bar average of Value1, you have to set MBB to
20 and do something like this:
Value1 = <whatever>;
if CurrentBar > 20 then begin
Avg = average(Value1, 20);
...
end;
You *can't* calculate Avg any sooner than bar 41, because you
need 20 bars of Value1, and you can't start calculating Value1
until bar 21 (when CurrentBar = 1 and bar > MBB), because you
have to set MBB to at least 20 so you can look back 20 bars for
your average.
Who cares about the first 40 bars anyway? Just make your chart
longer and don't pay attention to the first bit.
Gary
|