Newbie if statement qestion
"Can someone tell me why the following statement does not work?"
Because they are not equal despite your protestations.
Comparing equality of doubles is a known problem because of the way doubles are represented in binary.
When you get stuck, you can change to something like:
if(MathAbs(Bid - SellOpenPrice) < .00001)
Or...
Rosh 2007.05.16 12:13
//+------------------------------------------------------------------+ //| right comparison of 2 doubles | //+------------------------------------------------------------------+ bool CompareDoubles(double number1,double number2) { if(NormalizeDouble(number1-number2,8)==0) return(true); else return(false); }
"Can someone tell me why the following statement does not work?"
Because they are not equal despite your protestations.
Comparing equality of doubles is a known problem because of the way doubles are represented in binary.
When you get stuck, you can change to something like:
if(MathAbs(Bid - SellOpenPrice) < .00001)
Or...
Rosh 2007.05.16 12:13
//+------------------------------------------------------------------+ //| right comparison of 2 doubles | //+------------------------------------------------------------------+ bool CompareDoubles(double number1,double number2) { if(NormalizeDouble(number1-number2,8)==0) return(true); else return(false); }
Can someone tell me why the following statement does not work?
if(Bid == SellOpenPrice)
For some reason it returns false most of the time when it is true.
Thank you in advance