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

[amibroker] Re: Treament of Null Value



PureBytes Links

Trading Reference Links

Hello David,

This is a very good question that deserves a good answer.
Truly this is a question for the alpha-techs but all you got was me.

At the moment I limit myself to no more than one topic a week and 
you are the lucky, or unlucky, chosen one.
After this I may change to one a month.

Here are my credentials so you can decide if it is worth your while 
to read on:

I am a free man first and trading comes somewhere after that (along 
with husband, father, grandfather, cook, gardener, handyperson etc).
As a trader I only learn the math/programming/computer techs that I 
am obliged to.
In my answers I aim to provide enough leads to enable the forum to 
prove me right or wrong, if they so choose.
I don't provide answers; only directions towards them (you have to 
climb the mountain yourself).
I seldom elaborate, except to correct my errors or clarify my points.
This may seem harsh but anyone who can't follow some simple 
guidelines is highly unlikely to make a good trader so it is in 
their best interests if they are knocked out of the game early.
I like to assist people to succeed but I leave them to fail alone.

There has been a lot of interesting dicussion on this or related 
subjects in this forum  in the past.
It is a topic best considered as part of group rather than as a 
standalone.
I used the advanced search feature of this forum to search subject 
headings for NAN, NULL, EMPTY, IEEE, FINITE, TRUE.
There are additional messages with these topics in the body but I 
found sufficient information even when limiting the search to 
subject only.
There are some good links in the messages that go to advanced or 
tech level references if required. 
They also include posts by Tomasz that explain the AB philosophy, so 
I will not repeat that information here.

Over the years AB's handling of null has evolved so you have to keep 
that in mind when reading back posts.

As a result of reading the archives and using Explorer to test 
specific cases I believe I now have a reasonable laymans 
understanding of the subject as it applies to AB.
In any case, I always triple check my projects for any exceptional 
behaviour, including null/zero effects.
As a caution I would advise you to check my results for yourself and 
be careful of null exceptions in your work.
Obviously I have not checked all possible scenarios.


For the benefit of my laybrothers and laysisters I provide the 
following definitions:

http://www.webopedia.com/TERM/N/null_character.html

A character that has all its bits set to 0. A null character, 
therefore, has a numeric value of 0, but it has a special meaning 
when interpreted as text. In some programming languages, notably C, 
a null character is used to mark the end of a character string. In 
database and spreadsheet applications, null characters are often 
used as padding and are displayed as spaces. 

http://en.wikipedia.org/wiki/Null_%28computer%29

Null has several meanings in computer programming.
In many disciplines, the concept of null allows a three-valued 
logic, with null indicating "unknown value". The SQL database query 
language uses Null in this way, as do Visual Basic 
(Termed "Nothing") and its derivatives. In this model, an expression 
that depends on the value of a Null operand will evaluate to Null 
(VB) or "unknown" (SQL).



For this discussion Null == Empty == Traders speak for no data 
==    ; (?)

Null is not a reserved variable.
Neither is it a function.
AB uses it without complaint however e.g. 

AddColumn(IIf( DayOfWeek() == 5, Null,1),"NullTest",1.5);//produces 
Null every Friday when used in explore.

Using combinations of the following code I was able to test current 
null and zero behaviour in some typical AB applications:

//allows Explorer testing of  Null behaviour

N = IIf( DayOfWeek() == 5, Null,1);
P = 1 - N ;// formula P alternative is 1 - Null
//P = N/0; // formula P alternative is Null/0
AddColumn(IsNull(N),"IsNullFri",1.5);
AddColumn(P,"IsNullMath",1.5);

//allows Explorer testing of zero behaviour

AddColumn(1/0,"Math",1.5);

My findings are as follows (use at your own risk):

Substituting the word Null for N in formula P produces Null as the 
result of all */+- combinations including o cases.

For all cases of */+- using N:

Null + 1 == Null
Null ? 1 == Null
1 ? Null == 10,000,000,000 OR (+1 E10?)
1 + Null == Null

0/Null == 0
Null/0 == -1.#INFO
Null/1 == Null
1/Null == -0.0000

1 * Null ==  Null
Null  * 1 ==  Null
0 * Null ==  0
Null  * 0 ==  0

N * N == 100,000,002,004,087,730,000
N/N == 1
N + N == -20,000,000,000
N ? N == 0

The maths test 1/0 produces the result 1.#INFO



That's all from me and it's all from him.

BrianB2  ::-)   (sunglasses on forehead)





--- In amibroker@xxxxxxxxxxxxxxx, "David Weller" <wellerdr@xxx> 
wrote:
>
> How does AmiBroker treat Null values?
> 
>  
> 
> When there is no current position then following code does not 
execute as
> the return value is a Null.  But I think it should. When there are 
open
> positions the value is greater than 0 then this piece code 
executes fine.
> 
>  
> 
>  
> 
>                  if (ibc.GetPositionInfo(Name(),"Avg. cost") <=
> LastValue(C))
> 
>  
> 
> I fixed this situation by first checking  if( ibc.GetPositionSize( 
Name() )
> == 0 )  meaning no existing positions and routing only open 
positions > than
> 0 to the above code. 
> 
>  
> 
> In Hex Null is 000 which is less than all other numbers.  Just not
> understanding the situation.  Working with the IB Interface and 
really like
> this capability.    
> 
>  
> 
> Dave
>