PureBytes Links
Trading Reference Links
|
Hello Daniel - I didn't try to understand what you
understand, but hope this helps.
As an indicator or/and explore exercise, Try
the indicator. Uses the native AFL CUM function
and compares it with accumulating the hits in a
loop while plotting the result.
Best regards
Joe
// Using native AFL CUM function rather than looping through an array
//
Accum[ 0] = 0;
// Build array of 1's and 0's based on the logic
Array = Volume > EMA(V,50);
for (i = 1; i <=
BarCount-1; i++)
{
if (array[i]==1)
{
Accum[i] = Accum[i- 1] +
1;
}
else
accum[i] = accum[i- 1];
}
// AFL
Accum2 = Cum(array);
Title = "Counting all the hits where
vol > than 50 day moving average = " + WriteVal(accum) + "\n" +"Using the AFL function Cum= " + WriteVal(Accum2);
Plot (accum2,"accum2",colorBlue,styleThick);
Filter = 1;
AddColumn (array,"Vol
Hits");
AddColumn (accum,"Accum",1.0);
AddColumn (accum2,"Accum2",1.0);
----- Original Message -----
Sent: Sunday, April 09, 2006 12:19
PM
Subject: Re: [amibroker] Re: AFL drives
me nuts
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
SPONSORED LINKS
YAHOO! GROUPS LINKS
|
|