|
Steve,
An outstanding explaination. Thanks for taking the
time to put it together.
Dave
I think it is good enough to be converted to a PDF and
uploaded so it can be pointed to in the future. I would be glad to do so
unless you want to tweak it somemore. From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of Steve Dugas Sent: Monday, July 24, 2006 7:09 AM To: [email protected] Subject: Re: RE: RE: [amibroker] Re: I am lostII Hi Allen - Here are the basics of a simple loop,
hope it is helpful to someone...
In "regular" AFL, all elements of the data arrays
are automatically processed at once. So for example
Close = 0;
will automatically initialize the entire Close
array ( all dates ) by setting all of its elements to zero ( or more
precisely, a working copy of Close, since actual database is not overwritten ).
In general, it is quicker and easier to use this regular AFL - loops are really
only necessary when you need to access individual array elements for some
reason. A simple loop "template" would be
for ( beginning counter value; test for
condition(s) to break out of loop; increment counter )
{
code to do whatever you
want to current array element
}
Now we will turn the template into a real
loop. "i" is simply a variable that accepts a numeric value and acts as a
counter. We will increment it with each pass through the loop to keep track of
where we are. The letter "i" is commonly used for this because, I
beleive, it stands for "integer", but we can actually use any variable name
we want, such as "count", etc
for( count = 0; count < BarCount; count++
)
{
Close[count] = 0;
}
This also initializes the count array to zero, but
one element at a time. As you can see, using regular AFL is easier 8
- ) Now we will "pick apart" the loop a bit...
for ( count = 0
Since we want to start with the first array element
( element # 0 ), we initialize the counter at 0. The loop reads this
code just once at the beginning to see where to start, it will not be
rechecked after the loop starts running.
count < Barcount
BarCount is the number of data bars for any given
ticker. Lets say it is 1000, so the actual elements of the Close array
would be numbered 0 - 999.
"count < Barcount" tests to see if it is time to
stop looping yet. It means "continue doing loops while count is less than
Barcount." Since we have just set "count" to 0, it is less than 1000 so the loop
will be entered.
{
Close[count] = 0;
}
This is the "body" of the loop - it contains the
instructions to be performed on each pass through the loop. Here we are just
initializing a single element of the Close array to 0. On this pass, the
variable "count" is set to 0, so Count[0] ( first element ) will be set to
0.
count++ ) // back up to the header now
This is just a short way of writing "count = count
+ 1". We are just incrementing the count by one. When we are incrementing by 1,
we are allowed to use this "shorthand". If we were incrementing by anything
else, like 2 or 3, we would have to write "count = count + 2", etc. So next,
count is incremented from 0 to 1.
Now, the first pass is done, and subsequent
passes will continue repeating the same above steps until the end of the array
is reached -
1. Is count still < Barcount? If so, do
another pass through loop, if not, time to exit the loop.
2. If doing another pass, set Close[count] ( next
element ) to 0
3. increment counter again so next elent is
accessed on next pass
If this sounds too simplstic or condescending, I
apologize. Or, if you have any questions, feel free to ask...
Steve
__._,_.___ 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
|
- Re: RE: RE: [amibroker] Re: I am lostII allansn
- RE: RE: RE: [amibroker] Re: I am lostII MarketMonk777
- Re: RE: RE: [amibroker] Re: I am lostII Steve Dugas
- RE: RE: RE: [amibroker] Re: I am lostII MarketMonk777
- RE: [amibroker] Re: I am lostII brian.z123
