store bool in global variable

 

hi all


how can i store a bool in global variable?


thanks

 
well... store it as a double : 1.00 or 0.00
 

so if i retrieve it from globalvariableget


would it still read true or false?

 

just think of 1 as true, 0 as false.


Can int and bool not be stored as global variables?

If bool cannot be, int would be better, if int cannot be then the double solution will work.

 
fxCal:

just think of 1 as true, 0 as false.


Can int and bool not be stored as global variables?

If bool cannot be, int would be better, if int cannot be then the double solution will work.


This is the published syntax for setting a global variable:

datetime GlobalVariableSet( string name, double value)
  Sets a new value of the global variable. If it does not exist, the system creates a new global variable. If the function succeeds, the returned value will be the last access time. Otherwise, the returned value will be 0. To get the detailed error information, one has to call the GetLastError() function

Nothing about bool or int values per se.  But, this should not be a problem... a double is easily converted to an integer.  A boolean value can be represented by a 1.0 or 2.0, as has been already said.  However, you can get into trouble by setting one of the values to be interpreted as 0 because that is the error state of theGlobalVariableSet command.  I have made this mistake myself when learning MQL4, so be careful of the off the cuff advice given by those with more experience!!!  Sometimes we lead newbies into trouble without realizing it!

One other interesting possibility is to set a named global variable... where the value doesn't matter.  When the global variable is set, or exists, then that could be logical 1.  Then delete the global variable to represent 0.  Use GlobalVariableCheck to check for the existence of the global variable.  Actually I like and use this method myself, because it is not dependent on the value of the global variable, just whether it exists or not.  Just an idea.

Good luck!

Reason: