Download MetaTrader 5
To add comments, please log in or register
Do you have questions on how to turn your idea into reality? Ask them on the Forum!
MisterDog
380
MisterDog 2014.04.28 01:19 

I can't retrieved a Global Variable in an EA. First I am setting a Global Variable with a script. Then I am attempting to read the Global Variable in an EA. Here is the code and errors. What is wrong?

script...

int start()
{
   int testVar;
   GlobalVariableSet(testVar, 12345);     // set the global variable
   int xyz = GlobalVariableGet(testVar);  // get the global variable just as a test
   Print("Script: ",xyz);                 // prints: "Script: 12345"
   return;
}

EA...

      int abc = GlobalVariableGet(testVar);  // get variable
      Print("Error: ",GetLastError());       // prints, "Error: 4058". global variable not found
      Print("Result: ",abc);                 // prints, "Result: 0"
Keith Watford
Moderator
8016
Keith Watford 2014.04.28 01:40  
Do you have another expert running that deletes GVs?
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.28 01:46  

Most probably is like that.


@ MisterDog

After setting up a Global Variable with a script, open GV inside terminal and see if the GV is set or not.

You track and do troubleshooting first.

MisterDog
380
MisterDog 2014.04.28 02:01  

This is the first time I've looked at a global variable in the terminal. I found it by pressing F3. Yes -- the value of "12345" is there.

And guess what I found out. The EA has to be loaded and running for this to work! Somewhere in the process the EA got unloaded. Thanks for the education everyone.

Alain Verleyen
Moderator
28701
Alain Verleyen 2014.04.28 06:52  
MisterDog:

This is the first time I've looked at a global variable in the terminal. I found it by pressing F3. Yes -- the value of "12345" is there.

And guess what I found out. The EA has to be loaded and running for this to work! Somewhere in the process the EA got unloaded. Thanks for the education everyone.

The first parameter if GlobalVariableSet/Get is a string, it's probably better to not use an int.
/
To add comments, please log in or register