GlobalVariableGet

Müşteri terminalinde mevcut bulunan bir global değişkenin değerine dönüş yapar. Fonksiyonun 2 çeşidi bulunmaktadır.

1. Global değişkenin değerine hemen dönüş yapar.

double  GlobalVariableGet(
   string  name      // Global değişkenin ismi
   );

 
2. Fonksiyonun başarı durumuna göre, 'true' veya 'false' değerine dönüş yapar.  Başarı durumunda müşteri terminalinin global değişkeni, ikinci parametreye referansla geçirilen bir değişkene yerleştirilir

bool  GlobalVariableGet(
   string  name,              // Global değişkenin ismi
   double& double_var         // Global değişkenin değerini içerecek olan değişken
   );

Parametreler

name

[in]  Global değişkenin ismi.

double_var

[out]  Global değişkende saklanan değeri alacak olan double tipi hedef değişkeni.

Dönüş değeri

Mevcut global değişkenin değeri veya hata durumunda 0 değeri. Hata ile ilgili daha detaylı bilgi almak için GetLastError() fonksiyonunu çağırın.

Not

Global değişkenler, son erişimlerinin ardından 4 hafta boyunca müşteri terminali tarafından saklanır, sonra otomatik olarak silinirler.

 

Örnek:

#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
 
#define   GV_NAME    "TestGlobalVariableGet"
#define   GV_VALUE   1.23
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- müşteri terminalinin GV_NAME adlı global değişkenine değer ayarla
   if(!GlobalVariableSetValue(GV_NAMEGV_VALUE))
      return;
     
//--- GV_NAME adlı müşteri terminali global değişkeninin reel değerini al
//--- GlobalVariableGet çağrısının ilk biçimi kullanıldığında, sıfır bir hata sinyali olduğundan,
//--- sonucu okurken son hata kodunu analiz etmek gerekir
   double dvalue=GlobalVariableGet(GV_NAME);
   if(dvalue==0 && GetLastError()!=0)
     {
      Print("GlobalVariableGet() failed. Error "GetLastError());
      return;
     }
//--- elde edilen sonucu göster
   PrintFormat("The first form of the GlobalVariableGet() function call returned the value %.2f"dvalue);
   
//--- müşteri terminalinin GV_NAME adlı global değişkenine sıfır değerini ayarla
   if(!GlobalVariableSetValue(GV_NAME0))
      return;
     
//--- çağrının ilk biçimini kullanarak GV_NAME adlı müşteri terminali global değişkeninin Boolean değerini al
   bool bvalue=GlobalVariableGet(GV_NAME);
   if(!bvalue && GetLastError()!=0)
     {
      Print("GlobalVariableGet() failed. Error "GetLastError());
      return;
     }
//--- elde edilen sonucu göster
   PrintFormat("The first form of the GlobalVariableGet() function call returned the value %.2f with type bool as %s"bvalue, (string)bvalue);
     
//--- müşteri terminalinin GV_NAME adlı global değişkenine sıfırdan farklı bir değer ayarla
   if(!GlobalVariableSetValue(GV_NAMEGV_VALUE*100.0))
      return;
   
//--- GV_NAME adlı müşteri terminali global değişkeninin Boolean değerini tekrar oku
   bvalue=GlobalVariableGet(GV_NAME);
   if(!bvalue && GetLastError()!=0)
     {
      Print("GlobalVariableGet() failed. Error "GetLastError());
      return;
     }
//--- elde edilen sonucu göster
   PrintFormat("The first form of the GlobalVariableGet() function call returned the value %.2f with type bool as %s"bvalue, (string)bvalue);
     
//--- GlobalVariableGet çağrısının ikinci biçimini kullanarak GV_NAME adlı müşteri terminali global değişkeninin reel değerini al
   if(!GlobalVariableGet(GV_NAMEdvalue))
     {
      Print("GlobalVariableGet() failed. Error "GetLastError());
      return;
     }
//--- elde edilen reel değeri long türünde bir tamsayıya dönüştür ve sonucu göster
   long lvalue=(long)dvalue;
   PrintFormat("The second form of the GlobalVariableGet() function call returned the value %.2f with type long as %I64d"dvaluelvalue);
   
//--- kullanımdan sonra GV_NAME adlı müşteri terminali global değişkenini sil
   if(!GlobalVariableDel(GV_NAME))
     {
      Print("GlobalVariableDel() failed. Error ",GetLastError());
     }
   
   /*
   sonuç:
   The first form of the GlobalVariableGet() function call returned the value 1.23
   The first form of the GlobalVariableGet() function call returned the value 0.00 with type bool as false
   The first form of the GlobalVariableGet() function call returned the value 1.00 with type bool as true
   The second form of the GlobalVariableGet() function call returned the value 123.00 with type long as 123
   */
  }
//+------------------------------------------------------------------+
//| Terminal global değişkenine değer ayarla;                        |
//| Eğer değişken yoksa, oluştur                                     |
//+------------------------------------------------------------------+
bool GlobalVariableSetValue(const string gv_nameconst double value)
  {
   if(GlobalVariableSet(gv_namevalue)==0)
     {
      Print("GlobalVariableSet() failed. Error ",GetLastError());
      return(false);
     }
   return(true);
  }