mt5 strategy tester ticks - page 9

 
WhooDoo22:

Hello MQL5 community,

Has anyone else encountered numbers like these when running strategies in the tester? -1.000000000006551e-005 and 1.000000000006551e-005 (yep, that's eleven zeros). It must be a specific double format type but what double format type, hmm?

Also, I'm reading MQL5 documentation like yeah, ok, ok, standard int data type has a min value of -2 147 483 648 and a max value of 2 147 483 647 then yes, of course there's the unsigned int data type with a min value of 0 and a max value of 4 294 967 295 BUT ;) there's no int data type with a min value of minus -4 294 967 295 and a max value of 0. I'd a thought there would be an int data type having these min and max values but it is what it is. The previous statement might also apply to additional data types.

Thank you

0.00001  is the same a 1 e-5  is an exponent format.  The extra digits at the end, the 6551 are equivalent to  0.00000000000000006551  and this is why we have problems comparing doubles . . .  you need to read this, and do some research if you need to,  so you understand what is going on:  Can price != price ?
Can price != price ? - MQL4 forum
  • www.mql5.com
Can price != price ? - MQL4 forum
 
RaptorUK:
0.00001  is the same a 1 e-5  is an exponent format.  The extra digits at the end, the 6551 are equivalent to  0.00000000000000006551  and this is why we have problems comparing doubles . . .  you need to read this, and do some research if you need to,  so you understand what is going on:  Can price != price ?

Simon,

Much obliged, I'm reading the thread and believe the involved mql4 thread posters' general solution for double comparison was to discover and utilize a method for rounding these doubles appropriately to return correct values. What say you to this?

Thank you

 
WhooDoo22:

Simon,

Much obliged, I'm reading the thread and believe the involved mql4 thread posters' general solution for double comparison was to discover and utilize a method for rounding these doubles appropriately to return correct values. What say you to this?

Thank you

In the context of your post above comparisons of doubles is not important,  understanding why you can't simply compare doubles is what is important.
 
RaptorUK:
In the context of your post above comparisons of doubles is not important,  understanding why you can't simply compare doubles is what is important.

Why? Because I think price values are returned in a format of four and five digits (with exceptions like USDJPY which returns price values of two and three digits). I'll try to just break it down once and for all because I don't wish to drag this on longer than needed.

USDCHF's bid price is currently 0.92909 and I believe the furthest MetaTrader5 calculates these price values is sixteen places to the right of the decimal, if this is the case then there's eleven places after the last digit nine being thrown into calculations of USDCHF's price of 0.9290900000000000. I think the reason doubles can't simply be compared is because the rest of the places to the right of a price's decimal (not the ones readable in the terminal but the ones not readable in the terminal) cause inequality problems.

Thank you

 
WhooDoo22:

Why? Because I think price values are returned in a format of four and five digits (with exceptions like USDJPY which returns price values of two and three digits). I'll try to just break it down once and for all because I don't wish to drag this on longer than needed.

USDCHF's bid price is currently 0.92909 and I believe the furthest MetaTrader5 calculates these price values is sixteen places to the right of the decimal, if this is the case then there's eleven places after the last digit of nine being thrown into calculations of USDCHF's price of 0.9290900000000000. I think the reason doubles can't simply be compared is because the rest of the places to the right of a price's decimal (not the ones readable in the terminal but the ones not readable in the terminal) cause a problem of inequality.

Thank you

The problem with double come from their binary representation. There are double that don't have an exact binary representation, so you obtain things like 1.000000000006551e-005. I don't enter here in detailed explanation, if interested you can read this for example.
Double-precision floating-point format - Wikipedia, the free encyclopedia
Double-precision floating-point format - Wikipedia, the free encyclopedia
  • en.wikipedia.org
