global or not global, that is the question

 
I'm testing this now with a few of my scripts, but perhaps someone already knows the answer to this question.

Are the variables defined at the beginning of the script global? Do they reside in the program memory attached to the currency and chart until MetaTrader is restarted?
 
I'm testing this now with a few of my scripts, but perhaps someone already knows the answer to this question.

Are the variables defined at the beginning of the script global? Do they reside in the program memory attached to the currency and chart until MetaTrader is restarted?




FYI, none of the variables are globalized apart from ones that are saved globally.

I've been trying to figure out why my automation systems, get into more trades if the Metatrader gets reset once an hour. I know the code is solid - or it wouldn't be trading at all. I am under the impression that MetaQuotes is taking a while to let go of closed trades in memory. Considering that my automation scripts work over multiple currencies, this issue is compounded.

It would help to know if the OrderSelect syntax is accessing information on a server where the account is being processed, or if the command OrderSelect is only accessing the local MetaTrader software.

Actually, from a programmer's standpoint, it would be helpful to have a list of commands that access the server and commands that access the Terminal for information. I could then solve my problem in a hurry.
 
Regarding "global variables", you need to separate two things:

1. Variables, that are called "variables of global scope" in C++, meaning, that the variable is accessible from the whole program, it is defined before the main() func, not in a separate function.
These are kind of normal variables in mq4, as long as the terminal is running, they keep their value, and can be accessed from anywhere in the EA, and belong only to the EA that defined it. (if you have two instances running of the same EA, containing e.g. a double x, then the two x variables will have separate, and different values). These get reset upon any deinits (EA unattached, terminal restart)!

2. Variables, that are called "global variables" in mql4, and defined by GlobalVariableSet() func, are stored in the terminals Global Variable storage (press F3), are accessible by any running EAs , so GlobalVariableSet(x,10) will return 10 for every EAs that is calling it. These variables can only be reseted manually, or explicitly in the EA, so they keep their value upon deinit, even when terminal is restarted. Naturally these can be accessed from anywhere in an EA, but only by using the special functions for the purpose.
These are the main means of communicating between two or more EAs, and storing data that is important on the long run.
 
Regarding "global variables", you need to separate two things:

1. Variables, that are called "variables of global scope" in C++, meaning, that the variable is accessible from the whole program, it is defined before the main() func, not in a separate function.
These are kind of normal variables in mq4, as long as the terminal is running, they keep their value, and can be accessed from anywhere in the EA, and belong only to the EA that defined it. (if you have two instances running of the same EA, containing e.g. a double x, then the two x variables will have separate, and different values). These get reset upon any deinits (EA unattached, terminal restart)!

2. Variables, that are called "global variables" in mql4, and defined by GlobalVariableSet() func, are stored in the terminals Global Variable storage (press F3), are accessible by any running EAs , so GlobalVariableSet(x,10) will return 10 for every EAs that is calling it. These variables can only be reseted manually, or explicitly in the EA, so they keep their value upon deinit, even when terminal is restarted. Naturally these can be accessed from anywhere in an EA, but only by using the special functions for the purpose.
These are the main means of communicating between two or more EAs, and storing data that is important on the long run.




I realize that this might be out of line, but I was theorizing earlier that perhaps the variables treated at the beginning of the script were being handled as globals due to a bug in the system. I know from testing that this is now not the case.

I am simply trying to figure out why MetaQuotes is holding Orders that have been previously closed out in the local memory reserved by the Terminal. When the Terminal is shut down and reopened, this memory is then freed and new trades pop in. This has been going on at least since July of this year. The only work around I have at the moment is to have an external program close the trade station and reopen it every hour.

Now I am theorizing that the Terminal program is holding Open Orders in local memory long after they've been closed. These dangling open orders are still being processed by the OrderSelect command, which tells my system to stop producing new orders.
Reason: