Errors, bugs, questions - page 1932

 
Комбинатор:

Generally speaking, the decimal type would be useful, it's a handy thing.

Yes, its absence in software that works with prices has been confusing, to say the least, since the beginning of MT's existence.

PS. Now, with the existence of OOP language, MQ probably think that those who wish can write a class for themselves. Only you can't put it in a simple structure afterwards - you'd have to serialize/deserialize it into something simple like ulong.
 
Slava:

I am indeed very grateful to you for answering in such detail. Normalisation is used to generate trade requests.

// Point = 0.001, Digits = 3
OrderSend(8274 * Point);
OrderSend(NormalizeDouble(8274 * Point, Digits));

In this example it would appear that different prices are sent in these two OrderSend.

It has always been assumed that multiplying an integer by a Point does not require additional normalisation (that's how SL and TP were set, for example).

So which of the two lines will cause an error?

 
Stanislav Korotky:

Yes, its absence in software that works with prices has been embarrassing since the beginning of MT's existence, to say the least.

It can't be that no one has written in the SD
 
fxsaber:

I am indeed very grateful to you for answering in such detail. Normalisation is used to generate trade requests.

In this example it would appear that different prices are sent in these two OrderSend.

It has always been assumed that multiplying an integer by a Point does not require additional normalisation (that's how SL and TP were set, for example).

So which of the two lines will cause the error?

Cool

#include <MT4Orders.mqh>

void OnStart()
{
  const double Num = 8.274;
  const double Norm = NormalizeDouble(Num, 3);  
   
  Print(Num);  // 8.273999999999999
  Print(Norm); // 8.274000000000001
  
  Print((double)DoubleToString(Num, 3) == Num);     // true - без нормализации все замечательно
  Print((double)DoubleToString(Norm, 3) == Norm);   // false - а после нормализации полный облом!
  
  OrderSend("USDSEK", OP_BUYLIMIT, 1, Num, 0, 0, 0);
  OrderSend("USDSEK", OP_BUYLIMIT, 1, Norm, 0, 0, 0);
}

Result

script Test (EURUSD,M1) loaded successfully
'6185283': buy limit 1.00 USDSEK at 8.27400
'6185283': accepted buy limit 1.00 USDSEK at 8.27400
'6185283': order #158260308 buy limit 1.00 / 1.00 USDSEK at market done in 98.718 ms
'6185283': buy limit 1.00 USDSEK at 8.27400
'6185283': accepted buy limit 1.00 USDSEK at 8.27400
'6185283': order #158260309 buy limit 1.00 / 1.00 USDSEK at market done in 120.328 ms
script Test (EURUSD,M1) removed

Both queries with different prices, but executed without problems for the same price. How so?

 
fxsaber:

Cool

Result

Both queries with different prices, but executed without problems at the same price. How could this be?

Very simply, from the point of view of double, these numbers are identical, because double stores 52 bits of mantissa or 15 decimal places. Differences of plus or minus in subsequent bits don't count. Here is an article on hubra.

 
Stanislav Korotky:

Very simply, from the point of view of double, these numbers are the same because double stores 52 bits of the mantissa or 15 decimal places. Differences of plus or minus in subsequent digits do not count. Here is an article on hubra.

void OnStart()
{
  const double Num = 8.274;
  const double Norm = NormalizeDouble(Num, 3);
  
  Print((string)(Norm - Num)); // 1.77635683940025e-15
}
 

fxsaber, 2017.07.19 13:00

void OnStart()
{
  const double Num = 8.274;
  const double Norm = NormalizeDouble(Num, 3);
  
  Print((string)(Norm - Num)); // 1.77635683940025e-15
}

И?

 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2017.07.17 21:49

If you click on "Stop" during a single run, OnDeinit and destructors are not called.

Is this a flaw or a bug?

Right now, pressing the "Stop" button causes a hard disconnect with the Agent. So hard that it's impossible to see the report without waiting for the completion of a single run.

In MT4 you can always see the trading history of an incomplete single trade. But in MT5 there is no way.

Is it possible not to terminate connection hard, but to send a flag to Agent which could be caught and execute OnDeinit on it?

 
Stanislav Korotky:

И?

Stanislav Korotky:

Very simply, from the point of view of double, these numbers are the same because double stores 52 bits of mantissa or 15 decimal places. Differences of plus or minus in subsequent bits do not count. Here is an article on hubra.

The difference is greater than 1e-15. Moreover, Num != Norm. They are different numbers, not the same.
 
Stanislav Korotky:

И?

Actually I agree, if we set a literal, it would be logical that its double representation is normalized by the number of digits in the literal

Reason: