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 @@ + + + + + + + + + + + + + + + + + + + + + + +