Global variable value issue

To add comments, please log in or register
fftremblay
247
fftremblay  

Hi,

I have a small problem. I'm trying to work with global variables.

I have a GV set by an expert. This GV = 50 (the right value appears in the Global Variables when I go to the tools - global variables menu).

When I call this GV with an another expert, the expert is importing the following value : 1255033797.00000000.

Why is that ?

Thanks


Taskin Osman
778
Taskin Osman  
GV cannot be shared between experts. You need third party tools like http://www.fx1.net/permvar.php to store variables. this tool can help you to store variables in registry. you can read and write simultan. variables even saved after reboot.
fftremblay
247
fftremblay  
In that case, I don't understand this sentence : "Global variables of the client terminal are accessible simultaneously from all MQL4 programs launched in the client terminal."
Taskin Osman
778
Taskin Osman  
"

Global variables are defined at the same level as functions, i.e. they are not local in any block.

Example:

int GlobalFlag=10;   // global variable
int start()
  {
   ...
  }

Scope of global variables is the entire program. Global variables are accessible from all functions defined in the program. They are initialized with zero if no other initial value is explicitly defined.

I assume program is the strategy or indicator and not terminal. Global is simply word for global among all functions inside same study



Nikolay Panev
1174
Nikolay Panev  
fftremblay:
In that case, I don't understand this sentence : "Global variables of the client terminal are accessible simultaneously from all MQL4 programs launched in the client terminal."

Maybe you should use GlobalVariableGet() and GlobalVariableSet() functions. Check documentation.

https://docs.mql4.com/globals

Taskin Osman
778
Taskin Osman  

Seems global variables dont support strings. In case you want try permvar here is sample script;



#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#import "permvar.dll"
   string PVVersion();
   int PVInit(string);
   int PVError();
   int PVString(int,string,string);
   int PVValue(int,string,int);
   int PVDouble(int,string,double);
   int PVWipe(string);
   string PVGetString(int,string);
   int PVGetValue(int,string);
   double PVGetDouble(int,string);
   int PVRelease();
   int UnixTime();
#import

int start()
  {
   Print("Permvar Version : ",PVVersion());
   // lets init
   int hnd = PVInit("mt4");   
   if (hnd>0)
      {
      // Store
      PVValue(hnd,"myA",5);
      PVValue(hnd,"myB",21);
      PVValue(hnd,"StoreTime",UnixTime());
      
      // Read
      Print ("Reading variables from ",PVGetValue(hnd,"StoreTime"));
      Print ("Value of myA = ",PVGetValue(hnd,"myA"));
      Print ("Value of myB = ",PVGetValue(hnd,"myB"));
      Print ("myA + myB = ",PVGetValue(hnd,"myA") * PVGetValue(hnd,"myB"));
      }
   return(0);
  }
  
fftremblay
247
fftremblay  

Sorry - I didn't express myself clearly.

I have a GV set by an expert via the function . This GV = 50 (the right value appears in the Global Variables when I go to the tools - global variables menu).

When I call this GV with an another expert via the function GlobalVariableGet, the expert is importing the following value : 1255033797.00000000.

Why is that ?

Thanks

cloudbreaker
1574
cloudbreaker  

Can you show please the code snippets from both EAs.

Looks like perhaps you're getting a datetime in there.

You sure you're issuing a GlobalVariableGet() - the reason I ask is that GlobalVariableSet returns a datetime.


CB

fftremblay
247
fftremblay  
cloudbreaker:

Can you show please the code snippets from both EAs.

Looks like perhaps you're getting a datetime in there.

You sure you're issuing a GlobalVariableGet() - the reason I ask is that GlobalVariableSet returns a datetime.


CB


Thanks for the help. You were right.

I was copy-pasting my code when I saw my error : the GlobalVariableGet function was in fact a Set one. That's why I got this error.

procomK
12
procomK  
Taskin Osman:

Seems global variables dont support strings. In case you want try permvar here is sample script;




Hi.

How do I properly call the permvar.dll for MetaTrader 5 _64 (mql5) ?
Thanks.
To add comments, please log in or register