Control decimal places.....reg...

 
How to truncate extra decimal places in mql5. NormalizeDouble not working properly....Any one can help me in this?  Thanks in advance.
 
RDBS:
How to truncate extra decimal places in mql5. NormalizeDouble not working properly....Any one can help me in this?  Thanks in advance.

Please be more specific about your issue.

I can only guess that you may mean when printing of placing text in a label.

In such cases use DoubleToString().

 
You used NormalizeDouble, It's use is usually wrong, as it is in your case.
  1. Floating point has infinite number of decimals, 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

    See also The == operand. - MQL4 programming forum

  2. Print out your values to the precision you want with DoubleToString - Conversion Functions - MQL4 Reference.

  3. SL/TP (stops) need to be normalized to tick size (not Point) — code fails on metals. (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 programming forum

  4. Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 programming forum

  5. Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.

  6. MathRound() and NormalizeDouble() are rounding in a different way. Make it explicit.
              MT4:NormalizeDouble - MQL5 programming forum
              How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum

  7. Prices you get from the terminal are already normalized.
 
Keith Watford:

Please be more specific about your issue.

I can only guess that you may mean when printing of placing text in a label.

In such cases use DoubleToString().

Hello Mr.Keith ,

Thanks for your kind reply. I have given the codes which I tried. Please help me in this if possible to you.

Thanks and regards.

RDBS.


void OnTick()          

  {      
  
     MqlTick curtick;
//---
   if(SymbolInfoTick(Symbol(),curtick))
     {
      Print(curtick.time,": Bid = ",curtick.bid,
            " Ask = ",curtick.ask);
     }
   else Print("SymbolInfoTick() failed, error = ",GetLastError());
// THE  ABOVE CODE WORKS WELL AND GIVES THE BID/ASK  DETAILS FOR EUR/USD IN 5 DIGITS. 

// BUT THE FOLLOWING CODE GIVES 0.0  INSTEAD OF  CORRECT ANSWER......

   double dif = NormalizeDouble(curtick.ask,5)-NormalizeDouble(curtick.bid,5);
   Print("dif",dif);

 }


 
RDBS:

Hello Mr.Keith ,

Thanks for your kind reply. I have given the codes which I tried. Please help me in this if possible to you.

Thanks and regards.

RDBS.


Use the code button (Alt + S) when pasting code.

I have edited your post this time.

Your original question was

RDBS:
How to truncate extra decimal places in mql5. NormalizeDouble not working properly....Any one can help me in this?  Thanks in advance.

and I answered

Keith Watford:

Please be more specific about your issue.

I can only guess that you may mean when printing of placing text in a label.

In such cases use DoubleToString().

Now you come back with code that you say is printing 0.0 and not the correct answer.

Maybe it is the correct answer because the spread is zero.

You are still not using DoubleToString().

Documentation on MQL5: Conversion Functions / DoubleToString
Documentation on MQL5: Conversion Functions / DoubleToString
  • www.mql5.com
value is in the range between 0 and 16, a string presentation of a number with the specified number of digits after the point will be obtained. If the value is in the range between -1 and -16, a string representation of...
 
Keith Watford:

Use the code button (Alt + S) when pasting code.

I have edited your post this time.

Your original question was

and I answered

Now you come back with code that you say is printing 0.0 and not the correct answer.

Maybe it is the correct answer because the spread is zero.

You are still not using DoubleToString().

Thanks a lot Mr.Keith. <Deleted by moderator - Do not ask the same questions in this thread that you have opened a topic about>

Many regards.