# How to convert the price difference into a whole number?

46

Hi, i'm started to coding a few months ago, now that I've managed to do my own strategy, I want to automate it. My problem is that my strategy needs to get the price between the high and low but i want that difference in whole number,

not as 0.0000300, instead of  300.

At the moment my code get the difference between prices, but i have not managed to convert it in a whole number. If someone could guide me to any solution it will be well appreciated.

Btw i have some ideas but don't how to code them:

1.- Convert the price decimals to integer, eliminating the point.

2.- Convert the price by multiplying it for a number that depends on the decimals that has the pair in wich i'm working. The problem is that I would have to check for every pair the decimal places.

Hope someone could help me, and sorry for this horrible english.

4312

MarcoyLiss:

Hi, i'm started to coding a few months ago, now that I've managed to do my own strategy, I want to automate it. My problem is that my strategy needs to get the price between the high and low but i want that difference in whole number,

not as 0.0000300, instead of  300.

At the moment my code get the difference between prices, but i have not managed to convert it in a whole number. If someone could guide me to any solution it will be well appreciated.

Btw i have some ideas but don't how to code them:

1.- Convert the price decimals to integer, eliminating the point.

2.- Convert the price by multiplying it for a number that depends on the decimals that has the pair in wich i'm working. The problem is that I would have to check for every pair the decimal places.

Hope someone could help me, and sorry for this horrible english.

Use the function or variable for the symbol's point size: https://www.mql5.com/en/docs/check/point

`( High - Low ) / _Point;`

Documentation on MQL5: Checkup / Point
• www.mql5.com
Checkup / Point - Reference on algorithmic/automated trading language for MetaTrader 5
1869

Fernando Carreiro:

Use the function or variable for the symbol's point size: https://www.mql5.com/en/docs/check/point

`int(round(( High - Low ) / _Point));`

;)

4312

nicholi shen:

;)

I purposely did not include the rounding or the typecasting and only the point conversion for a reason, as it is unclear what the OP will do with that afterwards.

For example, if he intends to use it for setting stops or opening prices for pending orders, then he would have to align it with the tick size.

That is why I did not include any extras, and only presented the answer for obtaining whole numbers as he requested.

17457

Fernando Carreiro:

I purposely did not include the rounding or the typecasting and only the point conversion for a reason, as it is unclear what the OP will do with that afterwards.

For example, if he intends to use it for setting stops or opening prices for pending orders, then he would have to align it with the tick size.

That is why I did not include any extras, and only presented the answer for obtaining whole numbers as he requested.

Perhaps from your experience, can also answer another question, such as determining(packing) in one digit the full integral characteristic of the bar(OHLC prices).

Given that there is no need to re-extract prices (unpacking), but the result is desirable to have a unique for each bar value, rounded which is not sensitive to the small differences in prices that we see in some forex brokers.

4312

Ivan Negreshniy:

Perhaps from your experience, can also answer another question, such as determining(packing) in one digit the full integral characteristic of the bar(OHLC prices).

Given that there is no need to re-extract prices (unpacking), but the result is desirable to have a unique for each bar value, rounded which is not sensitive to the small differences in prices that we see in some forex brokers.

My apologies, but I don't understand your question. What do you mean by packing into one digit?

EDIT:

Are you perhaps trying to store the prices into a packed numerical space, like storing the OHLC prices into a 64-bit long integer?

If so, then you could condense the values by using point or tick values for the "Open", "delta High", "delta Low", "delta Close" and that should fit into a 64-bit Long integer!

The Open Price could be condensed into 20-24 bits and each of the delta values taking up 13-14 bits, resulting in a packed structure that could fit into a 64-bit Long Integer.

17457

Fernando Carreiro:
My apologies, but I don't understand your question. What do you mean by packing into one digit?
One digital value that can be calculated by formulas with Open, High, Low and Close prices or on bit level using operations >> & | .
4312

Ivan Negreshniy: One digital value that can be calculated by formulas with Open, High, Low and Close prices or on bit level using operations >> & | .

Sorry, but I still don't understand what you mean. I have reedited my previous post. Can you read it again and see if that is what you want?

17457

Fernando Carreiro:

Sorry, but I still don't understand what you mean. I have reedited my previous post. Can you read it again and see if that is what you want?

Thanks for the answer I read, but unfortunately the simple summation at the double level of the actual or the bit level does not solve the above sensitivity problem.
4312

Ivan Negreshniy: Thanks for the answer I read, but unfortunately the simple summation at the double level of the actual or the bit level does not solve the above sensitivity problem.

Sorry, but you seem to be using Google translate and all it is doing is creating complete confusion. I can't understand anything you are trying to communicate!

Moderator
8151

if High-Low = 0.0000300, he doesn't want a double 0.0000300 but he wants integer 300.