problems with mod function

 

Hi,

I want to find the next big number to the Open of a bar. Big numbers are defined as prices that end on x.xx250 or x.xx500 or x.xx750 or x.xx000 if we look at EURUSD for instance. I thought this could be done using the MathMod() function. When I tried this I found out by printing the function returns 0.0025 at the big numbers (which is pretty strange I thought it should be 0??). Now I tried to print just YES when the mod gives 0.0025 but this doens't work. Can anyone help please?

double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
 for(i=0;i<25;i++)
        {
           
            mod=MathMod(Open[0]-i*MyPoint,25*MyPoint);
            Alert(Open[0]-i*MyPoint," ",mod);
            if(mod==0.0025) 
            {
               Alert("YES");
               price=Open[0]-i*MyPoint;
               break;
            }
        }
 
mod will never = 0.0025 . . . unless you have a double precision issue with your (25*MyPoint) such that it is != 0.0025
 
mod=MathMod(Open[0]-i*MyPoint,25*MyPoint);

A price - 1 * pip is something like 1.23456.

25 * pip is 0.0025

The modulo(1.23456, 0.0025) is 0.00206 (1.23456 - 0.00206 = 1.2325 the next lower big)

modulo(x,m) will never be equal to m.

In addition doubles rarely compare equal.

try:

//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
     if (Digits % 2 == 1){  // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
:
double  pips2Big    = 25*pips2dbl,
        pPrice      = Open[0];                      // 1.23456
int     pipsBig     = pPrice / pips2Big;            // 493.824 -> 493
double  pBigBelow   = (pPipsBig      * pips2Big,    // 493 * 0.0025=1.2325
        pBigAbove   = (pPipsBig + 1) * pips2Big;    // 494 * 0.0025=1.2350

MyPoint is insufficient, as you must adjust Slippage.

Reason: