Problem with EMPTY_VALUE

 

Hello, I have a problem with EMPTY_VALUE constant. I have created an indicator which assigns a value to an element in a buffer or it assigns an EMPPTY_VALUE, but when I check the value in expert advisor its value is 2147483647.0000.

So in the "if" statement if(value == EMPTY_VALUE) resolves to false when it should be true. How can I fix the problem?

Thanks in advance.

 
mkheidzedavid:

Hello, I have a problem with EMPTY_VALUE constant. I have created an indicator which assigns a value to an element in a buffer or it assigns an EMPPTY_VALUE, but when I check the value in expert advisor its value is 2147483647.0000.

So in the "if" statement if(value == EMPTY_VALUE) resolves to false when it should be true. How can I fix the problem?

Comparing double values can often show that value != value read this thread: Can price != price ?
 
Thanks, I read the threads and I found useful answers on comparing doubles. But unfortunately I still don't have answer why EMPTY_VALUE gets the value of maximum 32bit integer which is 2147483647. So I can compare doubles with A - B > 0 rather than A > B (or NormalizeDoubles) but the problem I have is that the value is enormously high which makes no sense to compare.
 
mkheidzedavid:
Thanks, I read the threads and I found useful answers on comparing doubles. But unfortunately I still don't have answer why EMPTY_VALUE gets the value of maximum 32bit integer which is 2147483647. So I can compare doubles with A - B > 0 rather than A > B (or NormalizeDoubles) but the problem I have is that the value is enormously high which makes no sense to compare.
What do you expect EMPTY_VALUE to be ? it is meant to be 0x7FFFFFFF or 2147483647 so it is correct.
 
Thanks I got the answer. So what can I use instead of EMPTY_VALUE in indicator? If I use -1 it draws unclear lines, I want it to have a value of null or something like that in order to draw a clear line.
 
mkheidzedavid:
Thanks I got the answer. So what can I use instead of EMPTY_VALUE in indicator? If I use -1 it draws unclear lines, I want it to have a value of null or something like that in order to draw a clear line.
Use EMPTY_VALUE . . . for your if statement check if value > EMPTY_VALUE - Point if it returns true your value is EMPTY_VALUE
 
Thanks, and one last question, could you briefly explain why if(value > EMPTY_VALUE - Point) returns true if value is indeed EMPTY_VALUE?
 
mkheidzedavid:
Thanks, and one last question, could you briefly explain why if(value > EMPTY_VALUE - Point) returns true if value is indeed EMPTY_VALUE?

I thought I already did . . . didn't I ?

RaptorUK:
Comparing double values can often show that value != value read this thread: Can price != price ?

Please click on the link and read the thread . . .
 
Ok thanks, I read one but I think I missed something. Ill go through again.
 
mkheidzedavid: Thanks, I read the threads and I found useful answers on comparing doubles. But unfortunately I still don't have answer why EMPTY_VALUE gets the value of maximum 32bit integer which is 2147483647. So I can compare doubles with A - B > 0 rather than A > B (or NormalizeDoubles) but ...

Not very well. A - B > 0 and A > B and NormalizeDoubles(A-B) > 0 are all identical. The == operand. - MQL4 forum

mkheidzedavid: So in the "if" statement if(value == EMPTY_VALUE) resolves to false when it should be true.
double value=iCustom(); if (value == EMPTY_VALUE) should work fine since a double has ~16 decimal digits of precision AND EMPTY_VALUE is an integer. When you say it doesn't I don't believe you. Print the values and show the log
double value = iCustom(...);
Print("if( " +value +" == " +EMPTY_VALUE +" ) -> " + (value == EMPTY_VALUE)");
 

double slope_up = iCustom(Symb, MajorPeriod, "Slope__Line", SlopePeriod, SlopeMethod, SlopePrice, 0, 0);
double slope_dn = iCustom(Symb, MajorPeriod, "Slope_Line", SlopePeriod, SlopeMethod, SlopePrice, 1, 0);

if(slope_up != EMPTY_VALUE && slope_dn == EMPTY_VALUE)
{

//do something here...

}

I actually return the value with Comment("slope_up: " + slope_up + " slope_dn" + slope_dn) and the value of slope_up is 1.3860 (which is calculated correctly) and slope_dn = 2147483647 and the if scope is skipped because slope_dn is not considered equal to EMPTY_VALUE.