MQL4参考 程序端全局变量 GlobalVariableSetOnCondition


Sets the new value of the existing global variable if the current value equals to the third parameter check_value. If there is no global variable, the function will generate an error ERR_GLOBALVARIABLE_NOT_FOUND (4501) and return false.

bool  GlobalVariableSetOnCondition(
   string  name,            // Global variable name
   double  value,           // New value for variable if condition is true
   double  check_value      // Check value condition



[in]  The name of a global variable.


[in]  New value.


[in]   The value to check the current value of the global variable.

Return Value

If successful, the function returns true, otherwise it returns false. For details about the error call GetLastError(). If the current value of the global variable is different from check_value, the function returns false.


Function provides atomic access to the global variable, so it can be used for providing of a mutex at interaction of several Expert Advisors working simultaneously within one client terminal.