[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Boolean question



PureBytes Links

Trading Reference Links

Hello,

Like many scripting languages, AFL is a loosely typed language, which
means in computer science parlance that you don't have to explicitly
declare the type of your variables before you use them. The type of a
variable is automatically inferred from the type of the expressions
assigned to that variable.

The advantage is that scripts can be written in just a few lines of
code, without any formal variable declarations being required.  

This disadvantage is that sometimes the meaning (semantic) of scripts
can become more difficult to understand.  For example, it can be much
more difficult to see quickly what the type of a variable is.

> T1=20;
> Z1=BarIndex()>T1;
> 
> Does Z1 contain a boolean response?
> 

I'm still new to AFL, but my understanding of the example given in the
question would be as follows:

BarIndex() returns an Array (as per the AB help).

Hence also the "greater than" operator '>' returns an array.   It
compares the elements of the BarIndex()-array element-wise with 20. 
In the result array either 0 or 1 is stored is stored for each
element-wise comparison respectively,  with 0 indicating false and 1
indicating true.     The result array is an array of float numbers, so
its type is actually "array of float"  and not "array of boolean".

If I'm not mistaken, AFL has actually not any real boolean variables.
It interprets a float value of 0 as false, and a float value not equal
 to 0 as true.

So the answer to the question is: Z1 is an array of float values.

> Anyone know how to convert Z1 to boolean?

in order to convert Z1 to a boolean value (actually a float value),
you need to reference a specific element of the array

This can be done with the array access operator '[]', e.g. with an
expression like result[i],  with i specifying the index of the array
element you want to refer to.


Hope it helps,

Wolfgang


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get A Free Psychic Reading! Your Online Answer To Life's Important Questions.
http://us.click.yahoo.com/Lj3uPC/Me7FAA/CNxFAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/