35

Sometimes the function OrderOpenPrice return number with more digits than it should be and that's make problem because when i use that number inside of if statement like "Ask==OrderOpenPrice+50*pips" it doesn't make true the condition to execute the code at the brackets of if statement.I try the fuction "NormalizeDouble" but the problem remain .

Below is the code to see the price that open the position (OrderOpenPrice) and x is variable to see that price after using the NormalizeDouble with 1 digit.

``` if (OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber)
{
double x = NormalizeDouble(OrderOpenPrice(),1);
Comment(OrderOpenPrice()+"   "+x);

}

}```

Sometimes the results of the Comment function are like :  85.31100000000001      85.3

Sometimes are                                                           :  86.59                           86.59999999999999

I attached photos for these examples

it's like sometimes the fuction OrderOpenPrice doesn't work and sometimes the NormalizeDouble doesn't work.

it doesn't make any sense.

Thanks !

16096

dionikolo:

Sometimes the function OrderOpenPrice return number with more digits than it should be and that's make problem because when i use that number inside of if statement like

I attached photos for these examples

I try the fuction "NormalizeDouble"

1. No it does not, Floating point has infinite number of digits. It's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.) Double-precision floating-point format - Wikipedia, the free encyclopedia
2. You can't compare doubles for equality and price could easily move from below to above and never be equal.  The == operand. - MQL4 forum
3. Don't attach a image, insert the image
4. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
19297
Vasyl Nosal
DoubleToString()
35

WHRoeder:
1. No it does not, Floating point has infinite number of digits. It's your not understanding floating point and that some numbers can't be represented exactly. (like 1/10.) Double-precision floating-point format - Wikipedia, the free encyclopedia
2. You can't compare doubles for equality and price could easily move from below to above and never be equal.  The == operand. - MQL4 forum
3. Don't attach a image, insert the image
4. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
Ok..Thank you WHRoeder! Just to know all that need to work my code right is to change all these "if statements" Ask==OrderOpenPrice+something  with Ask>=OrderOpenPrice+something or Ask<=OrderOpenPrice+something  because of the choppy price and the Floating point (Correct me if i am wrong,  i am not a pro Programmer). This forum is perfect for newbie like me! I appreciate all that Information ! Thanks again !
16096