// You may want to prefix all global variable names with the EA name and testing mode.... // Also for testing you want code to delete all of the test ones ... whose name starts with globalId("") string globalId(string id) { string m = WindowExpertName()+"/"+IsTesting()+"/"+id+"/"; return (m); } datetime globalSet(string n,double d) { string id = globalId(n); datetime ret = GlobalVariableSet(id,d); return(ret); } double globalGet(string n) { string id = globalId(n); double d = GlobalVariableGet(id); return (d); }
Thanks ydrol, this is perfect. I had no idea there are special helpers for this purpose. One last issue remains - how to share a value accross sessions (if I do not want to persist to a file, that is) ...
They last for 28 days https://docs.mql4.com/globals if unaccessed. That might be enough...
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi MQLers,
please advise: within my EA I am using a variable which gets continuously updated based on how the market unfolds for that specific symbol. Given that of course I am going to have my EA run in multiple windows on multiple symbols, a question of concurrency arises. To use a live and typical example: in an ideal world variable XY gets updated within the EURUSD window and the USDJPY window is able to query this new value right afterwards. Where / how should such a variable be declared?
And - what are my options if I wanted that variable to keep its value in between sessions (e.g. during recompile or restart of the terminal)?
Thanks in advance,
Mac