Global Variables in Hosted Environment.

To add comments, please log in or register
Wayside48
503
Wayside48  

I am using some Global Variables in my MT4 EA to store values which should be retained if, for example, the server re-boots.  In the OnInit() method, the existence of these is checked using GlobalVariableCheck() for each variable.  If not present, the variable is re-initialized, and a message is written to the log.

This all works fine when running on a local machine, but when migrated to an MQL5 Hosted server, the logs indicate that all of the Global Variables are always unknown.  The variables are being re-initialized every time I migrate even though the same variable names were present from the previous migration.

Is it that the migration process always clears the Global Variables, or is there something else possibly going wrong?  

William Roeder
22726
William Roeder  
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Are you calling flush to make sure they are written in case the VPS unexpectedly shuts down?
Wayside48
503
Wayside48  
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Are you calling flush to make sure they are written in case the VPS unexpectedly shuts down?

1.  Ok, we all make mistakes!  Thanks for replying anyway.

2.  No I'm not but as I understand it the GlobalVariablesFlush() method is only to force a premature saving of the variables?  They should still get saved periodically without that call, I believe.  Yet on re-migrating to the host, my Global Variables are apparently unknown even though the EA has been running for days.  I'll try sticking in a 'flush' and report back.  Maybe by then the question will be in the correct section ;-).

EDIT:  Nope, calling GlobalVariablesFlush() now but still when the EA is migrated (twice), GlobalVariablesCheck(varName) is returning false for all variables.  I can only conclude that migration causes the Global Variables to be cleared.

William Roeder
22726
William Roeder  
Wayside48: I can only conclude that migration causes the Global Variables to be cleared.

That is true

As I understand it from https://www.mql5.com/en/articles/994 Global variable values are NOT migrated from the terminal... Terminal global variables are not migrated to the virtual hosting. If you need to initialize lots of variables when starting a program, you can use reading from files that can be passed using the "#property tester_file" directive.
That is not your original question
Wayside48: store values which should be retained if, for example, the server re-boots.
Wayside48
503
Wayside48  
William Roeder:

That is true.

That is not your original question

1. Ah, that was my original question!  So, Global Variables on the hosted server are cleared on migration - thanks.

2. Indeed it was not, I was trying to be helpful answering someone else's question which did ask whether Global Variables were copied from the terminal to the hosted terminal - not my question at all.

To add comments, please log in or register