Discussion of article "MQL5 Programming Basics: Global Variables of the Terminal"

 

New article MQL5 Programming Basics: Global Variables of the Terminal has been published:

Global variables of the terminal provide an indispensable tool for developing sophisticated and reliable Expert Advisors. If you master the global variables, you will no more be able to imagine developing EAs on MQL5 without them.

 Execute the script and open the global variables window from the terminal. The window should contain a new variable named "test" and the value of 1.23 (Fig. 4).

 
Fig. 4. Fragment of the global variables window with the new "test" variable

Author: Dmitry Fedoseev

 

Good articles for beginners.

The GlobalVariableTemp() function creates a temporary global variable (that exists till the terminal is stopped). In a few years that I develop EAs on MQL5, I have never faced the need for such a variable. Moreover, the very concept of a temporary global variable contradicts the basic principle of their application — long-term data storage not affected by the terminal relaunches.

That's not the only usage of Global Variables of the Terminal. They can also be used to exchange information between different EAs or indicators. So in such case it could be a feature to have data in memory only and not kept of terminal restart.

The mutex part is very interesting, I have one question and one remark.

It may happen that some EA is removed from a chart during the OnTick() function execution but the Mutex_Release() function is not executed.

How an EA could be removed and the Mutex_Release() function not executed ? If you remove an EA from a chart in a normal way (close chart, remove EA, or close terminal), it will never stop the execution flow. I am missing something ?

So my remark, the only way Mutex_Release() could not be executed is with an "hard" stop, power or hardware failure etc..., so that makes your mutex global variables a perfect candidate to be created as a temp using GlobalVariableTemp().

 

Do global variables work during Strategy Testing?

For example, when an indicator stores values to a GV and an EA reads them, will the Strategy Tester fetch the values during simulation on time?

 
Admiral Thrawn:

Do global variables work during Strategy Testing?

For example, when an indicator stores values to a GV and an EA reads them, will the Strategy Tester fetch the values during simulation on time?

Yes

 

Hi  Dmitry,

I realise your article is a few years old, but I thought I might share something and hopefully also ask a question!

So you mention that you have not found use of the Temp Global Var.  I'm developing something that requires that exactly.  I was racking my head trying to figure a way to implement sharing IO Completion Port handle through Global Variables, in particular on crash, or normal restart.  I'm designing an order handling system using Windows IO Completion Ports. Since we can create Win32 threads from MQL5, I cannot create a thread pool while creating the IOCP Server, so my workaround using Services is;

  1. Create an IOCP Server, instead of creating threads(which we cannot), I save the IOCP Handle to a Global Var
  2. I then open at least 2 other Services, which act as Worker Threads, and they read the IOCP Handle from Global Var, and register themselves to the IOCP

In the event of the terminal restarting, abnormally or otherwise, I want that IOCP Handle to have disappeared on terminal start, so I can create a new IOCP Handle for a fresh start. It is makes for a much cleaner implementation.

I was also wondering, how fast are Global Variables, and how reliable are they?

Thanks for the great article.  It was a great read,

Shep


 
MetaQuotes:

New article MQL5 Programming Basics: Global Variables of the Terminal has been published:

Author: Dmitry Fedoseev

This what the Python integration needs to send data to and from Python to MLQ EA's. Then an EA developed in Python could be tested in the Strategy Tester, unless there is some impossibility I don't know about.
Reason: