Errors, bugs, questions - page 2939

 
x572intraday:
All prices are displayed to five decimal places, and one for some reason in the same list takes it this way: Why? Is it an error or my output should be edited to a uniform look? Well, let's say, I'll comb it with PrintFormat or fprint, but in principle it is not incorrect representation of the number?

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

Nikolai Semko, 2020.01.05 21:41

I always have this question.
Constantly all talk about the IEEE standard 754, but people often, when they go to Wikipedia - whether because of the complexity, or because of laziness leave without understanding the meaning of the standard.

I will spend a little time to try to explain this standard as briefly as possible and in simple words, in order to further refer to this post.


So, the type double consists of 8 bytes = 64 bits.(float 4 bytes = 32 bits)

And the number representation ofdouble and float consists of 3 components:sign, exponent and mantissa


DOUBLE:


FLOAT:

Naturally there is no decimal representation of numbers in this format, only binary.

  • The sign is 1 bit. If 0 it is + (plus), if 1 it is - (minus).
  • The exponent stores the degree for number 2. Can be in the range -12610 to 12710 for float and -1022 10 to 102310 for double
  • The mantissa is the fractional part of the number itself in binary form, reduced to a form in which the comma stands after the first unit without regard to that first unit and the comma


A little understanding of binary representation of numbers and its relation to decimal numbers:

2 4= 100002 = 1610

2 3= 10002 = 810

2 2= 1002 = 4

2 1=102= 2

2 0=12=110

2 -1= 0.12 =(1/2)10= 0.510

2 -2= 0.012 = (1/4)10= 0.2510

2 -3= 0.0012 = (1/8)10= 0.12510

2 -4= 0.00012 = (1/16)10= 0.062510

2 -5= 0.000012 = (1/32)10= 0.0312510

2 -6= 0.0000012 = (1/64)10= 0.01562510

2 -7= 0.00000012 = (1/128)10= 0.007812510

2 -8= 0.000000012 = (1/256)10= 0.0039062510

2 -9= 0.0000000012 = (1/512)10= 0.00195312510

2 - 10= 0.00000000012 = (1/1024)10= 0.000976562510

2 - 11= 0.000000000012 = (1/2048)10= 0.0004882812510

2 - 12= 0.0000000000012 = (1/4096)10= 0.00024414062510

2 - 13= 0.00000000000012 = (1/8192)10= 0.000122070312510

Let's review examples for double:

Example #1

We have a decimal number: 891677.4025191

This number can be represented in binary form:

1101100110110001110101.01100111000010110111011111011000101000001111111010001110
(who wants can check)))

We extract the mantissa of the given number simply by moving the comma 19 digits to the left (in this case) so that it comes after the first unit.

1.1011001101100011101011001110000101101111101111000101000001111101110001110* 2 19

But we have a mantissa of only 52 bits. So we take the first 52 significant bits

Мантисса = 1011001101100011101011001110000101101111101111000101

Exponent = (19+1023)10 = 100000100102(as the exponent is a signed number and the exponent can be negative (for example if we have 0.0000042132), it needs to be added to 1023 10(01111111111112), 011111111112 is zero, everything more is positive, less is negative. In other words, to get the reverse value of the exponent, we need to subtract 1023 from the 11 bit value of the exponent.

In total, our number 891677.4025191 will look as follows in type double:

0100000100101011001101100011101011001110000101101111101111000101

But since this is a binary representation, let's convert it exactly to decimal:

that would be891677.40251909999996425211429595947265625


Example #2

We have a decimal number: -0.00000145258556224114

This number can be represented in binary form:

-0.000000000000000000011000010111101100111010110111010011010101001111001110

Select the mantissa of this number by simply moving the comma 20 digits to the right, so that it was after the first unit.

1.1000010111101100111010110111010011010101001111001110 * 2 -20

Мантисса = 1000010111101100111010110111010011010101001111001110

exponent = (-20+1023)10=011111010112

minus sign, so the first bit is 1.

Our total number -0.00000145258556224114 will look as follows in the double type:

1011111010111000010111101100111010110111010011010101001111001110

convert it exactly to decimal:

это будет -0.00000145258556224113991124017968015191826225418481044471263885498046875



In your case, the problem occurs with the number 0.01, since in the double type it will be represented in the form:

0 01111111000 0100011110101110000101000111101011100001010001111011

which when converted into the decimal notation system is equal to 0.0100000000000000000000208166817117216858513294309377670288085937510

Whereas with representation

310 = 1.5*2 = 1.12*2 1

510 = 2.5*2 = 10.12*2 1

610 = 1.5*4 = 1.12*2 2

710 = 3.5*2 = 11.12*2 1

no problem.

Why is the number double 0.01 really greater than 0.01?

Here's why:

0 01111111000 0100011110110101110100001010111101011101001010001111011 - 0.0100000000000000000000000020816681711721685132943093776702880859375 error = 0.000 000 000 000 000 000 208166817...

0 01111111000 01000111101101011100001010001111010 - 0.00999999999999999999984747344334114097569175064563751220703125 error = - 0.000 000 000 000 001 5265566...

To understand this process chemistry you can play around with these calculators:
https://babbage.cs.qc.cuny.edu/IEEE-754.old/Decimal.html

https://baseconvert.com/ieee-754-floating-point


https://baseconvert.com/ieee-754-floating-point


 

Thank you, informative. Well, basically, should MQs have, but under-corrected or was the decision left to the user?

 

Hm. Is there a function or some other additional functionality (library, code) for saving EA parameters?

The task is to put in ondeinit code, which, for example, when running the EA on a symbol (additional function is also period analysis), would save the set settings file.

For example - EA name-symbol-period.

File with the possibility of overwriting - only the last settings for the symbol.

For example, standard settings in the tester are saved for the last run.

 
Good day. Problem on a remote computer, I can't access the MQL5 website, so I can't download the indicator I bought. I can't get into the MQL5 site, therefore I can't download the indicator I bought.
 
Slava Botalov:
Hello, I have a problem on a remote computer, I can't access the MQL5 website and therefore I can't download the indicator I bought. i can't download the indicator i bought.


but a remote computer on Zomro?

 
x572intraday:

Thank you, informative. Well, basically, should MQs have, but under-corrected, or is the decision left to the user to judge?

So they didn't get it.
There are no mistakes.
Everything is as it should be.
 
Vladislav Andruschenko:


but a remote computer on Zomro?

Yes

 
Slava Botalov:
Good day. Problem on a remote computer, I can't access the MQL5 website, so I can't download the indicator I bought. I can't download the indicator, so I can't install it on the MQL5 site.
Vladislav Andruschenko:


but a remote computer on Zomro?

Slava Botalov:

Yes


This provider is banned for gross misconduct:

Forum on trading, automated trading systems and testing trading strategies

Why is access to www.mql4.com blocked?

Renat Fatkhullin, 2020.11.17 12:16

***

The entire Zomro provider with subnets is blocked for massive fraudulent activities from his subnets.

***
 
Nikolai Semko:
So, they do not understand.
There are no errors at all.
Everything is as it should be.

That's not the point. The question is, where can it be useful, especially for traders, not programmers? I have never seen such numbers in the terminal neither in the price scale nor in the order placing window; everything there is the same everywhere (somewhere five digits, somewhere else).

 
Vladimir Karputov:


This provider has been banned for gross misconduct:

Too bad, we'll have to switch to another one. Any suggestions?

Reason: