How to calculate number of pips

 

Hi,

I have been struggling hard to figure out for any given symbol, how to find out the number of pips between two prices. Remember some broker give 5 decimals points instead of 4 ( example EURUSD ). I saw all sort of complications when indexes, commodities and other exotic currencies come in picture.

If anyone knows about it, let me know.

thanks,

Kya

 
kyahain:

Hi,

I have been struggling hard to figure out for any given symbol, how to find out the number of pips between two prices. Remember some broker give 5 decimals points instead of 4 ( example EURUSD ). I saw all sort of complications when indexes, commodities and other exotic currencies come in picture.

If anyone knows about it, let me know.

thanks,

Kya


//++++ 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)
   if (Digits % 2 == 1)  // DE30=1/JPY=3/EURUSD=5 forum.mql4.com/43064#515262
     {pips2dbl = Point*10; pips2points = 10;   Digits.pips = 1;}
     else {pips2dbl = Point;    pips2points =  1;   Digits.pips = 0;}
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl  

two prices same symbol then ( price1- price2 )/ pipvalue ( pipvalue = pips2dbl if you have use the code above WHRoeder is often given here )

 

kyahain:

I saw all sort of complications when indexes, commodities and other exotic currencies come in picture.

I tried to find a way by this mathematical formula, but it is in trouble with prices beginning with 4xxx or 5xxx. What is your opinion about this attempt? Any improvement?
   double pipDigits = -MathFloor(MathLog(Close[0]) / MathLog(10.0) - MathLog(5000.0) / MathLog(10.0));
   double pointDigits = MarketInfo(Symbol(), MODE_DIGITS);
   double pips2points = MathPow(10.0, pointDigits - pipDigits);
   double pips2dbl = pips2points * Point;
   Print(pips2points);
   Print(pips2dbl);
 
Use this and you would have found Fixing decimals to 5 digits in outputds - MQL4 forum Posted yesterday!
Reason: