Problem with OrderOpenPrice and NormalizeDouble functions. Please help!

 
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.

So guys if you have any idea please help me!

 

Thanks !  

 
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

"Ask==OrderOpenPrice+50*pips" it doesn't make

 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
 
DoubleToString()
 
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 !  
 
dionikolo Ask>=OrderOpenPrice+something

Understand the links in The == operand. - MQL4 forum Ask >= OOP+n could be true because of round off at Ask >= OOP+n - 0.000005 and could be false at Ask >= OOP+n + 0.000005.

If the equality is important use (must be true at Ask == OOP+n) Use "definitely >=": Ask - (OOP+n) > -_Point/2. // Note the minus

If the equality is important use (must be false at Ask == OOP+n) Use "definitely >" Ask - (OOP+n) > _Point/2.

If the equality is not important (false when equal or true when not) just use Ask > OOP+n

 
William Roeder:
  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

whn i take a buy trade..the order opens above the ask price everytime..bt whn it comes to sell the order opens perfectlt at the marketprice..wht need to be corrected with ordersend function..can someone help  me plz..

 
[Deleted]:
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.

 

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.

So guys if you have any idea please help me!

 

Thanks !  

@tasaoirse sf
if(OrderSelect(OrdersTotal()-1, SELECT_BY_POS, MODE_TRADES))
     {
      if(OrderType() == OP_SELL && OrderMagicNumber()==MagicNumber)
        {
         double x = NormalizeDouble(OrderOpenPrice(),Digits);
         Comment(StringFormat(string(OrderOpenPrice()),Digits)+"   "+StringFormat(string(x),Digits));

        }

     }
   
  }