Double-precision floating-point format is a computer number format that occupies 8 bytes (64 bits) in computer memory and represents a wide dynamic range of values by using floating point. Computers with 32-bit storage locations use two memory locations to store a 64-bit double-precision number (a single storage location can hold a...
 
WhooDoo22:

Why? 

It's all explained on the first page of the thread I gave a link to,  in essence;  a value of 1.57373  may actually be held as a double value of  1.5737300000000001  while NormalizeDouble(1.57373, 5) might produce a double value of  1.5737299999999999    both values rounded to the nearest 5th digit are equal but compared directly are not equal . . .  this is how double values are stored,  they are floating point numbers  ( look up floating point numbers,  read and understand )  and often the value held is not exactly the same as the value that you think is being held.

So your comment shows a subtraction of two doubles and you see the difference as 1.0000000000xyz  -e5  this is because this is how doubles are stored - floating point numbers.

Articles - Understanding Floating Point Number Representation - Cprogramming.com
Articles - Understanding Floating Point Number Representation - Cprogramming.com
  • www.cprogramming.com
Floating point representations vary from machine to machine, as I've implied. Fortunately one is by far the most common these days: the IEEE-754 standard. This standard is prevalent enough that it's worthwhile to look at it in depth; chances are good you'd be able to use this information on your platform (look for ieee754.h). An IEEE-754...
 
angevoyageur:
The problem with double come from their binary representation. There are double that don't have an exact binary representation, so you obtain things like 1.000000000006551e-005. I don't enter here in detailed explanation, if interested you can read this for example.

1.000000000006551e-005's sixteenth place to the right of the decimal is e-005.

Are you saying 1.000000000006551e-005 doesn't have an exact binary representation because its sixteenth place to the right of the decimal isn't an integer, its e-005?


"I don't enter here in detailed explanation,"

Why not? If you wish to write a detailed explanation then by all means, do so.


"if interested you can read this for example."

I've begun reading it.

Thank you

Double-precision floating-point format - Wikipedia, the free encyclopedia
Double-precision floating-point format - Wikipedia, the free encyclopedia
  • en.wikipedia.org
Double-precision floating-point format is a computer number format that occupies 8 bytes (64 bits) in computer memory and represents a wide dynamic range of values by using floating point. Computers with 32-bit storage locations use two memory locations to store a 64-bit double-precision number (a single storage location can hold a...
 
WhooDoo22:


"I don't enter here in detailed explanation,"

Why not? If you wish to write a detailed explanation then by all means, do so.


Do you remember a discussion we had about the basic fundamental stuff you should know if you want to be able to code properly ?  floating point numbers is one of them . . .  DYOR, there is plenty of information out there,  find it, read it,  understand it then you will be able to code a little better.
DYOR
DYOR
  • acronyms.thefreedictionary.com
What does DYOR stand for?
 
WhooDoo22:

1.000000000006551e-005's sixteenth place to the right of the decimal is e-005.

Are you saying 1.000000000006551e-005 doesn't have an exact binary representation because its sixteenth place to the right of the decimal isn't an integer, its e-005?


No. If you read my link and/or the one of RaptorUK, that would be more clear to you. If not, read again :-D

1.000000000006551e-005 is simply another notation for 0.00001000000000006551.

 
RaptorUK:

It's all explained on the first page of the thread I gave a link to,  in essence;  a value of 1.57373  may actually be held as a double value of  1.5737300000000001  while NormalizeDouble(1.57373, 5) might produce a double value of  1.5737299999999999    both values rounded to the nearest 5th digit are equal but compared directly are not equal . . .  this is how double values are stored,  they are floating point numbers  ( look up floating point numbers,  read and understand )  and often the value held is not exactly the same as the value that you think is being held.

So your comment shows a subtraction of two doubles and you see the difference as 1.0000000000xyz  -e5  this is because this is how doubles are stored - floating point numbers.

1.57373 (ignore)

1.5737300000000001

1.5737299999999999

"both values rounded to the nearest 5th digit are equal"

Both values rounded to the nearest 5th equal 1.57373.


"but compared directly are not equal"

Yes, because there's a difference.


"this is how double values are stored"

Double values such as 1.5737300000000001 are stored as 1.57373 (if normalize double is used I assume). If normalize double isn't used, the double value 1.5737300000000001 would keep this value format, correct?


"and often the value held is not exactly the same as the value that you think is being held."

My last statement responds to this statement as well.


I'll read the link you provided, thank you for it.

Thank you

Reason: