Download MetaTrader 5
To add comments, please log in or register
Traders have already contributed more than 300 articles. Write your own one!
neverman
89
neverman 2014.08.14 18:16 

Hello guys,


I have a demo in FXPro and got situation there. I want to receive a quote with 5 digits. Normally this code should work:

Print(NormalizeDouble(iClose("GBPUSD",1,1),Digits));

the result was 1.6879

I decided to check

Print(MarketInfo("GBPUSD",MODE_DIGITS));

The result was 5

Finally I decided to try this code:

Print(DoubleToStr(_bid, Digits));

the result was 1.68795


Please solve this riddle and tell me how to work with 5 digits double variable ?!

Keith Watford
Moderator
9597
Keith Watford 2014.08.14 21:00  
neverman:

Hello guys,


Print(NormalizeDouble(iClose("GBPUSD",1,1),Digits));

the result was 1.6879

That is because the result was 1.68790

The Print will ignore zeroes at the end

If it had been 1.68000

It would have printed as

1.68 

whroeder1
14457
whroeder1 2014.08.15 00:48  
neverman:  Print(NormalizeDouble(iClose("GBPUSD",1,1),Digits));
  1. Don't use NormalizeDouble EVER
  2. string   PriceToStr(double p){   return( DoubleToStr(p, Digits) );            }

neverman
89
neverman 2014.08.15 06:20  

I think i get the same result with

DoubleToStr(_bid, Digits)

... but its not my goal to show it (I don't need 5 digit string variable, I need 5 digit double variable. I want to make math with it. I tried with the current way, the math works with 4 digits ONLY !


The problem is that I want to make arithmetic operations with double which results must have 5 digits.

So the question is up yet, how to assign the full 5 digit price to a variable and to have the ability to make math operations with it?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.08.15 06:49  

Actually what you want to achieve is very simple. You are just thinking it way too hard but it is actually just plain simple.


You either need to do some more homework because it is just logic. Nothing fancy.


OR


https://www.mql5.com/en/job

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.08.15 08:04  
neverman:

I think i get the same result with

DoubleToStr(_bid, Digits)

... but its not my goal to show it (I don't need 5 digit string variable, I need 5 digit double variable. I want to make math with it. I tried with the current way, the math works with 4 digits ONLY !


The problem is that I want to make arithmetic operations with double which results must have 5 digits.

So the question is up yet, how to assign the full 5 digit price to a variable and to have the ability to make math operations with it?

If your broker is a 5 Digit Broker then you have 5 digit prices (for most symbols) . . . yes,  it is that simple.  If you want the result of mathematics to have a max of 5 digits then you can simply round the values to 5 digits, add 0.5 X 10-5 then multiply by 105 then take the integer value using MathFloor() then divide by 105

neverman
89
neverman 2014.08.15 09:10  

It a little insane ... but let ask again.

It is 5 Digit Broker as shown above.


On the graph the price is Bid 1.68155 Ask 1.68174.

The double variable for Bid is 1.6815 Ask  1.6817

String variable for Ask is 1.68155 Ask 1.68174

When I decide a little math with double variables, Ask - Bid = 0.0001


As I know double variable allow 16 digits after the point, but shows only 4 digits.  You want to tell me that this is not MQL4 bug and I have to write 10 rows code just to work normally with double variables?

Alain Verleyen
Moderator
30635
Alain Verleyen 2014.08.15 09:17  
neverman:

It a little insane ... but let ask again.

It is 5 Digit Broker as shown above.


On the graph the price is Bid 1.68155 Ask 1.68174.

The double variable for Bid is 1.6815 Ask  1.6817

String variable for Ask is 1.68155 Ask 1.68174

When I decide a little math with double variables, Ask - Bid = 0.0001


As I know double variable allow 16 digits after the point, but shows only 4 digits.  You want to tell me that this is not MQL4 bug and I have to write 10 rows code just to work normally with double variables?

Which build are you using ? Which broker/Server. Show the relevant code to reproduce your issue and the output from Experts tab.
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.08.15 09:27  
neverman:

It a little insane ... but let ask again.

It is 5 Digit Broker as shown above.


On the graph the price is Bid 1.68155 Ask 1.68174.

The double variable for Bid is 1.6815 Ask  1.6817

How do you know this ?  where are you "seeing" it ?  I suspect it is just how you are showing that value so you can see it that is the problem . . .  in the old mql4 Print() and Comment() defaulted to just showing 4 digits for numeric values,  even though there were many more digits . . .  in mql4.5  it seems that Print() & Comment()  now shows 5 digits by default,  so where are you seeing 4 digits ?

 

neverman:


As I know double variable allow 16 digits after the point, but shows only 4 digits.  You want to tell me that this is not MQL4 bug and I have to write 10 rows code just to work normally with double variables?

It's not a mql4 bug . . .

 

Floating point variables can have many more digits than 16,  not many float values can be exactly represented due to the way they are stored in memory . . .  take a look here:  IEEE 754   and here:  http://en.wikipedia.org/wiki/Quadruple-precision_floating-point_format

Keith Watford
Moderator
9597
Keith Watford 2014.08.15 09:38  

Ï put this in a script and ran it on FXPro demo account

  Print(NormalizeDouble(iClose("GBPUSD",0,0),Digits));
  double bidprice=Bid;
  double askprice=Ask;
  Print("Bid is ",bidprice,".  Ask is ",askprice);

 result

2014.08.15 16:35:14.546 a GBPUSD,H1: 1.66914

2014.08.15 16:35:14.546 a GBPUSD,H1: Bid is 1.66914.  Ask is 1.66939

 

 All print with 5 digits

I think that you are doing something in your code to change the value 

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.08.15 11:23  
Yeah. The code must have been written specifically for 4 digits or simple rookie logic mistake.
/ /12
To add comments, please log in or register