#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_NAME, GV_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_NAME, 0))
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_NAME, GV_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_NAME, dvalue))
{
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", dvalue, lvalue);
//--- 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_name, const double value)
{
if(GlobalVariableSet(gv_name, value)==0)
{
Print("GlobalVariableSet() failed. Error ",GetLastError());
return(false);
}
return(true);
}
|