Global variable value issue

 

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


 
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.
 
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."
 
"

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



 
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

 

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);
  }
  
 

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

 

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

 
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.

 
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.