Any questions from a PROFI to a SUPER PROFI - 1. - page 20

 

Given:

In the init() function of the EA, an MQL PSP generator is initialized: MathSrand(...). When the terminal starts, several (for clarity, let's say three) copies of the Expert Advisor are loaded from the template. The loading is fast, so it is very likely (and almost always is) that the TimeLocal() and TimeCurrent() functions return the same values in all copies.

Question:

What tricks are there to get the PRNG to initialise different numbers in different copies of the EA? In other words, where (with minimal programming effort) to get the element of randomness?

 
alsu:

Given:

In the init() function of the EA, an MQL PSP generator is initialized: MathSrand(...). When the terminal starts, several (for clarity, let's say three) copies of the Expert Advisor are loaded from the template. The loading is fast, so it is very likely (and almost always is) that the TimeLocal() and TimeCurrent() functions return the same values in all copies.

Question:

What tricks are there to get the PRNG to initialise different numbers in different copies of the EA? In other words, where (with minimal programming effort) to get the element of randomness?

GetTickCount?
 
sergeev:
GetTickCount ?


might work, but not for sure...

A millisecond for a programme can be an eternity.)

 
alsu:

might work, but not for sure...
option 2 - use global variables to create "semaphores" to initialise EAs in sequence.
 
sergeev:
option 2 - use global variables to create "semaphores" to initialise the experts in sequence.
That's closer to the point, thank you.
 

Question about fetching rows from dll in mql.

function mysql_fetch_row from libmysql.dll returns type MYSQL_ROW

This type is defined as: typedef char** MYSQL_ROW

How do I get to this returned string array?

 
 
Zhunko:
Are the dimensions of the array known?
yes, the number of lines is known.

but the length of each row is not.

There's another thing in that link example - getting a *lengths pointer.
It turns out to be an array too... But how to get to it...

	unsigned long *lengths;lengths =  mysql_fetch_lengths(result); for(i = 0; i < num_fields; i++) { printf("[%.*s] ", (int) lengths[i]
, row[i] ? row[i] : "NULL"); }

here's what you get in MQL when just passing result of mysql_fetch_row to string

p0ƒu0ƒ;1;a

where
p0ƒu0ƒ is the address (8 bytes) of the string
;1;a is its usable data


but if you set it to int, then instead of p0ƒ the address is 42152040


	          
 
declspec (dllexport) char* WINAPI Func(const char* szBufString,
                                       const int   nSizeBuf)
 {
  MYSQL_ROW aszString; 
  memcpy_s(szBufString, nSizeBuf + 1, aszString[номер ячейки], strlen(aszString[номер ячейки]));
  return(szBufString);
 }

If the pointer to the string does not change while the program is running, you can return the pointer to the string without copying it to the buffer.

declspec (dllexport) char* WINAPI Func()
 {
  MYSQL_ROW aszString;
  return(aszString[номер ячейки]);
 }
 

So there is no way to do it in MQL? Not even MQL5?

Zhunko:
If the pointer to the string does not change while the program is running, you can return the pointer to the string without copying it to the buffer.

Simply
return aszString[номер ячейки]