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

 

An exemplary article!

Глобальные переменные терминала — незаменимое средство при разработке сложных и надежных экспертов. Освоив работу с глобальными переменными терминала, вы уже не сможете представить себе создание экспертов на MQL5 без их использования.

I somehow do without global terminalvariables. There are no tasks where they would be needed.

 
fxsaber:

An exemplary article!

I somehow do without global terminalvariables. There are no tasks where they would be needed.

Well, let's say that there are moments when it is impossible to do without them, except for writing to a file and then reading it, but this is very resource-intensive for many tasks, that's where global terminal variables come to the rescue.


Dmitry Fedoseev:
You should not confuse global terminal variables with the well-known global program variables (Fig. 2) and try to find their analogy in other programming languages, if you are familiar with them.

Well here of course there are some doubts, what is not a replacement in the language js and php, within the domain work, however, as well as glob.terminal work only in the environment of an individual terminal


 
Vitaly Muzichenko:

Well, let's say that there are times when it is impossible to do without them, except for writing to a file and then reading it, but this is very resource-intensive for many tasks, that's where global terminals come to the rescue.

No. I meant something else. TC interaction - there were no such tasks.

 
Vitaly Muzichenko:

...

Well there is certainly some doubt here, what is not a replacement in the language js and php

Pretty much yes, hadn't thought of that. Well good, it makes sense (considering some of the hassles when using cookies and which are completely absent when using global variables).

 
fxsaber:

No. That's not what I meant. Interaction of TCs - there were no such tasks.

Look, the simplest one: there is an Expert Advisor and we need to do something in time, let's say not more often than once every three hours. If we don't use glob.variables, then after the terminal reboot we completely lose control of time and don't know when the event was last executed, but if the time is stored in a global variable, then we can get this time at any time, regardless of how many times we rebooted the terminal.

And in general, the area of application is very wide, and as I wrote earlier, it is not always possible to do without them.

 
fxsaber:

An exemplary article!

I somehow do without global terminalvariables. There are no tasks where they would be needed.

How would you solve such a problem: stop-reversal strategy - at the market order at the stoploss there is a stoporder of increased volume, and so the reversal is performed and the lot is increased until there is profit. But the multiplication factor is 1.4, such a factor that not every multiplication will actually increase the lot (because of the need to normalise the lot). Here we can only count through MathPow(), which means that we need the initial lot and order index.

You can also go through the history, but still, the initial order must be labelled somehow.

How would you do it without global variables?

 

click on any link in the table of contents:

drive to such a page:


 
Dmitry Fedoseev:

How would you solve this problem: stop-reversal strategy - at the market order at the stop loss there is a stopper of increased volume, and so the reversal is performed and the lot is increased until there is a profit. But the multiplication factor is 1.4, such a factor that not every multiplication will actually increase the lot (because of the need to normalise the lot). Here we can only count through MathPow(), which means that we need the initial lot and order index.

You can also go through the history, but still, the initial order must be labelled somehow.

How would you do it without global variables?

Magic.
 

What I expected from the article was an explanation:

-- how and where global variables are stored (in memory, on disc)

-- how often these global variables can be read

-- etc.

Unfortunately, I didn't find any answers to these questions in the article.

 
Vitaly Muzichenko:

Well look, the simplest: there is an Expert Advisor and we need to do something on time, let's say not more often than once every three hours. If we don't use glob.variables, then after terminal restart we completely lose control of time and don't know when the event was last executed, but if the time is stored in a global variable, then we can get this time at any time, regardless of how many times we restarted the terminal.

And in general, the area of application is very wide, and as I wrote earlier, it is not always possible to do without them.

Yes, global variables are ideal in such a setting. I just never had any tasks when writing TS and indicators, where it would be necessary to memorise something at the terminal level.

That's why I was somewhat surprised by such a statement

Global terminal variables are an indispensable tool when developing complex and reliable Expert Advisors. Once you have mastered working with global terminal variables, you will not be able to imagine creating Expert Advisors in MQL5 without their use.

I know global variables, graphical objects and files at a good level. But I have never memorised anything for the TS using them (or anything else). Although, like, TCs were reliable and quite heavy.