| / | Forum |
|
naz
2008.02.12 01:15
Hello,
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 |
|
Review of Participants by Yuriy Zaytsev (YuraZ) I am not surprised by the profit of the top ten. |
|
phy
2008.02.12 01:58
"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 Use function from Stdlib.mq4 //+------------------------------------------------------------------+ //| right comparison of 2 doubles | //+------------------------------------------------------------------+ bool CompareDoubles(double number1,double number2) { if(NormalizeDouble(number1-number2,8)==0) return(true); else return(false); } |
|
naz
2008.02.12 02:36
phy wrote:
Thanks Phy. I will give it try."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 Use function from Stdlib.mq4 //+------------------------------------------------------------------+ //| right comparison of 2 doubles | //+------------------------------------------------------------------+ bool CompareDoubles(double number1,double number2) { if(NormalizeDouble(number1-number2,8)==0) return(true); else return(false); } |