IsNull versus "== Null"

Is there any different between IsNull() versus == Null ? It seems that "== Null" does not work in the IF statement.

// Search for missing data in a particular date
// Must set range to "1 recent bar(s)"


//Date_time = DateTime();
//Date_num = DateNum();
//Filter = 1;

if (StrRight(Name(),2) == "_D") Filter = 0; // Skip ticker symbol with "_D"
else {
/* The following code works but need loop.
	for (i=BarCount - 1; i >=0; i--) {
		//if (1210203 == Date_num[i] ) {
		if (_DT("2021-02-03") == Date_time[i] ) {
			Filter = 0;
		} else {
			//if (1210203 > Date_num[i]) {
			if (_DT("2021-02-03") > Date_time[i] ) {
	if (IsNull(Lookup(BarIndex(),_DT("2021-02-03"),0))) Filter = 1;
	//if (Lookup(BarIndex(),_DT("2021-02-03"),0) == Null) Filter = 1; // This does not work. Why ?
	else Filter = 0;

AddTextColumn (Name(),"Ticker");

IsNull() should always be used, '== Null' should never be used.

Null is Empty, it's not a Value. AmiBroker looks for IsNull() as part of its inner workings.

This has already been covered, see valuewhen-and-null-values.

I would presume that the Null is for assignment only i.e. "= Null;" It would be good to flag an error(== Null) just like comparing a string and a number.

Null has special semantics. Null means "having no value at all" or "we don't know what the value is". A typical example is that we don't know what is the value of N-day moving average before we actually got N-days worth of data. You can't compare to something that does not have any value. Any operation involving Null produces a Null.

Thanks. It took me quite a while to figure out logical comparison against Null does not work in ALF. I was misled by C, Javascript and VBA into thinking that it should work in AFL. Now that I am aware of this, it's OK. I am just mindful of new users.

They work, but you need to understand the meaning. What you are doing is asking whenever

<one value that you know nothing about> is equal <to other value that you know nothing about>

Null represents the STATE "I don't know the value".

The correct result of such comparison is: I have no idea, and it means precisely NULL.

In C/C++ there is no such thing as "true" Null. Null in C/C++ is merely a #define NULL 0
It is just zero. It does not have any special semantics.

Comparing to Null is not an error. The same way as it is not an error to add, subtract, multilpy or do whatever else with Null. The result of all these operations is UNKNOWN i.e Null (because you don't know the value of one of operands)


Thank you for taking time to explain.

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