How to convert the price difference into a whole number?

To add comments, please log in or register
MarcoyLiss
46
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.


Fernando Carreiro
4312
Fernando Carreiro  
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
Documentation on MQL5: Checkup / Point
  • www.mql5.com
Checkup / Point - Reference on algorithmic/automated trading language for MetaTrader 5
nicholi shen
1869
nicholi shen  
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));

;)

Fernando Carreiro
4312
Fernando Carreiro  
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.

Ivan Negreshniy
17457
Ivan Negreshniy  
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.

Fernando Carreiro
4312
Fernando Carreiro  
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.

Ivan Negreshniy
17457
Ivan Negreshniy  
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 >> & | .
Fernando Carreiro
4312
Fernando Carreiro  
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?

Ivan Negreshniy
17457
Ivan Negreshniy  
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.
Fernando Carreiro
4312
Fernando Carreiro  
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!

Marco vd Heijden
Moderator
8151
Marco vd Heijden  

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

To add comments, please log in or register