diff --git a/MtApi5/Mt5CommandType.cs b/MtApi5/Mt5CommandType.cs
index 6174e005..2fe7948d 100755
--- a/MtApi5/Mt5CommandType.cs
+++ b/MtApi5/Mt5CommandType.cs
@@ -235,6 +235,19 @@ namespace MtApi5
Print = 68,
ResetLastError = 143,
SendNotification = 144, //TODO
- SendMail = 145 //TODO
+ SendMail = 145, //TODO
+
+ //Global Variables
+ GlobalVariableCheck = 146,
+ GlobalVariableTime = 147,
+ GlobalVariableDel = 148,
+ GlobalVariableGet = 149,
+ GlobalVariableName = 150,
+ GlobalVariableSet = 151,
+ GlobalVariablesFlush = 152,
+ GlobalVariableTemp = 154,
+ GlobalVariableSetOnCondition = 156,
+ GlobalVariablesDeleteAll = 157,
+ GlobalVariablesTotal = 158
}
}
diff --git a/MtApi5/MtApi5Client.cs b/MtApi5/MtApi5Client.cs
index 6bc71b64..0b481426 100755
--- a/MtApi5/MtApi5Client.cs
+++ b/MtApi5/MtApi5Client.cs
@@ -2894,6 +2894,123 @@ namespace MtApi5
#endregion
+ #region Global Variables
+
+ ///
+ ///Checks the existence of a global variable with the specified name.
+ ///
+ /// Global variable name.
+ public bool GlobalVariableCheck(string name)
+ {
+ var commandParameters = new ArrayList { name };
+ return SendCommand(Mt5CommandType.GlobalVariableCheck, commandParameters);
+ }
+
+ ///
+ ///Returns the time when the global variable was last accessed.
+ ///
+ /// Name of the global variable.
+ public DateTime GlobalVariableTime(string name)
+ {
+ var commandParameters = new ArrayList { name };
+ var res = SendCommand(Mt5CommandType.GlobalVariableTime, commandParameters);
+ return Mt5TimeConverter.ConvertFromMtTime(res);
+ }
+
+ ///
+ ///Deletes a global variable from the client terminal.
+ ///
+ /// Name of the global variable.
+ public bool GlobalVariableDel(string name)
+ {
+ var commandParameters = new ArrayList { name };
+ return SendCommand(Mt5CommandType.GlobalVariableDel, commandParameters);
+ }
+
+ ///
+ ///Returns the value of an existing global variable of the client terminal.
+ ///
+ /// Global variable name.
+ public double GlobalVariableGet(string name)
+ {
+ var commandParameters = new ArrayList { name };
+ return SendCommand(Mt5CommandType.GlobalVariableGet, commandParameters);
+ }
+
+ ///
+ ///Returns the name of a global variable by its ordinal number.
+ ///
+ /// Sequence number in the list of global variables. It should be greater than or equal to 0 and less than GlobalVariablesTotal().
+ public string GlobalVariableName(int index)
+ {
+ var commandParameters = new ArrayList { index };
+ return SendCommand(Mt5CommandType.GlobalVariableName, commandParameters);
+ }
+
+ ///
+ ///Sets a new value for a global variable. If the variable does not exist, the system creates a new global variable.
+ ///
+ /// Global variable name.
+ /// The new numerical value.
+ public DateTime GlobalVariableSet(string name, double value)
+ {
+ var commandParameters = new ArrayList { name, value };
+ var res = SendCommand(Mt5CommandType.GlobalVariableSet, commandParameters);
+ return Mt5TimeConverter.ConvertFromMtTime(res);
+ }
+
+ ///
+ ///Forcibly saves contents of all global variables to a disk.
+ ///
+ public void GlobalVariablesFlush()
+ {
+ SendCommand(Mt5CommandType.GlobalVariablesFlush, null);
+ }
+
+ ///
+ ///The function attempts to create a temporary global variable. If the variable doesn't exist, the system creates a new temporary global variable.
+ ///
+ /// The name of a temporary global variable.
+ public bool GlobalVariableTemp(string name)
+ {
+ var commandParameters = new ArrayList { name };
+ return SendCommand(Mt5CommandType.GlobalVariableTemp, commandParameters);
+ }
+
+ ///
+ ///Sets the new value of the existing global variable if the current value equals to the third parameter check_value. If there is no global variable, the function will generate an error ERR_GLOBALVARIABLE_NOT_FOUND (4501) and return false.
+ ///
+ /// The name of a global variable.
+ /// New value.
+ /// The value to check the current value of the global variable.
+ public bool GlobalVariableSetOnCondition(string name, double value, double checkValue)
+ {
+ var commandParameters = new ArrayList { name, value, checkValue };
+ return SendCommand(Mt5CommandType.GlobalVariableSetOnCondition, commandParameters);
+ }
+
+ ///
+ ///Deletes global variables of the client terminal.
+ ///
+ /// Name prefix global variables to remove. If you specify a prefix NULL or empty string, then all variables that meet the data criterion will be deleted.
+ /// Date to select global variables by the time of their last modification. The function removes global variables, which were changed before this date. If the parameter is zero, then all variables that meet the first criterion (prefix) are deleted.
+ public int GlobalVariablesDeleteAll(string prefixName = "", DateTime? limitData = null)
+ {
+ if (prefixName == null)
+ prefixName = "";
+ var commandParameters = new ArrayList { prefixName, Mt5TimeConverter.ConvertToMtTime(limitData) };
+ return SendCommand(Mt5CommandType.GlobalVariablesDeleteAll, commandParameters);
+ }
+
+ ///
+ ///Returns the total number of global variables of the client terminal.
+ ///
+ public int GlobalVariablesTotal()
+ {
+ return SendCommand(Mt5CommandType.GlobalVariablesTotal, null);
+ }
+ #endregion
+
#endregion // Public Methods
#region Properties
diff --git a/TestClients/MtApi5TestClient/MainWindow.xaml b/TestClients/MtApi5TestClient/MainWindow.xaml
index d4c904b5..5a280a7f 100755
--- a/TestClients/MtApi5TestClient/MainWindow.xaml
+++ b/TestClients/MtApi5TestClient/MainWindow.xaml
@@ -586,6 +586,42 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TestClients/MtApi5TestClient/ViewModel.cs b/TestClients/MtApi5TestClient/ViewModel.cs
index 870f43cf..01180a6d 100755
--- a/TestClients/MtApi5TestClient/ViewModel.cs
+++ b/TestClients/MtApi5TestClient/ViewModel.cs
@@ -108,6 +108,18 @@ namespace MtApi5TestClient
public DelegateCommand TimeTradeServerCommand { get; private set; }
public DelegateCommand TimeLocalCommand { get; private set; }
public DelegateCommand TimeGMTCommand { get; private set; }
+
+ public DelegateCommand GlobalVariableCheckCommand { get; private set; }
+ public DelegateCommand GlobalVariableTimeCommand { get; private set; }
+ public DelegateCommand GlobalVariableDelCommand { get; private set; }
+ public DelegateCommand GlobalVariableGetCommand { get; private set; }
+ public DelegateCommand GlobalVariableNameCommand { get; private set; }
+ public DelegateCommand GlobalVariableSetCommand { get; private set; }
+ public DelegateCommand GlobalVariablesFlushCommand { get; private set; }
+ public DelegateCommand GlobalVariableTempCommand { get; private set; }
+ public DelegateCommand GlobalVariableSetOnConditionCommand { get; private set; }
+ public DelegateCommand GlobalVariablesDeleteAllCommand { get; private set; }
+ public DelegateCommand GlobalVariablesTotalCommand { get; private set; }
#endregion
#region Properties
@@ -229,6 +241,28 @@ namespace MtApi5TestClient
OnPropertyChanged("ChartFunctionsChartIdValue");
}
}
+
+ private string _globalVarName;
+ public string GlobalVarName
+ {
+ get { return _globalVarName; }
+ set
+ {
+ _globalVarName = value;
+ OnPropertyChanged("GlobalVarName");
+ }
+ }
+
+ private double _globalVarValue;
+ public double GlobalVarValue
+ {
+ get { return _globalVarValue; }
+ set
+ {
+ _globalVarValue = value;
+ OnPropertyChanged("GlobalVarValue");
+ }
+ }
#endregion
#region Public Methods
@@ -365,6 +399,18 @@ namespace MtApi5TestClient
TimeTradeServerCommand = new DelegateCommand(ExecuteTimeTradeServer);
TimeLocalCommand = new DelegateCommand(ExecuteTimeLocal);
TimeGMTCommand = new DelegateCommand(ExecuteTimeGMT);
+
+ GlobalVariableCheckCommand = new DelegateCommand(ExecuteGlobalVariableCheck);
+ GlobalVariableTimeCommand = new DelegateCommand(ExecuteGlobalVariableTime);
+ GlobalVariableDelCommand = new DelegateCommand(ExecuteGlobalVariableDel);
+ GlobalVariableGetCommand = new DelegateCommand(ExecuteGlobalVariableGet);
+ GlobalVariableNameCommand = new DelegateCommand(ExecuteGlobalVariableName);
+ GlobalVariableSetCommand = new DelegateCommand(ExecuteGlobalVariableSet);
+ GlobalVariablesFlushCommand = new DelegateCommand(ExecuteGlobalVariablesFlush);
+ GlobalVariableTempCommand = new DelegateCommand(ExecuteGlobalVariableTemp);
+ GlobalVariableSetOnConditionCommand = new DelegateCommand(ExecuteGlobalVariableSetOnCondition);
+ GlobalVariablesDeleteAllCommand = new DelegateCommand(ExecuteGlobalVariablesDeleteAll);
+ GlobalVariablesTotalCommand = new DelegateCommand(ExecuteGlobalVariablesTotal);
}
private bool CanExecuteConnect(object o)
@@ -1115,6 +1161,86 @@ namespace MtApi5TestClient
AddLog($"TimeGMT: {retVal}");
}
+ #region Global Variable Commands
+ private async void ExecuteGlobalVariableCheck(object obj)
+ {
+ var name = GlobalVarName;
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableCheck(name));
+ AddLog($"GlobalVariableCheck: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariableTime(object obj)
+ {
+ var name = GlobalVarName;
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableTime(name));
+ AddLog($"GlobalVariableTime: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariableDel(object obj)
+ {
+ var name = GlobalVarName;
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableDel(name));
+ AddLog($"GlobalVariableDel: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariableGet(object obj)
+ {
+ var name = GlobalVarName;
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableGet(name));
+ GlobalVarValue = retVal;
+ AddLog($"GlobalVariableGet: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariableName(object obj)
+ {
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableName(0));
+ GlobalVarName = retVal;
+ AddLog($"GlobalVariableName: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariableSet(object obj)
+ {
+ var name = GlobalVarName;
+ var value = GlobalVarValue;
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableSet(name, value));
+ AddLog($"GlobalVariableSet: {retVal}");
+ }
+
+ private void ExecuteGlobalVariablesFlush(object obj)
+ {
+ _mtApiClient.GlobalVariablesFlush();
+ AddLog("GlobalVariablesFlush: executed.");
+ }
+
+ private async void ExecuteGlobalVariableTemp(object obj)
+ {
+ var name = GlobalVarName;
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableTemp(name));
+ AddLog($"GlobalVariableTemp: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariableSetOnCondition(object obj)
+ {
+ var name = GlobalVarName;
+ var value = GlobalVarValue;
+ const double checkValue = 2;
+ var retVal = await Execute(() => _mtApiClient.GlobalVariableSetOnCondition(name, value, checkValue));
+ AddLog($"GlobalVariableSetOnCondition: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariablesDeleteAll(object obj)
+ {
+ var retVal = await Execute(() => _mtApiClient.GlobalVariablesDeleteAll());
+ AddLog($"GlobalVariablesDeleteAll: {retVal}");
+ }
+
+ private async void ExecuteGlobalVariablesTotal(object obj)
+ {
+ var retVal = await Execute(() => _mtApiClient.GlobalVariablesTotal());
+ AddLog($"GlobalVariablesTotal: {retVal}");
+ }
+ #endregion
+
#region Chart Commands
private async void ExecuteChartOpen(object o)
{
diff --git a/mq5/MtApi5.ex5 b/mq5/MtApi5.ex5
index cee3a9de..c8ea16a0 100755
Binary files a/mq5/MtApi5.ex5 and b/mq5/MtApi5.ex5 differ
diff --git a/mq5/MtApi5.mq5 b/mq5/MtApi5.mq5
index d81a727a..96dfdad3 100644
--- a/mq5/MtApi5.mq5
+++ b/mq5/MtApi5.mq5
@@ -705,9 +705,42 @@ int executeCommand()
case 143: //ResetLastError
Execute_ResetLastError();
break;
+ case 146: //GlobalVariableCheck
+ Execute_GlobalVariableCheck();
+ break;
+ case 147: //GlobalVariableTime
+ Execute_GlobalVariableTime();
+ break;
+ case 148: //GlobalVariableDel
+ Execute_GlobalVariableDel();
+ break;
+ case 149: //GlobalVariableGet
+ Execute_GlobalVariableGet();
+ break;
+ case 150: //GlobalVariableName
+ Execute_GlobalVariableName();
+ break;
+ case 151: //GlobalVariableSet
+ Execute_GlobalVariableSet();
+ break;
+ case 152: //GlobalVariablesFlush
+ Execute_GlobalVariablesFlush();
+ break;
case 153: //TerminalInfoString
Execute_TerminalInfoString();
break;
+ case 154: //GlobalVariableTemp
+ Execute_GlobalVariableTemp();
+ break;
+ case 156: //GlobalVariableSetOnCondition
+ Execute_GlobalVariableSetOnCondition();
+ break;
+ case 157: //GlobalVariablesDeleteAll
+ Execute_GlobalVariablesDeleteAll();
+ break;
+ case 158: //GlobalVariablesTotal
+ Execute_GlobalVariablesTotal();
+ break;
case 204: //TerminalInfoInteger
Execute_TerminalInfoInteger();
break;
@@ -5659,6 +5692,114 @@ void Execute_ResetLastError()
SEND_VOID_RESPONSE
}
+void Execute_GlobalVariableCheck()
+{
+ string name;
+ StringInit(name, 500);
+
+ GET_STRING_VALUE(0, name, "name")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: name = %s", __FUNCTION__, name);
+#endif
+
+ bool res = GlobalVariableCheck(name);
+
+ SEND_BOOL_RESPONSE(res)
+}
+
+void Execute_GlobalVariableTime()
+{
+ string name;
+ StringInit(name, 500);
+
+ GET_STRING_VALUE(0, name, "name")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: name = %s", __FUNCTION__, name);
+#endif
+
+ datetime time = GlobalVariableTime(name);
+
+ SEND_INT_RESPONSE((int)time)
+}
+
+void Execute_GlobalVariableDel()
+{
+ string name;
+ StringInit(name, 500);
+
+ GET_STRING_VALUE(0, name, "name")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: name = %s", __FUNCTION__, name);
+#endif
+
+ bool res = GlobalVariableDel(name);
+
+ SEND_BOOL_RESPONSE(res)
+}
+
+void Execute_GlobalVariableGet()
+{
+ string name;
+ StringInit(name, 500);
+
+ GET_STRING_VALUE(0, name, "name")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: name = %s", __FUNCTION__, name);
+#endif
+
+ double res = GlobalVariableGet(name);
+
+ SEND_DOUBLE_RESPONSE(res)
+}
+
+void Execute_GlobalVariableName()
+{
+ int index;
+
+ GET_INT_VALUE(0, index, "index")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: index = %d", __FUNCTION__, index);
+#endif
+
+ string name = GlobalVariableName(index);
+
+ SEND_STRING_RESPONSE(name)
+}
+
+void Execute_GlobalVariableSet()
+{
+ string name;
+ double value;
+ StringInit(name, 500);
+
+ GET_STRING_VALUE(0, name, "name")
+ GET_DOUBLE_VALUE(1, value, "value")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: name = %s, value = %f", __FUNCTION__, name, value);
+#endif
+
+ datetime res = GlobalVariableSet(name, value);
+
+ SEND_INT_RESPONSE((int)res)
+}
+
+void Execute_GlobalVariablesFlush()
+{
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: called.", __FUNCTION__);
+#endif
+
+ GlobalVariablesFlush();
+
+ SEND_VOID_RESPONSE
+}
+
void Execute_ChartOpen()
{
string symbol;
@@ -6247,6 +6388,79 @@ void Execute_TerminalInfoString()
}
}
+void Execute_GlobalVariableTemp()
+{
+ string name;
+ StringInit(name, 500);
+
+ GET_STRING_VALUE(0, name, "name")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: name = %s", __FUNCTION__, name);
+#endif
+
+ bool res = GlobalVariableTemp(name);
+
+ SEND_BOOL_RESPONSE(res)
+}
+
+void Execute_GlobalVariableSetOnCondition()
+{
+ string name;
+ double value;
+ double check_value;
+ StringInit(name, 500);
+
+ GET_STRING_VALUE(0, name, "name")
+ GET_DOUBLE_VALUE(1, value, "value")
+ GET_DOUBLE_VALUE(2, check_value, "check_value")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: name = %s, value = %f, check_value = %f", __FUNCTION__, name, value, check_value);
+#endif
+
+ bool res = GlobalVariableSetOnCondition(name, value, check_value);
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: result = %s", __FUNCTION__, BoolToString(res));
+#endif
+
+ SEND_BOOL_RESPONSE(res)
+}
+
+void Execute_GlobalVariablesDeleteAll()
+{
+ string prefix_name;
+ int limit_data;
+ StringInit(prefix_name, 500);
+
+ GET_STRING_VALUE(0, prefix_name, "prefix_name")
+ GET_INT_VALUE(1, limit_data, "limit_data")
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: prefix_name = %s, limit_data = %d", __FUNCTION__, prefix_name, limit_data);
+#endif
+
+ int res = GlobalVariablesDeleteAll(prefix_name, (datetime)limit_data);
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: result = %d", __FUNCTION__, res);
+#endif
+
+ SEND_INT_RESPONSE(res)
+}
+
+void Execute_GlobalVariablesTotal()
+{
+ int res = GlobalVariablesTotal();
+
+#ifdef __DEBUG_LOG__
+ PrintFormat("%s: result = %d", __FUNCTION__, res);
+#endif
+
+ SEND_INT_RESPONSE(res)
+}
+
void Execute_TerminalInfoInteger()
{
int propertyId;