Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network affiliate program and make money!
Pierre DELAHAYE
64
Pierre DELAHAYE 2014.02.23 20:03 

I just notice that global variables declared in a EA keep their value when you stop the EA, and are restored even if you close terminal and reboot your machine.
So these datas are certainly saved on the hard disk but where and what is the format ?

And... while I'm here,... ;) are these datas saved at each tick or when I close or stop the EA ?

thanks and have an excellent day/night according your country

whroeder1
13602
whroeder1 2014.02.23 20:28  

Common (globally declared) variables are not restored, they are reloaded on EA start. Not on deinit/init cycles.

Terminal (Global) Variables are not the EA's, they are visible to any script, indicator or EA. If you want to be certain, write a file.

They are saved when set, (exactly when isn't documented so I guess at end of tick, but it's no longer at terminal close which was unsafe.)

Why do you care where they are stored. Just open Tools -> Global Variables or F3

Pierre DELAHAYE
64
Pierre DELAHAYE 2014.02.23 20:39  

Thanks WHRoeder,

I am speaking about Common : (globally declared) variables

But yes they are restored... If you are using by exemple, a double variable which is equal at one moment at 128.24 and you stop the EA, close MT4, reboot your VPS,... when you will restart your EA, the value of this variable will always be equal to 128.24. So it shows that MT4 stores (or saves) theses data somewhere else when EA stop.

But where, how, and when... ?

Vitalie Postolache
11028
Vitalie Postolache 2014.02.23 20:58  
Trader55:

Thanks WHRoeder,

I am speaking about Common : (globally declared) variables

But yes they are restored... If you are using by exemple, a double variable which is equal at one moment at 128.24 and you stop the EA, close MT4, reboot your VPS,... when you will restart your EA, the value of this variable will always be equal to 128.24. So it shows that MT4 stores (or saves) theses data somewhere else when EA stop.

But where, how, and when... ?


Look in "data folder\MQL4\Files\" for new created of modified files after you stop your EA. But better search in source code where it accesses any file in write mode.
Keith Watford
Moderator
7896
Keith Watford 2014.02.23 21:07  

I understand that variables that are declared without assigning them with an initial value are now no longer automatically set to zero.

Is it possible that when you restart that the EA manages to use the same bytes of memory as it did last time and so the value assigned to the variable is the same as before?

If so, I wouldn't rely on it. Best to give the variable a zero value when declaring it.

Alain Verleyen
Moderator
28537
Alain Verleyen 2014.02.23 22:01  
Trader55:

Thanks WHRoeder,

I am speaking about Common : (globally declared) variables

But yes they are restored... If you are using by exemple, a double variable which is equal at one moment at 128.24 and you stop the EA, close MT4, reboot your VPS,... when you will restart your EA, the value of this variable will always be equal to 128.24. So it shows that MT4 stores (or saves) theses data somewhere else when EA stop.

But where, how, and when... ?

The globals variables (I am not talking about Globals Variables of the Terminal) are NOT preserved when you remove an EA from a chart, you close MT4 or reboot your computer. If after close/reboot...your variables still have the same values it's because your EA save/restore them in one way or an other.
Jack Thomas
501
Jack Thomas 2014.02.23 22:36  
Trader55:

I just notice that global variables declared in a EA keep their value when you stop the EA, and are restored even if you close terminal and reboot your machine.
So these datas are certainly saved on the hard disk but where and what is the format ?

And... while I'm here,... ;) are these datas saved at each tick or when I close or stop the EA ?

thanks and have an excellent day/night according your country


This pages may be of some help to you:

https://book.mql4.com/functions/globals

https://book.mql4.com/variables/globals

https://docs.mql4.com/globals

Jack Thomas
501
Jack Thomas 2014.02.23 22:41  
Trader55:

I just notice that global variables declared in a EA keep their value when you stop the EA, and are restored even if you close terminal and reboot your machine.
So these datas are certainly saved on the hard disk but where and what is the format ?

And... while I'm here,... ;) are these datas saved at each tick or when I close or stop the EA ?

thanks and have an excellent day/night according your country


persistent global variables are typically stored in \MetaTrader 4\profiles\gvariables.dat

I don't know the specific format for the file, but I believe that is what you are looking for.

Pierre DELAHAYE
64
Pierre DELAHAYE 2014.02.23 23:16  

@CodeMonkey : I think you confuse Common (globally declared) variables and Terminal (Global) Variables .

For my case my question is realted to Common (globally declared) variables

@angevoyageur : Same, my question is relative to Common (globally declared) variables, NOT terminal variables

@GumRai : Not possible that MT4 manage that in memory because it retrieve value event if you stop your PC.

@Evillive : Could you be more precise with the path of the folder :data folder\MQL4\Files\" ??

Vitalie Postolache
11028
Vitalie Postolache 2014.02.23 23:19  
Trader55:

@Evillive : Could you be more precise with the path of the folder :data folder\MQL4\Files\" ??

Click on File > Open data folder in your terminal and look at it's path, it's dependent of OS and trader's account, and even of starting terminal mode (portable or not) so nobody knows your path.
/
To add comments, please log in or register