Any way to programmatically detect/monitor cpu load or usage in MT4?

 

Is there any way I can code my EA's to programmatically monitor CPU load?

My desire to be able to do this stems from the need to coordinate auto-optimizers that could be running concurrently with other terminals.

Ideally I'd be able to have a cpu load monitor that could prevent an auto-optimizer from launching if the cpu load was above some user-defined threshold.

 

Suggestion.
Measure run time of main procedure by "GetTickCount()" in the start and in the end of this procedure, and place the obtained value to "Sleep()" after this procedure.
Probably you will have 50% of CPU load.

 

That is a great suggestion, basically the idea would be to build an internal reference point for the EA to be able to detect when a certain computation takes ~2x longer (load balancing on a single-core assuming equal priority) as a means of detecting whether or not any free CPU cores are available.

I think this will work quite well!

https://docs.mql4.com/common/GetTickCount

 

And once again, excuse me please.

Just useful information about precision of the system time in Windows, and in MetaTrader respectively:
theoretically 0,1 ms;
practically may be obtained 1 ms;
typically for ordinary systems 16 ms.
 

Hi,

if you have experience wiht writting a dll, you will find lot in google .. and call the dll from your ea.

example for calling CPU Usage: http://www.codeproject.com/KB/system/processescpuusage.aspx

 
1005phillip:

That is a great suggestion, basically the idea would be to build an internal reference point for the EA to be able to detect when a certain computation takes ~2x longer (load balancing on a single-core assuming equal priority) as a means of detecting whether or not any free CPU cores are available.

Hmmm. There are all sorts of potential problems with this, such as a calculation taking longer than normal because it indirectly involves some disk I/O at the same time as e.g. your anti-virus deciding that it would be a good idea to re-scan the whole disk. More generally, there are all sorts of occasional background processes which can cause a spike in the execution time of one in a series of identical tasks - but without having future implications.

You haven't provided much detail about the setup, but a simpler effective solution might be some sort of semaphore which prevents more than one (or two, or three) instances of MT4 running this auto-optimization at the same time.

If you are going to use GetTickCount() then you may need to watch for the fact that it must wrap round every 24 days, because it's a number of milliseconds being represented in a signed (31-bit) integer.

 
jjc:

[...] wrap round every 24 days, because it's a number of milliseconds being represented in a signed (31-bit) integer.

Unsigned...

GetTickCountGetTickCount() returns number of milliseconds passed since a system was started. The counter is limited by the resolution of the system timer. Since time is stored as an unsigned integer, it is overfilled every 49.7 days.

EDIT: The documentation is a bit misleading, as jjc points out bellow.

 
gordon:

Unsigned...

GetTickCountGetTickCount() returns number of milliseconds passed since a system was started. The counter is limited by the resolution of the system timer. Since time is stored as an unsigned integer, it is overfilled every 49.7 days.

The Win32 GetTickCount() is indeed a DWORD, but this is getting represented as an int in MT4, which is signed. Therefore, at some point, it's either going to flip from 2147483647 to -2147483648, if MT4 simply passes on the raw Win32 DWORD value and treats it as a signed int, or it's going to flip from 2147483647 to zero, if MT4 does conversion on the value.

(I'm not quite sure what you're quoting above, but the current documentation of the MT4 GetTickCount() which your text links through to doesn't include the mention of 49.7 days.)
 
jjc:
The Win32 GetTickCount() is indeed a DWORD, but this is getting represented as an int in MT4, which is signed. Therefore, at some point, it's either going to flip from 2147483647 to -2147483648, if MT4 simply passes on the raw Win32 DWORD value and treats it as a signed int, or it's going to flip from 2147483647 to zero, if MT4 does conversion on the value.

(I'm not quite sure what you're quoting above, but the current documentation of the MT4 GetTickCount() which your text links through to doesn't include the mention of 49.7 days.)

...MT4 simply passes on the raw Win32 value. I have a machine which, conveniently, has been running for between 24 and 49 days (0x923BED3A seconds). The MT4 GetTickCount() function returns -1841535843.

Therefore, strictly speaking, from the point of view of MT4's signed ints, the value starts at zero; flips over to negative after 24.9 days; increases for 49.7 days; and the flips over again. It "overfills" every 49.7 days except for the first period after booting, when in effect it "overfills" after only 24.9 days.

 
jjc:
The Win32 GetTickCount() is indeed a DWORD, but this is getting represented as an int in MT4, which is signed. Therefore, at some point, it's either going to flip from 2147483647 to -2147483648, if MT4 simply passes on the raw Win32 DWORD value and treats it as a signed int, or it's going to flip from 2147483647 to zero, if MT4 does conversion on the value.
I see. The documentation is a bit misleading (or an inaccurate translation). I had a feeling there was something wrong with it...
 
jjc:
(I'm not quite sure what you're quoting above, but the current documentation of the MT4 GetTickCount() which your text links through to doesn't include the mention of 49.7 days.)
It's from the book: https://book.mql4.com/functions/common (on the bottom).
Reason: