Download MetaTrader 5

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

To add comments, please log in or register
Traders have already contributed more than 300 articles. Write your own one!
MetaQuotes Software Corp.
Moderator
181339
MetaQuotes Software Corp. 2016.11.25 13:11 

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

Alain Verleyen
Moderator
30745
Alain Verleyen 2016.11.25 23:00  

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().

To add comments, please log in or register