Questions from a "dummy" - page 69

 
rlx:

Everything is correctly converted without errors

In the"MQL5 Reference / Language Basics / Data Types / Type conversion" section, two things are mentioned:

1) long=>double conversion may lead to loss of accuracy;

2) datetime type is allowed instead of long (they take 8 bytes).

I come to the conclusion, that, ideally, conversion datetime =>double may also lead to loss of accuracy. But I can't give an example.

rlx:

Why not store datetime in indic......or buffers of type double

Lots of dots added, or some kind of reference appears.

It's easier to put an extra space between the two words: 'indicator buffers' (two spaces).

 
Yedelkin:

In the"MQL5 Reference Guide / Language Basics / Data Types / Type conversion " section, two things are mentioned:

1) long=>double conversion can lead to loss of accuracy;

2) datetime type (take 8 bytes each) is allowed instead of long type.

I come to the conclusion, that, ideally, conversion datetime =>double may also lead to loss of accuracy. But I can't give an example.

It's easier to put extra space between two words: "indicator buffers" (two spaces).

Write a simple conversion test and you will see for yourself. And you can tell the rest of us later.

 
Vladix:

Write a simple transformation test and you will see for yourself. And you can tell everyone else later.

Do you have a substantive answer?

A "simple conversion test" has already been given by rlx. It seems to work correctly. The doubts based on the reference material are outlined above. If there is an example of incorrect datetime =>double conversion, please ask.

 
Yedelkin:

Is there a substantive answer?

A "simple conversion test" has already been givenby rlx. It seems to work correctly. The doubts based on the reference material are stated above. If there is an example of incorrect datetime =>double conversion, please send it to me.

void OnStart()
  {   
   double vDbl = 1.7976931348623158 e+308;
   datetime vTime = (datetime)vDbl;
   
   Print((double)vTime);  
  }

2011.09.25 16:24:38 test (EURUSD,H1) -9.223372036854776e+018

This is an example of when problems might occur, but it is definitely not your case

 
Vladix:

2011.09.25 16:24:38 test (EURUSD,H1) -9.223372036854776e+018

This is an example of when problems might occur, but it is definitely not your case

Congrats! Live and learn!
 
Vladix:

2011.09.25 16:24:38 test (EURUSD,H1) -9.223372036854776e+018

This is an example when there might be a problem, but it is definitely not your case

Not a very correct example, as they say dickhead for 20 minutes (not about you but about those who will use it)

The current datetime value is 1316816136 those 10 digits, that's 40 years, mantissa double has 16 digits,

hence the overflow of the mantis double and the subsequent incorrect conversion from datetime to double will occur in 6*40=240 years.

I think we will have time to use it.

 
Yedelkin:
Spas! You live and learn a long time!

I've now put together an example just for you. The output is as follows:

datetime type is defined till 31.12.3000 23:59:59, it is32535215999

the double type is defined up to1.7976931348623158e+308

It turns out that when converting the maximum possible value of datetime to double, there is still allowable margin in the number of significant digits.

Hence, the conclusion is that it will work correctly in all cases.

Urain:

This is not a very correct example, as it is said to a fool with a glass dick for 20 minutes.

Not a good analogy.

It's just an example of the need to check the boundary values of values when giving types, just as a side note. But again, this is not the case.

 

The previous calculations I did not do correctly, more precisely here: 15 digits are used, because if the 16th is present, there is a conversion error

   long i,l;double d;
   for(i=0;i<999999999999999;i+=365*86400){d=(double)i;l=(long)d;if(i!=l)break;}
   Print("до ",(1970+i/(365*86400))," года datetime в double преобразуется верно");

up to 31711762 year datetime to double is converted correctly

So we sleep well until 31 millionth year.

 

Calling imported functions from ex5 library.

Please, explain. Read https://www.mql5.com/ru/docs/runtime/imports

System libraries (DLLs) are loaded according to the rules of the operating system. If the library is already loaded (e.g., by another Expert Advisor or even from another client terminal running in parallel), the call goes to the already loaded library.

How are ex5 libraries loaded?If the library is already loaded (e.g., by another Expert Advisor, and even from another client terminal, running in parallel),

For the test, I have created the library

lib.mq5.

#property library
int      i=0;

int Get(void) export {return(i++);}

Compiled lib.mq5 into lib.ex5

Created Expert Advisor

expert.mq5

#import "lib.ex5"
  int Get(void);
#import
void OnTick()
  {
   Print(Get());
  }

Compiled it.

I put the Expert Advisor on EURUSD.

It prints

0

1

2

3

4

5

Putting an Expert Advisor (optional) on GBPUSD

Prints

6 --- from EURUSD Expert Advisor

0 --- from GBPUSD Expert Advisor.

7 --- from EURUSD Expert Advisor

1 --- from GBPUSD advisor.

8 --- from EURUSD advisor

2 --- from GBPUSD advisor.

I.e. another copy of lib.ex5 library is downloaded for GBPUSD Expert Advisor.

Does anybody know how to print

6 --- from EURUSD Expert Advisor

7 --- from GBPUSD Expert Advisor.

8 --- from EURUSD Expert Advisor.

9 --- from GBPUSD advisor.

10 --- EURUSD advisor

11 --- from GBPUSD advisor.

Only using the capabilities of MT5

PS// Or maybe I need to hook up the library in a special way.

///// I.e. I need this ex5 library to be loaded once.

Документация по MQL5: Программы MQL5 / Вызов импортируемых функций
Документация по MQL5: Программы MQL5 / Вызов импортируемых функций
  • www.mql5.com
Программы MQL5 / Вызов импортируемых функций - Документация по MQL5
 

Hello. Can you tell me please. Why do orders and trades have a ticket but positions don't?

And what is the difference between a ticket and an identifier?

Reason: