The appearance of an implicit copy constructor allows such entries to be made.
voidOnStart()
{
MqlTick Tick;
// Two different ways to call MqlTick::MqlTick(const MqlTick&)constMqlTick Tick1 = Tick;
constMqlTickTick2(Tick); // b5200-: function not defined, b5200+: OK.
}
fxsaber #: Pay attention to such constructs in your sources. After b5200 they may stop working as before. The compiler will not report anything about it.
Here is an example of such danger of different execution BEFORE and AFTER b5200.
struct A
{
int Tmp;
voidoperator =( const A&) { Print(__FUNCSIG__); }
A f()
{
return(this); // Return object.
}
};
voidOnStart()
{
A a;
a.f(); // b5200-: void A::operator=(const A&), b5200+: NULL.
}
That's why you should look carefully at functions, where the object is returned.
It returns a unique counter value that is incremented each time any MQL program (Expert Advisor, Script, Indicator) calls MQLInfoInteger(MQL_GLOBAL_COUNTER).
Think of it as a monotonically increasing global launch counter across the whole MetaTrader terminal session, not just within one EA or chart.
The counter starts at 1 when the terminal is launched and increases every time a new MQL program instance calls MQLInfoInteger(MQL_GLOBAL_COUNTER).
The counter period is a 32-bit signed integer in the range [1, 2147483647]
Use cases
Seeding a PRNG with a value that is different for each program launch (to avoid identical sequences when multiple EAs/scripts are started simultaneously).
Creating unique identifiers across all scripts/EAs without risk of collision.
I'm sure that, for example, GetMicrosecondCount can always be used to get guaranteed different values with any reasonable number of concurrently running programmes.
I am sure that, for example, GetMicrosecondCount can always be used to get guaranteed different values for any reasonable number of concurrently running programmes.
I seem to have come across non-unique values. Probably when starting the terminal or connecting to an account. But I don't remember exactly.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
The appearance of implicit copy constructor allows making such records.
However, the use of this feature loses compatibility with MQL4.
Pay attention to such constructs in your sources. After b5200 they may stop working as before. The compiler will not report anything about it.
Here is an example of such danger of different execution BEFORE and AFTER b5200.
That's why you should look carefully at functions, where the object is returned.
Undocumented constant:
MQL_GLOBAL_COUNTER
It returns a unique counter value that is incremented each time any MQL program (Expert Advisor, Script, Indicator) calls MQLInfoInteger(MQL_GLOBAL_COUNTER).
Think of it as a monotonically increasing global launch counter across the whole MetaTrader terminal session, not just within one EA or chart.
The counter starts at 1 when the terminal is launched and increases every time a new MQL program instance calls MQLInfoInteger(MQL_GLOBAL_COUNTER).
The counter period is a 32-bit signed integer in the range [1, 2147483647]
Use cases
Seeding a PRNG with a value that is different for each program launch (to avoid identical sequences when multiple EAs/scripts are started simultaneously).
Creating unique identifiers across all scripts/EAs without risk of collision.
Example
If you run this script multiple times, you’ll see increasing numbers like:
Important:
It is global to the terminal session, not reset per chart or EA.
Once you restart MetaTrader, the counter resets back to 1 .
So in short:
MQLInfoInteger(MQL_GLOBAL_COUNTER) gives you a unique, incrementing integer each time an MQL program calls the MQLInfoInteger function.
(How it was detected: see https://www.mql5.com/en/code/56055)
Undocumented constant:
MQL_GLOBAL_COUNTER
Thanks for the information!
MQL_GLOBAL_COUNTER
Thanks for the information!
I wonder if atomic access to this counter is implemented. If 2 or more indicators are running on the same instrument, will they get different numbers?
If 2 or more indicators work on the same instrument, do they get different numbers?
Different. There are 2 Buttons indicators attached to the chart, the first one has a unique ID "Buttons01" at the top, the second one has "Buttons02".
Thanks for the information!
I wonder if atomic access to this counter is implemented. If 2 or more indicators are running on the same instrument, will they get different numbers?
Indicators for a given instrument are running on the same thread, so they are executed in series not in parallel.
will they get different numbers?
I'm sure that, for example, GetMicrosecondCount can always be used to get guaranteed different values with any reasonable number of concurrently running programmes.
I am sure that, for example, GetMicrosecondCount can always be used to get guaranteed different values for any reasonable number of concurrently running programmes.
I seem to have come across non-unique values. Probably when starting the terminal or connecting to an account. But I don't remember exactly.