CompareDoubles()

 
What does CompareDoubles() do and when would one use it? Where is the documentaion for this function?
 

Well, im sure you can google it and get some answers..

But you have unusual question about where would you use it? Most people ask the other way around..


From what I understand, CompareDoubles() compares two double values and returns bool true or false. But im just beginner so..

 
Look at your terminal directory \experts\libraries, you will see stdlib.mq4. This is a library for some things such as CompareDoubles(), ErrorDiscription() etc. You can use it in your program if you include this library into your code.
 
Roger wrote >>
Look at your terminal directory \experts\libraries, you will see stdlib.mq4. This is a library for some things such as CompareDoubles(), ErrorDiscription() etc. You can use it in your program if you include this library into your code.

That is where I found out there was a CompareDoubles() function. But what does it do? it is a bool. When does it return true? When both values are the same? I am currently using NormalizeDouble before comparing two doubles. Would it be more effective to use CompareDoubles?

 
If you use NormalizeDouble before comparing, you don't need this function.
 

yes.

bool CompareDoubles(double number1,double number2)
{
if(NormalizeDouble(number1-number2,8)==0) return(true);
else return(false);
}

 
USForexGuy wrote >>
What does CompareDoubles() do and when would one use it? Where is the documentaion for this function?

Using functions like CompareDouble is good habit. It is easy to incorrectly compare values in the code if they are double type. Is 1.00000000001=0.99999999999?

This function will tell you easily if two doubles are equal within 8 digits (true) or not (false).

If you do that without normalization result is unpredictible.

 
USForexGuy:

That is where I found out there was a CompareDoubles() function. But what does it do? it is a bool. When does it return true? When both values are the same? I am currently using NormalizeDouble before comparing two doubles. Would it be more effective to use CompareDoubles?

bool CompareDoubles(double number1,double number2)
  {
   if(NormalizeDouble(number1-number2,8)==0) return(true);
   else return(false);
  }


CB

 
cloudbreaker wrote >>

CB

Thanks for the responses!

Reason: