PureBytes Links
Trading Reference Links
|
On Thu, Dec 3, 2009 at 1:15 PM, bistrader <bistrader@xxxxxxxxx> wrote:
i is element of array; i++ is counter for "for" statement. Loop goes thru all values. Better, in my opinion, is iff as defined below.
Not quite.
If you're going to write a program or script, you have to be more precise than that. 'i' is not an element of the array. Rather it is an index referring to an element of the array (the precise concept of what 'i' is depends on what programming language you're using, but what I have given here is good enough for someone beginning his exposure to programming using AFL). 'i++' is not a counter. Rather it is a statement applying the unary operator '++' to the index 'i'. It is correct, though, that it loops through all the elements of the array.
A for loop in AFL (and in C++ and Java and a number of related languages) has a structure you need to understand. That is "for (initialization code ; test ; end code)". You can see that in action in your example. "i = 0" creates and initializes your index variable. "i
< BarCount" verifies that 'i' always has a value less than 'BarCount'. If this test fails (returns false) the _expression_ 'Close[i]' would refer to an element that is not in the array. This test, therefore, ensures that the loop operates only on elements that really exist in the array. The end code 'i++' increments the value of 'i' by one after all the work in the loop is complete, and basically restarts the loop with the incremented value of 'i' (so once it is finished with one element in the array it can work on the next). This keeps going until 'i' has the same value as 'BarCount - 1' . At the end of the loop where 'i' has that value, it is given the value 'BarCount', and the test fails. At that point, execution resums on the next executable statement after that body of the loop.
I could be wrong, but my impression on a first examination of AFL is that a large proportion of the syntax and semantics of AFL is borrowed from C++. If 'learner' is unfamiliar with programming, any introductory text on C++ may be helpful in understanding more fully AFL. Having had some experience teaching software engineering, I would not regard the documentation provided with AmiBroker or in the books related to it as a suitable introduction to programming using AFL (rather, those seem more appropriate as a reference for someone who is already a reasonably proficient programmer). If the developers of AmiBroker are inclined to accept advice from someone like me, I'd suggest an extra book that would take the description of AFL, provided in the Introduction to AmiBroker, and expand it into a book that could serve as an introductory programming book that happens to use AFL (using one of Stroustrup's books on C++, or Koenig and Moo's book on C++ as a model).
I won't comment on the relative benefit of the function 'iff' as I have not tested it or executed benchmarks using it.
HTH
Ted
--- In amibroker@xxxxxxxxxxxxxxx, "Ton Sieverding" <ton.sieverding@xxx> wrote:
>
> What about :
>
> color = iif(C>0,colorgreen,colorred);
>
> Regards, Ton.
>
> ----- Original Message -----
> From: Joe Landry
> To: amibroker@xxxxxxxxxxxxxxx
> Sent: Thursday, December 03, 2009 3:28 PM
> Subject: Re: [amibroker] please read this formula and tell what it is?
>
>
>
>
> Is this a test?
> Joe
> ----- Original Message -----
> From: learner
> To: amibroker@xxxxxxxxxxxxxxx
> Sent: Thursday, December 03, 2009 8:12 AM
> Subject: [amibroker] please read this formula and tell what it is?
>
>
>
> for( i = 0; i < BarCount; i++ )
> {
> if( Close[ i ] > Open[ i ] ) // CORRECT
> Color[ i ] = colorGreen;
> else
> Color[ i ] = colorRed;
> }
>
>
>
>
>
> please read above formula and tell me what is i and i++
> what it does exactly?
> thankyou for support
>
-- R.E.(Ted) Byers, Ph.D.,Ed.D. TED@xxxxxxxxxxxxxxxxxxxxxxxCTO Merchant Services Corp. 350 Harry Walker Parkway North, Suite 8
Newmarket, Ontario L3Y 8L3
__._,_.___
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
__,_._,___
|