Global variables in MT5 and restart Windows

 

Hello.

I figure out MT5 delete all saved  globals when Windows restart in time when MT5 work.

Is there any  way to stop MT5 from deleting global variables at the time of Windows restart?

Or better use another way to save important information?

 
Piotr Storozenko:

Hello.

I figure out MT5 delete all saved  globals when Windows restart in time when MT5 work.

Is there any  way to stop MT5 from deleting global variables at the time of Windows restart?

Or better use another way to save important information?

no it does not,  they remain for 4 weeks after last access.

but if you want another way you will need to store data to files.

 
Paul Anscombe #:

no it does not,  they remain for 4 weeks after last access.

Want be sure I understand you correct.  Is that mean no way get this globals? 

I know what happned mainly  with globals .

My question is only about this particular problem when MT5 works with saved  globals and the system restarts.

And thanks , I know about files, but it's  a bit work for recoding :) 

 
Piotr Storozenko #: Want be sure I understand you correct.  Is that mean no way get this globals?

It means you are wrong. They are saved. You get them the usual way.

 
William Roeder #:

It means you are wrong. They are saved. You get them the usual way.

So try saved some globals in MT5. Then simulate restart  system  with running MT5 and you will see clean property  globals. 

Globals stay if we before simulate restart close MT5.

In MT4 global stay, but in MT5 it clean. It why I sak.

 
Piotr Storozenko #: So try saved some globals in MT5. Then simulate restart  system  with running MT5 and you will see clean property  globals. Globals stay if we before simulate restart close MT5. In MT4 global stay, but in MT5 it clean. It why I sak.

There must be something wrong on your system as that is that is not the general case for most users of MetaTrader 5.

Maybe the directory permissions are incorrect, or some kind of misconfiguration, or there are corrupt files, or your MetaTrader 5 terminal is not shutting down properly and not flushing files correctly. Maybe your shutdown process is causing the terminal to be forced to shutdown prematurely and does not complete its shutdown cycle correctly.

In my own case, the Global Terminal Variables persist between restarts with no issues, on both MT5 and MT4.

EDIT: In your MQL5 code, force flushing the GTVs and see if the data file is updated on the disk. If it does not, then there is a problem at the file level. If it does, then MT5 may not be being shutting down properly.

GlobalVariablesFlush

Forcibly saves contents of all global variables to a disk

 
Piotr Storozenko #:

So try saved some globals in MT5. Then simulate restart  system  with running MT5 and you will see clean property  globals. 

Globals stay if we before simulate restart close MT5.

In MT4 global stay, but in MT5 it clean. It why I sak.

You are wrong it works fine
You can even look at the global variables from the terminal
Show your code where you set them 
 

It's possible to lose some global variables on unexpected system restarts:

To optimize performance, global variables reside in memory while the terminal is running. However, as we know, variables are stored between sessions in a special file. This applies to all global variables except temporary variables. Normally writing variables to a file happens when the terminal closes. However, if your computer suddenly crashes, your data may be lost. Therefore, it can be useful to forcibly initiate writing in order to guarantee the safety of data in any unforeseen situations. For this purpose, the MQL5 API provides the GlobalVariablesFlush function.
MQL5 Book: Common APIs / Client terminal global variables / Flushing global variables to disk
MQL5 Book: Common APIs / Client terminal global variables / Flushing global variables to disk
  • www.mql5.com
To optimize performance, global variables reside in memory while the terminal is running. However, as we know, variables are stored between...
 
Thanks, never use    GlobalVariablesFlush before, will check and let you know.
 

All i can tell you is this from bad experience which lost me money from EA that i bought that was using MT5 global variables 

If you want peace of mind, dont have anything to do with mt5 global variables. IN my case the data only lasted for a month each time and i did not realise this so all my EA was getting lost and positions were not managed.

Nobody including the makers of mt5 seems to have a clue about the lifestyle of global variables, if you intend to trade with  real money, dont use any EA that relies on global variables.

Store all your data in files folder if you dont want to loose your data
 
i can also confirm that GVs and both mt4/5 do different behaviours how you shut it down, whether that is pressing the x at top right corner of window OR clicking close under File menu, or using the windows shut down process. The last one is very dangerous on the later versions of windows... and can screw up all settings and templates and charts on all your terminals when not shutting down correctly, including restart. I think the moderators need to try these out so that they can teach themselves something.