PureBytes Links
Trading Reference Links
|
OK, now I understand what I was confused about. AFL is much simpler than I
had imagined.
I thought that the script is executed once completely for each bar, from the
first bar to the last. To allow this, I thought the array expressions were
interpreted relative to the current bar, so that A + B means A[currentBar] +
B[currentBar]. This seemed reasonable because every bar should only depend
on previously calculated data, either earlier in the script or in previous
bars.
Moreover, doing the calculation that way would allow realtime processing to
run the script on just the very last bar, rather than repeat it for all bars
in the time range (or required bars). I really think AFL should have this
feature somehow.
Never mind how I imagined the script got ahold of future data, which shouldnt
be allowed anyway. Another contradiction was how explicit loops relate to
the array operations.
So the correct model (I believe) is that A + B iterates through the entire
array(s) at that time. And Ref(A, -1) creates a new array that shifts the
entire array of A forward one bar before doing anything else. That's why
you can't do the equivalent of accumulating across all bars without an
explicit loop or by using the Cum function (or maybe faking it with some
other function that has the effect of accumulating).
Cum(x):
Cum[0] = x;
for (i = 1; i < lastBar; i++)
Cum[i] = Cum[i-1] + x;
I'd like to see clear documentation on all this in the reference manual.
On Thursday 06 April 2006 01:05 am, Graham wrote:
> You will not get a cumulative effext by referencing the variable
> within itself like this
> Result1 = Ref(Result1, -1) +
> Iif( Higher, Iif( Close > Open, 1.5, 1),
> Iif( Lower, Iif( Close < Open, -1.5, 1), 0));
>
> If you do not want to use loops which is far better you could try
> this.
Do you mean that it is far better to use loops, or to not use loops? I
assumed it was better to not use loops, to let AmiBroker internals do the
looping, instead of interpreting the loop in script code.
> From what I can see your results will be different because you
> ahve added a different value for result1 with the added conditions and
> values
>
> Result1 = cum(
> Iif( Higher, Iif( Close > Open, 1.5, 1),
> Iif( Lower, Iif( Close < Open, -1.5, 1), 0)) );
You are correct -I made a mistake. The "1" in the last line should be "-1".
The results are still different between the explicit loop and using the AFL
array calculations. The explicit loop seems to not start at the beginning of
the data, when viewing the charts. I guess this is caused by the "quick"
mode.
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|