Error in working with global variables

 
Hello dear developers.

I ran into a problem when the customer's global variables are automatically deleted after restarting the terminal. Because of this, the adviser does not work correctly.
But I do not have such an error, and I have not encountered this before.
At the same time, we have the same build of the MT5 terminal - 3677.
The only difference is that I have Windows and the customer has MacOS.

The code below gives different results after restarting the terminal for me and for the customer.
I have the values 1 and 1, since the global variable has retained its value, and the customer has 0 and 1, since it was deleted.
There is nothing in OnDeinit and OnTick.

I can't understand why the same code works differently in the MT5 terminal.

Thanks in advance for any help.


int OnInit()
{
   string name = "GV_Flag";
   Print(GlobalVariableGet(name));
   
   GlobalVariableSet(name, 1);
   Print(GlobalVariableGet(name));
   
   return(INIT_SUCCEEDED);
}
 
Tatiana Zyrianova: I ran into a problem when the customer's global variables are automatically deleted after restarting the terminal.

Wrong. Your code is deleting them, or you are not properly shutting down the terminal. It can take thirty (30) seconds after the window closes, before all files are written and the terminal exits if you have dozens of open charts.

 
William Roeder #:

Wrong. Your code is deleting them, or you are not properly shutting down the terminal. It can take thirty (30) seconds after the window closes, before all files are written and the terminal exits if you have dozens of open charts.

My code does not remove global variables because it does not contain the GlobalVariableDel function. As I wrote above, with the same code, my global variable is saved after restarting the terminal, but the customer does not.

Regarding the incorrect closing of the terminal, I do not quite understand what you mean. Could you explain this in more detail please?

 
Tatiana Zyrianova: I ran into a problem when the customer's global variables are automatically deleted after restarting the terminal. Because of this, the adviser does not work correctly.
But I do not have such an error, and I have not encountered this before. At the same time, we have the same build of the MT5 terminal - 3677. The only difference is that I have Windows and the customer has MacOS.
The code below gives different results after restarting the terminal for me and for the customer. I have the values 1 and 1, since the global variable has retained its value, and the customer has 0 and 1, since it was deleted.
There is nothing in OnDeinit and OnTick. I can't understand why the same code works differently in the MT5 terminal. Thanks in advance for any help.
  1. There is a possibility that the file that holds the Global Terminal Variables may be corrupted. Try closing the terminal then deleting that file "<data folder>/Bases/gvariables.dat" and then recreating all the variables again.
  2. When you change a Global Terminal Variable, remember to flush the content to the file with GlobalVariablesFlush. This prevents possible data loss if the terminal is closed unexpectedly.
  3. As for the Windows vs Mac difference, I don't have any experience with a Mac, so there could be another possible reason, but try the previous two points to see if it resolves the issue.
 
Tatiana Zyrianova:
Hello dear developers.

I ran into a problem when the customer's global variables are automatically deleted after restarting the terminal. Because of this, the adviser does not work correctly.
But I do not have such an error, and I have not encountered this before.
At the same time, we have the same build of the MT5 terminal - 3677.
The only difference is that I have Windows and the customer has MacOS.

The code below gives different results after restarting the terminal for me and for the customer.
I have the values 1 and 1, since the global variable has retained its value, and the customer has 0 and 1, since it was deleted.
There is nothing in OnDeinit and OnTick.

I can't understand why the same code works differently in the MT5 terminal.

Thanks in advance for any help.


So I tried your code on a Mac. The first run gives 0 and 1, normal. And after I restarted MT5 it gives 1 and 1. So all seems ok.

As suggested by others, most probably your customer didn't close the platform correctly and the GVT was not saved, flush them regularly or each time it's important to not lose a value.

 

Thank you so much for your help, your advice helped me.

Now everything works as it should.

Reason: