Round current price to closest(up or down) round number (00,25,50,75)

To add comments, please log in or register
emches
49
emches  

Hello,

I am trying to figure out how to get the current price (DAX/GER30 with 2 decimals i.e 12263.71) and convert it to the next closest round number up/or down that ends in 00,25,50 or 75 -> 12275.00

I am trying with:

bidAsInt = MathFloor((Bid/Point)/100);

But this only returns 12263. Scratching my head now on how to get this rounded up to -> 12275.00 or down to -> 12250.00

Any help is greatly appreciated, thank you.

emches
49
emches  

Seems I got it working with the part of the following code

   double step = 25;
   double pricerounded = DoubleToString(step * round(Bid / step),2);

source: https://www.mql5.com/en/forum/234245/page2#comment_6999138

NormalizeDouble(Bid, Digits)
NormalizeDouble(Bid, Digits)
  • 2018.04.04
  • www.mql5.com
I want to get exact BID,ASK value with normalization. But i can not able to do that following most popular way...
William Roeder
20228
William Roeder  
DoubleToString returns a string. You can't assign that to a double if you used strict. Always use strict. Fixing the warnings will save you hours of debugging.
          Program Properties (#property) - Preprocessor - Language Basics - MQL4 Reference
See
          MT4:NormalizeDouble - General - MQL5 programming forum
          How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum
emches
49
emches  
I've changed it and will keep this in mind for the future. Thanks for pointing it out.
To add comments, please log in or register