Files
mql5-skills/skills/mql5/references/docs/22-globals/0866-globals-globalvariablecheck.md
T
2026-06-23 21:47:51 +08:00

56 lines
1.5 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# GlobalVariableCheck
Checks the existence of a global variable with the specified name
```
bool  GlobalVariableCheck(
   string  name      // Global variable name
   );
```
Parameters
name
[in]  Global variable name.
Return Value
Returns true, if the global variable exists, otherwise returns false.
Global variables exist in the client terminal during 4 weeks since their last use, then they are automatically deleted.
Example:
```
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   GV_NAME    "TestGlobalVariableCheck"
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- get the flag of the client terminal global variable named GV_NAME
   bool exist=GlobalVariableCheck(GV_NAME);
   PrintFormat("Terminal global variable named \"%s\" %s", GV_NAME, (exist ? "exists" : "does not exist"));
   
   /*
   result in the presence of a global variable:
   Terminal global variable named "TestGlobalVariableCheck" exists
   
   result in the absence of a global variable:
   Terminal global variable named "TestGlobalVariableCheck" does not exist
   */
  }
```
See also
[GlobalVariableTime()](/en/docs/globals/globalvariabletime)