GlobalVariableName

Rend le nom de la variable globale selon le numéro d'ordre.

string  GlobalVariableName(
   int  index      // numéro dans le répertoire des variables globales
   );

Paramètres

index

[in]  Le numéro d'ordre dans le répertoire des variables globales. Doit être plus ou égal à 0 et moins que GlobalVariablesTotal().

La valeur rendue

Le nom de la variable globale selon le numéro d'ordre dans la liste des variables globales.Pour recevoir l'information sur l'erreur, il est nécessaire d'appeler la fonction GetLastError().

Note

Les variables globales existent dans le terminal de client les 4 semaines dès le moment du dernier appel, après cela elles se suppriment automatiquement.

 

Exemple :

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   GV_NAME    "TestGlobalVariableSet"
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- créons d'abord les variables globales
   for(int i=0i<21i++)
      GlobalVariableSet(GV_NAME+string(i),i);
//--- récupère le nombre de variables globales du terminal client et affiche leurs noms en boucle
   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);
     }
//--- nettoyage
   GlobalVariablesDeleteAll(GV_NAME);
   /*
   résultat :
   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"
S   GlobalVariableName(06) = "TestGlobalVariableSet14"
   GlobalVariableName(05) = "TestGlobalVariableSet13"
   GlobalVariableName(04) = "TestGlobalVariableSet12"
   GlobalVariableName(03) = "TestGlobalVariableSet11"
   GlobalVariableName(02) = "TestGlobalVariableSet10"
   GlobalVariableName(01) = "TestGlobalVariableSet1"
   GlobalVariableName(00) = "TestGlobalVariableSet0"
   */
  }