Why is the type of variable changing?

Trying to come to grips with AB field types. Why does the type change as below?

Buy = close;
_TRACE(typeof(buy));
Buy = IIf(False == False, False, False);
_TRACE(typeof(buy));

Buy = close;
_TRACE(typeof(buy));
Buy = false;
_TRACE(typeof(buy));

gives
image

@garydown,

See Understanding AFL.
See how-to-ask-a-good-question.

Only users with "Verified Badge" are allowed to post on this forum.
Search "Verified Badge" for more information on how to get verified.

Thanks TrendSurfer,
I am aware of verified badge requirement and am in the process of getting a license (awaiting reply to an email). As this is the presale/trial forum I would expect that simple questions like mine which may decide any future path would be acceptable.
I have read (several times) the suggested links.

Will try to improve my asking, but in the meantime I thought this would be such a simple thing (obviously not too simple as I had to ask).

Cheers.

AFL is dynamically typed. Which means that type of variable can change. The variable type depends on last assignment, so each assignment may change the type if you are assigning value that has different type.

REQUIRED reading:

In short Close is an array. False is constant equal to 0 (a number).

Note that numbers are accepted in places where functions expect arrays because of type coercion:

Thanks guys,
I re-read the articles and have achieved an array of zeros

buy = close - close;

As soon as I read the info again I remembered what I needed. Guess the sponge between my ears is a bit leaky.

Yes - for your first 30 days.

Everyone's sponge is leaky, key is to keep the sponge saturated (by learning) and then not let it go dry (keep learning / re-pouring).

@garydown - you do NOT NEED array of zeros. NEVER. In all places that require array
you can use just 0. Scalar (plain number) can be used in ALL places that accept array.
So no, you should not write close-close as it is waste of resources. Write 0 instead.

It is explained in link I already provided. JUST READ IT carefully. Don't skip When scalar becomes an array, aka. type coercion in AFL

Thanks Tomasz,
I am slowly coming to an understanding (have read through the doco few times now).
Amended the code to "=0" as suggested,
The next reference to the Buy variable does actually change it from a number to an array.

_TRACE("3 " + typeof(Buy));
                Buy[barI] = True;
_TRACE("4 " + typeof(Buy));

gives
image
It was this changing the type that was confusing me.

Thanks again,
Gary.

If you use subscript operator [index] on scalar (numeric) variable, it automatically gets upsized to array. This was explained in: When scalar becomes an array, aka. type coercion in AFL

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.