diff --git a/MtApi/MtApiClient.cs b/MtApi/MtApiClient.cs index 2065c0ed..d75cefb3 100755 --- a/MtApi/MtApiClient.cs +++ b/MtApi/MtApiClient.cs @@ -1780,6 +1780,409 @@ namespace MtApi var commandParameters = new ArrayList { chartId }; SendCommand(MtCommandType.ChartRedraw, commandParameters); } + + /// + ///Applies a specific template from a specified file to the chart. + /// + ///Chart ID. + ///The name of the file containing the template. + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartApplyTemplate(long chartId, string filename) + { + var commandParameters = new ArrayList { chartId, filename }; + return SendCommand(MtCommandType.ChartApplyTemplate, commandParameters); + } + + /// + ///Saves current chart settings in a template with a specified name. + /// + ///Chart ID. + ///The filename to save the template. The ".tpl" extension will be added to the filename automatically; there is no need to specify it. The template is saved in data_folder\templates\ and can be used for manual application in the terminal. If a template with the same filename already exists, the contents of this file will be overwritten. + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartSaveTemplate(long chartId, string filename) + { + var commandParameters = new ArrayList { chartId, filename }; + return SendCommand(MtCommandType.ChartSaveTemplate, commandParameters); + } + + /// + ///The function returns the number of a subwindow where an indicator is drawn. + /// + ///Chart ID. + ///Short name of the indicator. + /// + ///Subwindow number in case of success. In case of failure the function returns -1. + /// + public int ChartWindowFind(long chartId, string indicatorShortname) + { + var commandParameters = new ArrayList { chartId, indicatorShortname }; + return SendCommand(MtCommandType.ChartWindowFind, commandParameters); + } + + /// + ///The function returns the number of a subwindow where an indicator is drawn. + /// + ///Chart ID. + ///The number of the chart subwindow. 0 means the main chart window. + ///The time value on the chart, for which the value in pixels along the X axis will be received. + ///The price value on the chart, for which the value in pixels along the Y axis will be received. + ///The variable, into which the conversion of time to X will be received. The origin is in the upper left corner of the main chart window. + ///The variable, into which the conversion of price to Y will be received. The origin is in the upper left corner of the main chart window. + /// + ///Subwindow number in case of success. In case of failure the function returns -1. + /// + public bool ChartTimePriceToXY(long chartId, int subWindow, DateTime? time, double price, out int x, out int y) + { + var commandParameters = new ArrayList { chartId, subWindow, MtApiTimeConverter.ConvertToMtTime(time), price }; + var str = SendCommand(MtCommandType.ChartTimePriceToXY, commandParameters); + var res = false; + x = 0; + y = 0; + if (!string.IsNullOrEmpty(str) && str.Contains(";")) + { + var values = str.Split(';'); + if (values.Length > 1) + { + int.TryParse(values[0], out x); + int.TryParse(values[1], out y); + res = true; + } + } + return res; + } + + /// + ///The function returns the number of a subwindow where an indicator is drawn. + /// + ///Chart ID. + ///The variable, into which the conversion of time to X will be received. The origin is in the upper left corner of the main chart window. + ///The variable, into which the conversion of price to Y will be received. The origin is in the upper left corner of the main chart window. + ///The number of the chart subwindow. 0 means the main chart window. + ///The time value on the chart, for which the value in pixels along the X axis will be received. + ///The price value on the chart, for which the value in pixels along the Y axis will be received. + /// + ///Subwindow number in case of success. In case of failure the function returns -1. + /// + public bool ChartXYToTimePrice(long chartId, int x, int y, out int subWindow, out DateTime? time, out double price) + { + var commandParameters = new ArrayList { chartId, x, y }; + var str = SendCommand(MtCommandType.ChartXYToTimePrice, commandParameters); + var res = false; + subWindow = 0; + time = null; + price = double.NaN; + if (!string.IsNullOrEmpty(str) && str.Contains(";")) + { + var values = str.Split(';'); + if (values.Length > 2) + { + int.TryParse(values[0], out subWindow); + int mt4Time; + int.TryParse(values[1], out mt4Time); + time = MtApiTimeConverter.ConvertFromMtTime(mt4Time); + double.TryParse(values[2], out price); + res = true; + } + } + return res; + } + + /// + ///Opens a new chart with the specified symbol and period. + /// + ///Chart symbol. NULL means the symbol of the current chart (the Expert Advisor is attached to). + /// Chart period (timeframe). Can be one of the ENUM_TIMEFRAMES values. 0 means the current chart period. + /// + ///If successful, it returns the opened chart ID. Otherwise returns 0. + /// + public long ChartOpen(string symbol, ENUM_TIMEFRAMES period) + { + var commandParameters = new ArrayList { symbol, (int)period }; + return SendCommand(MtCommandType.ChartOpen, commandParameters); + } + + /// + ///Returns the ID of the first chart of the client terminal. + /// + public long ChartFirst() + { + return SendCommand(MtCommandType.ChartFirst, null); + } + + /// + ///Returns the chart ID of the chart next to the specified one. + /// + ///Chart ID. 0 does not mean the current chart. 0 means "return the first chart ID". + /// + ///Chart ID. If this is the end of the chart list, it returns -1. + /// + public long ChartNext(long chartId) + { + var commandParameters = new ArrayList { chartId }; + return SendCommand(MtCommandType.ChartNext, commandParameters); + } + + /// + ///Closes the specified chart. + /// + ///Chart ID. 0 means the current chart. + /// + ///If successful, returns true, otherwise false. + /// + public bool ChartClose(long chartId) + { + var commandParameters = new ArrayList { chartId }; + return SendCommand(MtCommandType.ChartClose, commandParameters); + } + + /// + ///Returns the symbol name for the specified chart. + /// + ///Chart ID. 0 means the current chart. + /// + ///If chart does not exist, the result will be an empty string. + /// + public string ChartSymbol(long chartId) + { + var commandParameters = new ArrayList { chartId }; + return SendCommand(MtCommandType.ChartSymbol, commandParameters); + } + + /// + ///Returns the timeframe period of specified chart. + /// + ///Chart ID. 0 means the current chart. + /// + ///The function returns one of the ENUM_TIMEFRAMES values. If chart does not exist, it returns 0. + /// + public ENUM_TIMEFRAMES ChartPeriod(long chartId) + { + var commandParameters = new ArrayList { chartId }; + return (ENUM_TIMEFRAMES) SendCommand(MtCommandType.ChartPeriod, commandParameters); + } + + /// + ///Sets a value for a corresponding property of the specified chart. Chart property should be of a double type. + /// + ///Chart ID. 0 means the current chart. + ///Chart property ID. Can be one of the ENUM_CHART_PROPERTY_DOUBLE values (except the read-only properties). + ///Property value. + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartSetDouble(long chartId, int propId, double value) + { + var commandParameters = new ArrayList { chartId, propId, value }; + return SendCommand(MtCommandType.ChartSetDouble, commandParameters); + } + + /// + ///Sets a value for a corresponding property of the specified chart. Chart property must be datetime, int, color, bool or char. + /// + ///Chart ID. 0 means the current chart. + ///Chart property ID. It can be one of the ENUM_CHART_PROPERTY_INTEGER value (except the read-only properties). + ///Property value. + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartSetInteger(long chartId, int propId, long value) + { + var commandParameters = new ArrayList { chartId, propId, value }; + return SendCommand(MtCommandType.ChartSetInteger, commandParameters); + } + + /// + ///Sets a value for a corresponding property of the specified chart. Chart property must be of the string type. + /// + ///Chart ID. 0 means the current chart. + ///Chart property ID. Its value can be one of the ENUM_CHART_PROPERTY_STRING values (except the read-only properties). + ///Property value string. String length cannot exceed 2045 characters (extra characters will be truncated). + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartSetString(long chartId, int propId, string value) + { + var commandParameters = new ArrayList { chartId, propId, value }; + return SendCommand(MtCommandType.ChartSetString, commandParameters); + } + + /// + ///Sets a value for a corresponding property of the specified chart. Chart property must be of the string type. + /// + ///Chart ID. 0 means the current chart. + ///Chart property ID. This value can be one of the ENUM_CHART_PROPERTY_DOUBLE values. + ///Number of the chart subwindow. For the first case, the default value is 0 (main chart window). The most of the properties do not require a subwindow number. + /// + ///The value of double type. + /// + public double ChartGetDouble(long chartId, int propId, int subWindow = 0) + { + var commandParameters = new ArrayList { chartId, propId, subWindow }; + return SendCommand(MtCommandType.ChartGetDouble, commandParameters); + } + + /// + ///Returns the value of a corresponding property of the specified chart. Chart property must be of datetime, int or bool type. + /// + ///Chart ID. 0 means the current chart. + ///Chart property ID. This value can be one of the ENUM_CHART_PROPERTY_INTEGER values. + ///Number of the chart subwindow. For the first case, the default value is 0 (main chart window). The most of the properties do not require a subwindow number. + /// + ///The value of long type. + /// + public long ChartGetInteger(long chartId, int propId, int subWindow = 0) + { + var commandParameters = new ArrayList { chartId, propId, subWindow }; + return SendCommand(MtCommandType.ChartGetInteger, commandParameters); + } + + /// + ///Returns the value of a corresponding property of the specified chart. Chart property must be of string type. + /// + ///Chart ID. 0 means the current chart. + ///Chart property ID. This value can be one of the ENUM_CHART_PROPERTY_STRING values. + /// + ///The value of string type. + /// + public string ChartGetString(long chartId, int propId) + { + var commandParameters = new ArrayList { chartId, propId }; + return SendCommand(MtCommandType.ChartGetString, commandParameters); + } + + /// + ///Performs shift of the specified chart by the specified number of bars relative to the specified position in the chart. + /// + ///Chart ID. 0 means the current chart. + ///Chart position to perform a shift. Can be one of the ENUM_CHART_POSITION values. + ///Number of bars to shift the chart. Positive value means the right shift (to the end of chart), negative value means the left shift (to the beginning of chart). The zero shift can be used to navigate to the beginning or end of chart. + /// + ///Returns true if successful, otherwise returns false. + /// + public bool ChartNavigate(long chartId, int position, int shift = 0) + { + var commandParameters = new ArrayList { chartId, position, shift }; + return SendCommand(MtCommandType.ChartNavigate, commandParameters); + } + + /// + ///Performs shift of the specified chart by the specified number of bars relative to the specified position in the chart. + /// + ///Chart ID. 0 means the current chart. + ///Number of the chart subwindow. 0 denotes the main chart subwindow. + ///The short name of the indicator which is set in the INDICATOR_SHORTNAME property with the IndicatorSetString() function. To get the short name of an indicator use the ChartIndicatorName() function. + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartIndicatorDelete(long chartId, int subWindow, string indicatorShortname) + { + var commandParameters = new ArrayList { chartId, subWindow, indicatorShortname }; + return SendCommand(MtCommandType.ChartIndicatorDelete, commandParameters); + } + + /// + ///Returns the short name of the indicator by the number in the indicators list on the specified chart window. + /// + ///Chart ID. 0 means the current chart. + ///Number of the chart subwindow. 0 denotes the main chart subwindow. + ///the index of the indicator in the list of indicators. The numeration of indicators start with zero, i.e. the first indicator in the list has the 0 index. To obtain the number of indicators in the list use the ChartIndicatorsTotal() function. + /// + ///The short name of the indicator which is set in the INDICATOR_SHORTNAME property with the IndicatorSetString() function. + /// + public string ChartIndicatorName(long chartId, int subWindow, int index) + { + var commandParameters = new ArrayList { chartId, subWindow, index }; + return SendCommand(MtCommandType.ChartIndicatorName, commandParameters); + } + + /// + ///Returns the number of all indicators applied to the specified chart window. + /// + ///Chart ID. 0 means the current chart. + ///Number of the chart subwindow. 0 denotes the main chart subwindow. + /// + ///The number of indicators in the specified chart window. + /// + public string ChartIndicatorsTotal(long chartId, int subWindow) + { + var commandParameters = new ArrayList { chartId, subWindow }; + return SendCommand(MtCommandType.ChartIndicatorsTotal, commandParameters); + } + + /// + ///Returns the number (index) of the chart subwindow the Expert Advisor or script has been dropped to. 0 means the main chart window. + /// + public int ChartWindowOnDropped() + { + return SendCommand(MtCommandType.ChartWindowOnDropped, null); + } + + /// + ///Returns the price coordinate corresponding to the chart point the Expert Advisor or script has been dropped to. + /// + public double ChartPriceOnDropped() + { + return SendCommand(MtCommandType.ChartPriceOnDropped, null); + } + + /// + ///Returns the time coordinate corresponding to the chart point the Expert Advisor or script has been dropped to. + /// + public DateTime ChartTimeOnDropped() + { + var res = SendCommand(MtCommandType.ChartTimeOnDropped, null); + return MtApiTimeConverter.ConvertFromMtTime(res); + } + + /// + ///Returns the X coordinate of the chart point the Expert Advisor or script has been dropped to. + /// + public int ChartXOnDropped() + { + return SendCommand(MtCommandType.ChartXOnDropped, null); + } + + /// + ///Returns the Y coordinateof the chart point the Expert Advisor or script has been dropped to. + /// + public int ChartYOnDropped() + { + return SendCommand(MtCommandType.ChartYOnDropped, null); + } + + /// + ///Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. + /// + ///Chart ID. 0 means the current chart. + ///Chart symbol. NULL value means the current chart symbol (Expert Advisor is attached to) + ///Chart period (timeframe). Can be one of the ENUM_TIMEFRAMES values. 0 means the current chart period. + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartSetSymbolPeriod(long chartId, string symbol, ENUM_TIMEFRAMES period) + { + var commandParameters = new ArrayList { chartId, symbol, (int)period }; + return SendCommand(MtCommandType.ChartSetSymbolPeriod, commandParameters); + } + + /// + ///Changes the symbol and period of the specified chart. The function is asynchronous, i.e. it sends the command and does not wait for its execution completion. + /// + ///Chart ID. 0 means the current chart. + ///Chart symbol. NULL value means the current chart symbol (Expert Advisor is attached to) + ///Chart period (timeframe). Can be one of the ENUM_TIMEFRAMES values. 0 means the current chart period. + /// + ///Returns true if the command has been added to chart queue, otherwise false. + /// + public bool ChartScreenShot(long chartId, string symbol, ENUM_TIMEFRAMES period) + { + var commandParameters = new ArrayList { chartId, symbol, (int)period }; + return SendCommand(MtCommandType.ChartScreenShot, commandParameters); + } #endregion #region Object Functions diff --git a/MtApi/MtCommandType.cs b/MtApi/MtCommandType.cs index 3b3b5492..8418b291 100755 --- a/MtApi/MtCommandType.cs +++ b/MtApi/MtCommandType.cs @@ -197,8 +197,6 @@ SymbolName = 201, SymbolSelect = 202, SymbolInfoInteger = 203, - ChartId = 206, - ChartRedraw = 207, //Object Functions ObjectCreate = 208, @@ -229,6 +227,54 @@ ObjectSetText = 233, ObjectType = 234, - UnlockTicks = 235 + UnlockTicks = 235, + + //Chart Operations + ChartId = 206, + ChartRedraw = 207, + ChartApplyTemplate = 236, + ChartSaveTemplate = 237, + ChartWindowFind = 238, + ChartTimePriceToXY = 239, + ChartXYToTimePrice = 240, + ChartOpen = 241, + ChartFirst = 242, + ChartNext = 243, + ChartClose = 244, + ChartSymbol = 245, + ChartPeriod = 246, + ChartSetDouble = 247, + ChartSetInteger = 248, + ChartSetString = 249, + ChartGetDouble = 250, + ChartGetInteger = 251, + ChartGetString = 252, + ChartNavigate = 253, + ChartIndicatorDelete = 254, + ChartIndicatorName = 255, + ChartIndicatorsTotal = 256, + ChartWindowOnDropped = 257, + ChartPriceOnDropped = 258, + ChartTimeOnDropped = 259, + ChartXOnDropped = 260, + ChartYOnDropped = 261, + ChartSetSymbolPeriod = 262, + ChartScreenShot = 263, + WindowBarsPerChart = 264, + WindowExpertName = 265, + WindowFind = 266, + WindowFirstVisibleBar = 267, + WindowHandle = 268, + WindowIsVisible = 269, + WindowOnDropped = 270, + WindowPriceMax = 271, + WindowPriceMin = 272, + WindowPriceOnDropped = 273, + WindowRedraw = 274, + WindowScreenShot = 275, + WindowTimeOnDropped = 276, + WindowsTotal = 277, + WindowXOnDropped = 278, + WindowYOnDropped = 279 } }