Read var from another EA.. ?!

 
Read var from another EA.. ?!

Sometimes, I use short scrips to activate special operations while trading. To do that I need to get some values of the variables (some are 'extern vars ') that are used in my main expert.

What is the recommended way to do that?

Thank you,

James
 
If you want to read values of a variable from another ea then you'll need to use the GlobalVariableSet(). Write the Variable to File, then read the file is another option for you.
 
ubzen :
If you want to read values of a variable from another ea then you'll need to use the GlobalVariableSet(). Write the Variable to File, then read the file is another option for you.

How can I define the type of the global variable ?!
it seems that when I use the function, GlobalVariableSet() it always defines as double.

Example: GlobalVariableSet("G_Longrange",Longrange);
defines "G_Longrange" as double in spite of it being Boolean.

Alert (" Longrange= ", Longrange+0.2 ); gives: 1.2

Thank you,

James
 
JJF :

it seems that when I use the function, GlobalVariableSet() it always defines as double.

defines "G_Longrange" as double in spite of it being Boolean.

RTFM it is always a double.

That means the GV value can be bool, int, double or datetime. RTFM bools, ints, doubles, or datetimes are trival conversions (assignments)

That means the GV name is a string

What more do you want?



 
JJF :

How can I define the type of the global variable ?!
it seems that when I use the function, GlobalVariableSet() it always defines as double.

Example: GlobalVariableSet("G_Longrange",Longrange);
defines "G_Longrange" as double in spite of it being Boolean.

Alert (" Longrange= ", Longrange+0.2 ); gives: 1.2

Thank you,

James

The GVS was designed that way because it needs to be flexible. Usually I don't have a problem with it. If I know the variable is bool, I would not add floating values upon it [ but thats just me ]. Anyways, I don't use GlobalVariable's directly. I would define an actual bool_local_variable which would get the values for the gv at the beginning of start(). Also there would be another function which set all my local_variables to gv at the end of the start function. I do this because I don't like working with long variable_name/functions and it's just a matter of preference. However, in your case, it might serve to add another level of error_checking which you seem to desire.

Ps: if Longrange is a bool. Then Longrange+0.2 turning into 1.2 could be the effect of TypeCasting. This is a different matter altogether.