how can you calculate the difference in ticks between 2 prices

 
Hi,
in MQL5, how can you calculate the difference in ticks between 2 prices?


Both for crosses of 5 and 3 decimals.


For example:

1,17028 -> 1,17046
84,040 -> 84,067


Thank you

 

Question makes no sense. A tick is a change in price not a unit of measure. What is the difference "in ticks" between 10 am and 12 pm? Meaningless. Is is 2 hours, 120 minutes, or 7200 seconds, etc.

If you meant "tick size", now you have a unit of measure. (P1-P2)/TS.

 
JLLMNCHR:
Hi,
in MQL5, how can you calculate the difference in ticks between 2 prices?


Both for crosses of 5 and 3 decimals.


For example:

1,17028 -> 1,17046
84,040 -> 84,067


Thank you

Do you pips or points, perhaps?  You can multiply the change in price by 10^(int)MarketInfo(Symbol(), MODE_DIGITS), that will give you the number of points that the price has moved.  Divide that by 10, you have number of pips the price has moved.  Not sure if the syntax is the exact same in MQL5, but hopefully my answer has pointed you in the right direction.

Edit, so for MQL4 you want 

int points_moved = price_difference*pow(10,(int)MarketInfo(Symbol(),MODE_DIGITS));

And for MQL5 you want

int point_moved = price_difference*pow(10,SymbolInfoInteger(Symbol(),SYMBOL_DIGITS));

That is of course if you meant points, and not ticks.

 
pow(10,(int)MarketInfo(Symbol(),MODE_DIGITS))
pow(10,SymbolInfoInteger(Symbol(),SYMBOL_DIGITS)

s a m e  a s

1 / _Point
 

I want to find a "standarized" way to meassure changes in price, equivalent for 5 and 3 decimals Forex symbols.

Somewhere in the forum I have read that a pip is defined as 0.00010 (or for JPY 0.010)


With that in mind:

---(A)---

1,17028 -> 1,17046


1,17046 - 1,17028 = 0,00018;

1 pip = 0,00010
x pip = 0,00018

x = 0,00018 / 0,00010 = 1,8

------------------------------ 

---(B)---

84,040 -> 84,067


84,067 - 84,040 = 0,027;

1 pip = 0,010
x pip = 0,027

x = 0,027 / 0,010 = 2,7

 
JLLMNCHR:I have read that a pip is defined as 0.00010 (or for JPY 0.010)
Using Points means code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
          How to manage JPY pairs with parameters? - MQL4 and MetaTrader 4 - MQL4 programming forum
          Slippage defined in index points - Currency Pairs - Expert Advisors and Automated Trading - MQL5 programming forum
 
whroeder1:

Haha!  So it is!  There's an easy way and a hard way for everything :P

Reason: