GlobalVariableName

Gibt den Wert der globalen Variable nach der Ordnungsnummer zurück.

string  GlobalVariableName(
   int  index      // Nummer in der Liste der globalen Variablen 
   );

Parameter

index

[in]  Ordnungsnummer in der Liste der globalen Variablen  Muss groesser als oder 0 sein und weniger als GlobalVariablesTotal() .

Rückgabewert

Name der globalen Variable nach der Ordnungsnummer in der Liste der globalen Variablen. Fur die Erhaltung der fehlerbezogenen Information muss die Funtion GetLastError() aufgerufen werden .

Hinweis

Globale Variablen existieren im Client-Terminal innerhalb von 4 Wochen seit dem lezten Zugriff, danach werden sie automatisch entfernt.

 

Beispiel:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   GV_NAME    "TestGlobalVariableSet"
//+------------------------------------------------------------------+
//| Skript Programm Start Funktion                                   |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- Zunächst erstellen wir die globalen Variablen
   for(int i=0i<21i++)
      GlobalVariableSet(GV_NAME+string(i),i);
//--- Abrufen der Anzahl der globalen Variablen des Client-Terminals und deren Namen in einer Schleife anzeigen
   int total=GlobalVariablesTotal();
   for(int i=total-1i>=0i--)
     {
      string name=GlobalVariableName(i);
      if(GetLastError()!=0)
        {
         PrintFormat("Error %d occurred while getting global variable name at index %d"GetLastError(), i);
         ResetLastError();
         continue;
        }
      PrintFormat("GlobalVariableName(%02d) = \"%s\""iname);
     }
//--- aufräumen
   GlobalVariablesDeleteAll(GV_NAME);
   /*
   Ergebnis:
   GlobalVariableName(20) = "TestGlobalVariableSet9"
   GlobalVariableName(19) = "TestGlobalVariableSet8"
   GlobalVariableName(18) = "TestGlobalVariableSet7"
   GlobalVariableName(17) = "TestGlobalVariableSet6"
   GlobalVariableName(16) = "TestGlobalVariableSet5"
   GlobalVariableName(15) = "TestGlobalVariableSet4"
   GlobalVariableName(14) = "TestGlobalVariableSet3"
   GlobalVariableName(13) = "TestGlobalVariableSet20"
   GlobalVariableName(12) = "TestGlobalVariableSet2"
   GlobalVariableName(11) = "TestGlobalVariableSet19"
   GlobalVariableName(10) = "TestGlobalVariableSet18"
   GlobalVariableName(09) = "TestGlobalVariableSet17"
   GlobalVariableName(08) = "TestGlobalVariableSet16"
   GlobalVariableName(07) = "TestGlobalVariableSet15"
   GlobalVariableName(06) = "TestGlobalVariableSet14"
   GlobalVariableName(05) = "TestGlobalVariableSet13"
   GlobalVariableName(04) = "TestGlobalVariableSet12"
   GlobalVariableName(03) = "TestGlobalVariableSet11"
   GlobalVariableName(02) = "TestGlobalVariableSet10"
   GlobalVariableName(01) = "TestGlobalVariableSet1"
   GlobalVariableName(00) = "TestGlobalVariableSet0"
   */
  }