Rounding to non-standard numbers in MQL4

thread: Rounding to non-standard numbers in MQL4

  1. #1
    Junior Member Celay_bokany's Avatar
    29

    Rounding to non-standard numbers in MQL4

    When trading CFD's which potentially have a minimum increment/tick dimensions of 0.25 in the case of the SP500, I need to discover a method of rounding some like a moving average or ATR into the closest of the tiniest increment.

    NormalizeDouble(78.2123,0.25) will trune the 0.25 into the closest number in this case 0 then round to 78

    as will:

    MathRound(78.2123)

    anybody have some ideas?

    cheers

    M

  2. #2
    You can also try
    Inserted Code double a=78.1251; double ticksize=0.25; a=NormalizeDouble(MathRound(a/ticksize)*ticksize,2); Print(a= DoubleToStr(a,2));

  3. #3
    Junior Member Celay_bokany's Avatar
    29
    wow, thanks guys, very much appreciated!
    I'll try them in the morning
    M

  4. #4
    Inserted Code double d = 78.2123; double ticksize = 0.25; Id = (int)(d / ticksize ticksize) * ticksize; NormalizeDouble(d, 2); Print(d);

  •