What is going on here?

 

I am printing the following statement:

Print(Order_Symbol, ",", Order_Quantity, ",",(OrderType() == 1),",", (Order_Quantity == 0));

It returns (symbol, 0, 1, 0)

How can Order_Quantity = 0 and Order_Quantity != 0 in the same statement? Order_Quantity is declared as a double variable.

 
fxtraydor:

I am printing the following statement:

Print(Order_Symbol, ",", Order_Quantity, ",",(OrderType() == 1),",", (Order_Quantity == 0));

It returns (symbol, 0, 1, 0)

How can Order_Quantity = 0 and Order_Quantity != 0 in the same statement? Order_Quantity is declared as a double variable.

I have a possible answer to your question . . . . . try this:

Print(Order_Symbol, ",", Order_Quantity, ",",(OrderType() == 1),",", (NormalizeDouble(Order_Quantity, Digits) == 0));

Print will do this . . . "Data of double type are printed with 4 decimal digits after point." so if your variable Order_Quantity is 0.00000001 it is != 0 but will print as 0 . . . you need to be careful comparing double values, precision issues can catch you out, they have caught me out in the past and I learned a good lesson.

 

RaptorUK is exactly right with the exception on a 5 digit broker if quantity was 0.0000x, quantity will print as 0 but normalize(digits)==0 will still print 0.

  1. See Working with Doubles in MQL4 - MQL4 Articles
  2. It is never ever necessary to use normalize.
        double  minLot  = MarketInfo(Symbol(), MODE_MINLOT);
        if (Order_Quantity < minLot){ // Effectually zero
    

 
This helps thank you. I cant for the life of me figure out where the precision issues are being introduced, but lopping off some decimal places is taking care of it.
Reason: