Problem with EMPTY_VALUE

 
Hi,

i have a little problem with the EMPTY_VALUE about this code.

//Function
bool my_function( int value1=EMPTY_VALUE)
{
        Print("EMPTY_VALUE is:"+EMPTY_VALUE);
        if(value1!=EMPTY_VALUE){ Print("ok ->"+value1); }
        return true;
}

//Call the function
my_function(   EMPTY_VALUE);



The result is
EMPTY_VALUE is:1.7976931348623157e+308
ok->-2147483648

Why it is so, normaly i thought the "ok" part is unreachable, because value1 has EMPTY_Value, but the both values are different - im a little bit confused!?
 
ReLor2:
Hi,

i have a little problem with the EMPTY_VALUE about this code.

The result is
EMPTY_VALUE is:1.7976931348623157e+308
ok->-2147483648

Why it is so, normaly i thought the "ok" part is unreachable, because value1 has EMPTY_Value, but the both values are different - im a little bit confused!?

Works correctly for me (MT4)

void OnStart()
  {
   my_function(EMPTY_VALUE);
  }

//Function
bool my_function(int value1=EMPTY_VALUE)
{
        Print("EMPTY_VALUE is:"+EMPTY_VALUE);
        if(value1!=EMPTY_VALUE){ Print("ok ->"+value1); }
        return true;
}
 
ReLor2: i have a little problem with the EMPTY_VALUE about this code.

For MQL5:

The constant EMPTY_VALUE is for use with the double data-type. It should not be use for integer data-types.

EMPTY_VALUE

Empty value in an indicator buffer

DBL_MAX

DBL_MAX

Maximal value, which can be represented by double type

1.7976931348623158e+308


 
Vladislav Boyko #: Works correctly for me (MT4)

For MQL4:

The constant EMPTY_VALUE is different in MQL4 than it is in MQL5 and its value is for integer but can also be used with double.

EMPTY_VALUE

Empty value in an indicator buffer. Default custom indicator empty value

2147483647 (0x7FFFFFFF

 
Thank you, so i use MQL5.

I change the EMPTY_VALUE to NULL, but now i have the problem that i also dont get the wanted result.

//Function
bool my_function( double value1=NULL)
{
        Print("NULL is:"+NULL);
        if(value1!=NULL){ Print("ok ->"+value1); }
        return true;
}

//Call the function
my_function(   0);
Now i want to use NULL for a kind of "nothing", i will pass in one case "nothing" so i will use "null", sometime i pass zero "0" now my if statement failed and dont print the "ok -> " part.

Did i have to check the difference between NULL and zero / 0 in another way?
 
ReLor2 #: Thank you, so i use MQL5. I change the EMPTY_VALUE to NULL, but now i have the problem that i also dont get the wanted result. Now i want to use NULL for a kind of "nothing", i will pass in one case "nothing" so i will use "null", sometime i pass zero "0" now my if statement failed and dont print the "ok -> " part. Did i have to check the difference between NULL and zero / 0 in another way?

Doubles are rarely equal.

// Function for double
   bool my_function_double( double value1 = EMPTY_VALUE ) {
      Print( "Empty value: ", EMPTY_VALUE );
      if( value1 < EMPTY_VALUE )
         Print( "ok -> ", value1 );
      return true;
   };

// Call the function for double 
   my_function_double( EMPTY_VALUE );
Reason: