Global Variables Lost on Window 10 PC Update?

 

I set up a live testing of my strategies with the use of MT5 Global Variables few days ago. There was an update of Window 10 on the weekend and the terminals were forcibly closed.

I opened the terminals again today and found that all the Global Variables disappeared. Aren't Global Variables designed to preserve value even when the terminal was closed?

How to prevent the Global Variables from disappearing in this scenario? 

 
JrDevil:

I set up a live testing of my strategies with the use of MT5 Global Variables few days ago. There was an update of Window 10 on the weekend and the terminals were forcibly closed.

I opened the terminals again today and found that all the Global Variables disappeared. Aren't Global Variables designed to preserve value even when the terminal was closed?

How to prevent the Global Variables from disappearing in this scenario? 

Global variables are a solution if you "flush" them to disk (either on every update to the variables or on a regular basis). If you don't "flush" them, and the terminal "crashes" or is "abnormally closed", then the variables are not saved properly. So, modify your code to properly flush them to disk with the GlobalVariableFlush() function.

The following Article may also be of interest to you: MQL5 Programming Basics: Global Variables of the Terminal

In this case, read the section specifically on the GlobalVariablesFlush function and I quote:

In case of the terminal's emergency shutdown, the global variables may be lost. The GlobalVariableFlush() function helps you to avoid this. The function forcibly saves the global variables. After the values are set by the GlobalVariableSet() function or the variables are deleted, simply call the GlobalVariableFlush() function.

 
Fernando Carreiro:

Global variables are a solution if you "flush" them to disk (either on every update to the variables or on a regular basis). If you don't "flush" them, and the terminal "crashes" or is "abnormally closed", then the variables are not saved properly. So, modify your code to properly flush them to disk with the GlobalVariableFlush() function.

The following Article may also be of interest to you: MQL5 Programming Basics: Global Variables of the Terminal

In this case, read the section specifically on the GlobalVariablesFlush function and I quote:

So, if we don't flush the Global Variables, they will never be saved to the disk? Even when a day has passed?

Also, will flushing all the Global Variables regularly significantly slow down the overall operation?

Thank you.

 
JrDevil:

So, if we don't flush the Global Variables, they will never be saved to the disk? Even when a day has passed?

Also, will flushing all the Global Variables regularly significantly slow down the overall operation?

Thank you.

  1. If you don't "flush", the variables will be cached in memory and only saved when you exit the application properly.
  2. If you "flush", there could technically be a slight delay, but the file is so small and compact that I have never detected any "practical" delay or anything problematic with its use.
 
Fernando Carreiro:
  1. If you don't "flush", the variables will be cached in memory and only saved when you exit the application properly.
  2. ...

By application I suppose you mean the terminal ?

If yes, are you sure the GV are only saved when the terminal is closed ? Is it documented somewhere ?

All I found in documentation is :

The terminal writes all the global variables when the work is over

Which is a bit cryptic.

 
And irrelevant. If a power fails, or OS crashes, changes to the GVs will not be written to disk, and that can happen one microsecond after you modify the variables.
 
Alain Verleyen:

By application I suppose you mean the terminal ?

If yes, are you sure the GV are only saved when the terminal is closed ? Is it documented somewhere ?

All I found in documentation is :

Which is a bit cryptic.

I am refering to my experiences. The terminal application may "flush" on other occasions too, but I noticed that it is not very often. However, if one actively flushes the data then the problem is solved.
 
Fernando Carreiro:
I am refering to my experiences. The terminal application may "flush" on other occasions too, but I noticed that it is not very often. However, if one actively flushes the data then the problem is solved.

Thank you so much!