using System; using System.Collections.Generic; using System.Linq; using System.Text; using MTApiService; using System.Collections; namespace MtApi5 { public class MtApi5Client { #region MT Constants public const int SYMBOL_EXPIRATION_GTC = 1; public const int SYMBOL_EXPIRATION_DAY = 2; public const int SYMBOL_EXPIRATION_SPECIFIED = 4; public const int SYMBOL_EXPIRATION_SPECIFIED_DAY = 8; public const int SYMBOL_FILLING_ALL_OR_NONE = 1; public const int SYMBOL_CANCEL_REMAIND = 1; public const int SYMBOL_RETURN_REMAIND = 1; #endregion private const char PARAM_SEPARATOR = ';'; public delegate void QuoteHandler(object sender, string symbol, double bid, double ask); #region Public Methods public MtApi5Client() { ConnectionState = Mt5ConnectionState.Disconnected; mClient.QuoteAdded += new MtClient.MtQuoteHandler(mClient_QuoteAdded); mClient.QuoteRemoved += new MtClient.MtQuoteHandler(mClient_QuoteRemoved); mClient.QuoteUpdated += new MtClient.MtQuoteHandler(mClient_QuoteUpdated); mClient.ServerDisconnected += new EventHandler(mClient_ServerDisconnected); mClient.ServerFailed += new EventHandler(mClient_ServerFailed); } /// ///Connect with MetaTrader API. Async method. /// ///Address of MetaTrader host (ex. 192.168.1.2) ///Port of host connection (default 8222) public void BeginConnect(string host, int port) { //if (string.IsNullOrEmpty(host) == false && (host.Equals("localhost") || host.Equals("127.0.0.1"))) //{ // this.BeginConnect(port); //} //else //{ Action connectAction = Connect; connectAction.BeginInvoke(host, port, null, null); //} } /// ///Connect with MetaTrader API. Async method. /// ///Port of host connection (default 8222) public void BeginConnect(int port) { Action connectAction = Connect; connectAction.BeginInvoke(port, null, null); } /// ///Disconnect from MetaTrader API. Async method. /// public void BeginDisconnect() { Action disconnectAction = Disconnect; disconnectAction.BeginInvoke(null, null); } /// ///Load quotes connected into MetaTrader API. /// public IEnumerable GetQuotes() { var quotes = mClient.GetQuotes(); return quotes != null ? (from q in quotes select q.Parse()) : null; } #region Trading functions /// ///Sends trade requests to a server /// ///Reference to a object of MqlTradeRequest type describing the trade activity of the client. ///Reference to a object of MqlTradeResult type describing the result of trade operation in case of a successful completion (if true is returned). /// /// In case of a successful basic check of structures (index checking) returns true. /// However, this is not a sign of successful execution of a trade operation. /// For a more detailed description of the function execution result, analyze the fields of result structure. /// public bool OrderSend(MqlTradeRequest request, out MqlTradeResult result) { if (request == null) { result = null; return false; } var commandParameters = request.ToArrayList(); string strResult = sendCommand(Mt5CommandType.OrderSend, commandParameters); return strResult.ParseResult(PARAM_SEPARATOR, out result); } /// ///The function calculates the margin required for the specified order type, on the current account ///, in the current market environment not taking into account current pending orders and open positions ///. It allows the evaluation of margin for the trade operation planned. The value is returned in the account currency. /// ///The order type, can be one of the values of the ENUM_ORDER_TYPE enumeration. ///Symbol name. ///Volume of the trade operation. ///Open price. ///The variable, to which the value of the required margin will be written in case the function is successfully executed ///. The calculation is performed as if there were no pending orders and open positions on the current account ///. The margin value depends on many factors, and can differ in different market environments. /// /// The function returns true in case of success; otherwise it returns false. /// public bool OrderCalcMargin(ENUM_ORDER_TYPE action, string symbol, double volume, double price, out double margin) { var commandParameters = new ArrayList { (int)action, symbol, volume, price }; string strResult = sendCommand(Mt5CommandType.OrderCalcMargin, commandParameters); return strResult.ParseResult(PARAM_SEPARATOR, out margin); } /// ///The function calculates the profit for the current account, ///in the current market conditions, based on the parameters passed. ///The function is used for pre-evaluation of the result of a trade operation. ///The value is returned in the account currency. /// ///Type of the order, can be one of the two values of the ENUM_ORDER_TYPE enumeration: ORDER_TYPE_BUY or ORDER_TYPE_SELL. ///Symbol name. ///Volume of the trade operation. ///Open price. ///Close price. ///The variable, to which the calculated value of the profit will be written in case the function is successfully executed. ///The estimated profit value depends on many factors, and can differ in different market environments. /// /// The function returns true in case of success; otherwise it returns false. If an invalid order type is specified, the function will return false. /// public bool OrderCalcProfit(ENUM_ORDER_TYPE action, string symbol, double volume, double price_open, double price_close, out double profit) { var commandParameters = new ArrayList { (int)action, symbol, volume, price_open, price_close }; string strResult = sendCommand(Mt5CommandType.OrderCalcProfit, commandParameters); return strResult.ParseResult(PARAM_SEPARATOR, out profit); } /// ///The OrderCheck() function checks if there are enough money to execute a required trade operation. ///The check results are placed to the fields of the MqlTradeCheckResult structure. /// ///Reference to a object of MqlTradeRequest type describing the trade activity of the client. /// Reference to the object of the MqlTradeCheckResult type, to which the check result will be placed. /// /// If funds are not enough for the operation, or parameters are filled out incorrectly, the function returns false. /// In case of a successful basic check of structures (check of pointers), it returns true. /// However, this is not an indication that the requested trade operation is sure to be successfully executed. /// For a more detailed description of the function execution result, analyze the fields of the result structure. /// public bool OrderCheck(MqlTradeRequest request, out MqlTradeCheckResult result) { if (request == null) { result = null; return false; } var commandParameters = request.ToArrayList(); string strResult = sendCommand(Mt5CommandType.OrderSend, commandParameters); return strResult.ParseResult(PARAM_SEPARATOR, out result); } /// ///Returns the number of open positions. /// public int PositionsTotal() { return sendCommand(Mt5CommandType.PositionsTotal, null); } /// ///Returns the symbol corresponding to the open position and automatically selects the position for further working with it using functions PositionGetDouble, PositionGetInteger, PositionGetString. /// ///Number of the position in the list of open positions. public string PositionGetSymbol(int index) { var commandParameters = new ArrayList { index }; return sendCommand(Mt5CommandType.PositionGetSymbol, commandParameters); } /// ///Chooses an open position for further working with it. Returns true if the function is successfully completed. Returns false in case of failure. /// ///Name of the financial security. public bool PositionSelect(string symbol) { var commandParameters = new ArrayList { symbol }; return sendCommand(Mt5CommandType.PositionSelect, commandParameters); } /// ///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. /// ///Identifier of a position property. public double PositionGetDouble(ENUM_POSITION_PROPERTY_DOUBLE property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.PositionGetDouble, commandParameters); } /// ///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. /// ///Identifier of a position property. public long PositionGetInteger(ENUM_POSITION_PROPERTY_INTEGER property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.PositionGetInteger, commandParameters); } /// ///The function returns the requested property of an open position, pre-selected using PositionGetSymbol or PositionSelect. /// ///Identifier of a position property. public string PositionGetString(ENUM_POSITION_PROPERTY_STRING property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.PositionGetString, commandParameters); } /// ///Returns the number of current orders. /// public int OrdersTotal() { return sendCommand(Mt5CommandType.OrdersTotal, null); } /// ///Returns the number of current orders. /// ///Number of an order in the list of current orders. public ulong OrderGetTicket(int index) { var commandParameters = new ArrayList { index }; return sendCommand(Mt5CommandType.OrderGetTicket, commandParameters); } /// ///Selects an order to work with. Returns true if the function has been successfully completed. /// ///Order ticket. public bool OrderSelect(ulong ticket) { var commandParameters = new ArrayList { ticket }; return sendCommand(Mt5CommandType.OrderSelect, commandParameters); } /// ///Returns the requested property of an order, pre-selected using OrderGetTicket or OrderSelect. /// /// Identifier of the order property. public double OrderGetDouble(ENUM_ORDER_PROPERTY_DOUBLE property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.OrderGetDouble, commandParameters); } /// ///Returns the requested property of an order, pre-selected using OrderGetTicket or OrderSelect. /// /// Identifier of the order property. public long OrderGetInteger(ENUM_ORDER_PROPERTY_INTEGER property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.OrderGetInteger, commandParameters); } /// ///Returns the requested property of an order, pre-selected using OrderGetTicket or OrderSelect. /// /// Identifier of the order property. public string OrderGetString(ENUM_ORDER_PROPERTY_STRING property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.OrderGetString, commandParameters); } /// ///Retrieves the history of deals and orders for the specified period of server time. /// ///Start date of the request. ///End date of the request. public bool HistorySelect(DateTime from_date, DateTime to_date) { var commandParameters = new ArrayList { Mt5TimeConverter.ConvertToMtTime(from_date), Mt5TimeConverter.ConvertToMtTime(to_date) }; return sendCommand(Mt5CommandType.HistorySelect, commandParameters); } /// ///Retrieves the history of deals and orders having the specified position identifier. /// ///Position identifier that is set to every executed order and every deal. public bool HistorySelectByPosition(long position_id) { var commandParameters = new ArrayList { position_id }; return sendCommand(Mt5CommandType.HistorySelectByPosition, commandParameters); } /// ///Selects an order from the history for further calling it through appropriate functions. /// ///Order ticket. public bool HistoryOrderSelect(ulong ticket) { var commandParameters = new ArrayList { ticket }; return sendCommand(Mt5CommandType.HistoryOrderSelect, commandParameters); } /// ///Returns the number of orders in the history. /// public int HistoryOrdersTotal() { return sendCommand(Mt5CommandType.HistoryOrdersTotal, null); } /// ///Return the ticket of a corresponding order in the history. /// ///Number of the order in the list of orders. public ulong HistoryOrderGetTicket(int index) { var commandParameters = new ArrayList { index }; return sendCommand(Mt5CommandType.HistoryOrderGetTicket, commandParameters); } /// ///Returns the requested order property. /// ///Order ticket. ///Identifier of the order property. public double HistoryOrderGetDouble(ulong ticket_number, ENUM_ORDER_PROPERTY_DOUBLE property_id) { var commandParameters = new ArrayList { ticket_number, (int)property_id }; return sendCommand(Mt5CommandType.HistoryOrderGetDouble, commandParameters); } /// ///Returns the requested property of an order. /// ///Order ticket. ///Identifier of the order property. public long HistoryOrderGetInteger(ulong ticket_number, ENUM_ORDER_PROPERTY_INTEGER property_id) { var commandParameters = new ArrayList { ticket_number, (int)property_id }; return sendCommand(Mt5CommandType.HistoryOrderGetInteger, commandParameters); } /// ///Returns the requested property of an order. /// ///Order ticket. ///Identifier of the order property. public string HistoryOrderGetString(ulong ticket_number, ENUM_ORDER_PROPERTY_STRING property_id) { var commandParameters = new ArrayList { ticket_number, (int)property_id }; return sendCommand(Mt5CommandType.HistoryOrderGetString, commandParameters); } /// ///Selects a deal in the history for further calling it through appropriate functions. /// ///Deal ticket. public bool HistoryDealSelect(ulong ticket) { var commandParameters = new ArrayList { ticket }; return sendCommand(Mt5CommandType.HistoryDealSelect, commandParameters); } /// ///Returns the number of deal in history. /// public int HistoryDealsTotal() { return sendCommand(Mt5CommandType.HistoryDealsTotal, null); } /// ///The function selects a deal for further processing and returns the deal ticket in history. /// ///Number of a deal in the list of deals. public ulong HistoryDealGetTicket(int index) { var commandParameters = new ArrayList { index }; return sendCommand(Mt5CommandType.HistoryDealGetTicket, commandParameters); } /// ///Returns the requested property of a deal. /// ///Deal ticket. /// Identifier of a deal property. public double HistoryDealGetDouble(ulong ticket_number, ENUM_DEAL_PROPERTY_DOUBLE property_id) { var commandParameters = new ArrayList { ticket_number, property_id }; return sendCommand(Mt5CommandType.HistoryDealGetDouble, commandParameters); } /// ///Returns the requested property of a deal. /// ///Deal ticket. /// Identifier of a deal property. public long HistoryDealGetInteger(ulong ticket_number, ENUM_DEAL_PROPERTY_INTEGER property_id) { var commandParameters = new ArrayList { ticket_number, property_id }; return sendCommand(Mt5CommandType.HistoryDealGetInteger, commandParameters); } /// ///Returns the requested property of a deal. /// ///Deal ticket. /// Identifier of a deal property. public string HistoryDealGetString(ulong ticket_number, ENUM_DEAL_PROPERTY_STRING property_id) { var commandParameters = new ArrayList { ticket_number, property_id }; return sendCommand(Mt5CommandType.HistoryDealGetString, commandParameters); } /// ///Close all open positions. /// ///OrderCloseAll public bool OrderCloseAll() { return sendCommand(Mt5CommandType.OrderCloseAll, null); } /// ///Closes a position with the specified ticket. /// ///Ticket of the closed position. public bool PositionClose(int ticket) { var commandParameters = new ArrayList { ticket}; return sendCommand(Mt5CommandType.PositionClose, commandParameters); } #endregion #region Account Information functions /// ///Returns the value of the corresponding account property. /// ///Identifier of the property. public double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.AccountInfoDouble, commandParameters); } /// ///Returns the value of the corresponding account property. /// ///Identifier of the property. public long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.AccountInfoInteger, commandParameters); } /// ///Returns the value of the corresponding account property. /// ///Identifier of the property. public string AccountInfoString(ENUM_ACCOUNT_INFO_STRING property_id) { var commandParameters = new ArrayList { (int)property_id }; return sendCommand(Mt5CommandType.AccountInfoString, commandParameters); } #endregion #region Timeseries and Indicators Access /// ///Returns information about the state of historical data. /// ///Symbol name. /// Period. ///Identifier of the requested property, value of the ENUM_SERIES_INFO_INTEGER enumeration. public int SeriesInfoInteger(string symbol_name, ENUM_TIMEFRAMES timeframe, ENUM_SERIES_INFO_INTEGER prop_id) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, (int)prop_id }; return sendCommand(Mt5CommandType.SeriesInfoInteger, commandParameters); } /// ///Returns the number of bars count in the history for a specified symbol and period. /// ///Symbol name. /// Period. public int Bars(string symbol_name, ENUM_TIMEFRAMES timeframe) { var commandParameters = new ArrayList { symbol_name, (int)timeframe }; return sendCommand(Mt5CommandType.Bars, commandParameters); } /// ///Returns the number of bars count in the history for a specified symbol and period. /// ///Symbol name. ///Period. ///Bar time corresponding to the first element. ///Bar time corresponding to the last element. public int Bars(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; return sendCommand(Mt5CommandType.Bars2, commandParameters); } /// ///Returns the number of calculated data for the specified indicator. /// ///The indicator handle, returned by the corresponding indicator function. public int BarsCalculated(int indicator_handle) { var commandParameters = new ArrayList { indicator_handle }; return sendCommand(Mt5CommandType.BarsCalculated, commandParameters); } /// ///Gets data of a specified buffer of a certain indicator in the necessary quantity. /// ///The indicator handle, returned by the corresponding indicator function. ///The indicator buffer number. ///The position of the first element to copy. ///Data count to copy. ///Array of double type. public int CopyBuffer(int indicator_handle, int buffer_num, int start_pos, int count, out double[] buffer) { var commandParameters = new ArrayList { indicator_handle, buffer_num, start_pos, count }; buffer = sendCommand(Mt5CommandType.CopyBuffer, commandParameters); return buffer != null ? buffer.Length : 0; } /// ///Gets data of a specified buffer of a certain indicator in the necessary quantity. /// ///The indicator handle, returned by the corresponding indicator function. ///The indicator buffer number. ///Bar time, corresponding to the first element. ///Data count to copy. ///Array of double type. public int CopyBuffer(int indicator_handle, int buffer_num, DateTime start_time, int count, out double[] buffer) { var commandParameters = new ArrayList { indicator_handle, buffer_num, Mt5TimeConverter.ConvertToMtTime(start_time), count }; buffer = sendCommand(Mt5CommandType.CopyBuffer1, commandParameters); return buffer != null ? buffer.Length : 0; } /// ///Gets data of a specified buffer of a certain indicator in the necessary quantity. /// ///The indicator handle, returned by the corresponding indicator function. ///The indicator buffer number. ///Bar time, corresponding to the first element. ///Bar time, corresponding to the last element. ///Array of double type. public int CopyBuffer(int indicator_handle, int buffer_num, DateTime start_time, DateTime stop_time, out double[] buffer) { var commandParameters = new ArrayList { indicator_handle, buffer_num, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; buffer = sendCommand(Mt5CommandType.CopyBuffer1, commandParameters); return buffer != null ? buffer.Length : 0; } /// ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the rates_array array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of MqlRates type. public int CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out MqlRates[] rates_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; rates_array = null; var retVal = sendCommand(Mt5CommandType.CopyRates, commandParameters); if (retVal != null) { rates_array = new MqlRates[retVal.Length]; for(int i = 0; i < retVal.Length; i++) { rates_array[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) , retVal[i].open , retVal[i].high , retVal[i].low , retVal[i].close , retVal[i].tick_volume , retVal[i].spread , retVal[i].real_volume); } } return rates_array != null ? rates_array.Length : 0; } /// ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the rates_array array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of MqlRates type. public int CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out MqlRates[] rates_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; rates_array = null; var retVal = sendCommand(Mt5CommandType.CopyRates1, commandParameters); if (retVal != null) { rates_array = new MqlRates[retVal.Length]; for (int i = 0; i < retVal.Length; i++) { rates_array[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) , retVal[i].open , retVal[i].high , retVal[i].low , retVal[i].close , retVal[i].tick_volume , retVal[i].spread , retVal[i].real_volume); } } return rates_array != null ? rates_array.Length : 0; } /// ///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the rates_array array. The elements ordering of the copied data is from present to the past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Bar time, corresponding to the last element to copy. ///Array of MqlRates type. public int CopyRates(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out MqlRates[] rates_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; rates_array = null; var retVal = sendCommand(Mt5CommandType.CopyRates2, commandParameters); if (retVal != null) { rates_array = new MqlRates[retVal.Length]; for (int i = 0; i < retVal.Length; i++) { rates_array[i] = new MqlRates(Mt5TimeConverter.ConvertFromMtTime(retVal[i].time) , retVal[i].open , retVal[i].high , retVal[i].low , retVal[i].close , retVal[i].tick_volume , retVal[i].spread , retVal[i].real_volume); } } return rates_array != null ? rates_array.Length : 0; } /// ///The function gets to time_array history data of bar opening time for the specified symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of DatetTme type. public int CopyTime(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out DateTime[] time_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; time_array = null; var retVal = sendCommand(Mt5CommandType.CopyTime, commandParameters); if (retVal != null) { time_array = new DateTime[retVal.Length]; for (int i = 0; i < retVal.Length; i++) { time_array[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); } } return time_array != null ? time_array.Length : 0; } /// ///The function gets to time_array history data of bar opening time for the specified symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of DatetTme type. public int CopyTime(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out DateTime[] time_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; time_array = null; var retVal = sendCommand(Mt5CommandType.CopyTime1, commandParameters); if (retVal != null) { time_array = new DateTime[retVal.Length]; for (int i = 0; i < retVal.Length; i++) { time_array[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); } } return time_array != null ? time_array.Length : 0; } /// ///The function gets to time_array history data of bar opening time for the specified symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Bar time corresponding to the last element to copy. ///Array of DatetTme type. public int CopyTime(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out DateTime[] time_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; time_array = null; var retVal = sendCommand(Mt5CommandType.CopyTime2, commandParameters); if (retVal != null) { time_array = new DateTime[retVal.Length]; for (int i = 0; i < retVal.Length; i++) { time_array[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]); } } return time_array != null ? time_array.Length : 0; } /// ///The function gets into open_array the history data of bar open prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyOpen(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] open_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; open_array = sendCommand(Mt5CommandType.CopyOpen, commandParameters); return open_array != null ? open_array.Length : 0; } /// ///The function gets into open_array the history data of bar open prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyOpen(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] open_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; open_array = sendCommand(Mt5CommandType.CopyOpen1, commandParameters); return open_array != null ? open_array.Length : 0; } /// ///The function gets into open_array the history data of bar open prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///The start time for the last element to copy. ///Array of double type. public int CopyOpen(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] open_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; open_array = sendCommand(Mt5CommandType.CopyOpen2, commandParameters); return open_array != null ? open_array.Length : 0; } /// ///The function gets into high_array the history data of highest bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyHigh(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] high_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; high_array = sendCommand(Mt5CommandType.CopyHigh, commandParameters); return high_array != null ? high_array.Length : 0; } /// ///The function gets into high_array the history data of highest bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyHigh(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] high_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; high_array = sendCommand(Mt5CommandType.CopyHigh1, commandParameters); return high_array != null ? high_array.Length : 0; } /// ///The function gets into high_array the history data of highest bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///The start time for the last element to copy. ///Array of double type. public int CopyHigh(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] high_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; high_array = sendCommand(Mt5CommandType.CopyHigh2, commandParameters); return high_array != null ? high_array.Length : 0; } /// ///The function gets into low_array the history data of minimal bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] low_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; low_array = sendCommand(Mt5CommandType.CopyLow, commandParameters); return low_array != null ? low_array.Length : 0; } /// ///The function gets into low_array the history data of minimal bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] low_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; low_array = sendCommand(Mt5CommandType.CopyLow1, commandParameters); return low_array != null ? low_array.Length : 0; } /// ///The function gets into low_array the history data of minimal bar prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///The start time for the last element to copy. ///Array of double type. public int CopyLow(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] low_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; low_array = sendCommand(Mt5CommandType.CopyLow2, commandParameters); return low_array != null ? low_array.Length : 0; } /// ///The function gets into close_array the history data of bar close prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out double[] close_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; close_array = sendCommand(Mt5CommandType.CopyClose, commandParameters); return close_array != null ? close_array.Length : 0; } /// ///The function gets into close_array the history data of bar close prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of double type. public int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out double[] close_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; close_array = sendCommand(Mt5CommandType.CopyClose1, commandParameters); return close_array != null ? close_array.Length : 0; } /// ///The function gets into close_array the history data of bar close prices for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///The start time for the last element to copy. ///Array of double type. public int CopyClose(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out double[] close_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; close_array = sendCommand(Mt5CommandType.CopyClose2, commandParameters); return close_array != null ? close_array.Length : 0; } /// ///The function gets into volume_array the history data of tick volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of long type. public int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out long[] volume_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; volume_array = sendCommand(Mt5CommandType.CopyTickVolume, commandParameters); return volume_array != null ? volume_array.Length : 0; } /// ///The function gets into volume_array the history data of tick volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of long type. public int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out long[] volume_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; volume_array = sendCommand(Mt5CommandType.CopyTickVolume1, commandParameters); return volume_array != null ? volume_array.Length : 0; } /// ///The function gets into volume_array the history data of tick volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///The start time for the last element to copy. ///Array of long type. public int CopyTickVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out long[] volume_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; volume_array = sendCommand(Mt5CommandType.CopyTickVolume2, commandParameters); return volume_array != null ? volume_array.Length : 0; } /// ///The function gets into volume_array the history data of trade volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of long type. public int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out long[] volume_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; volume_array = sendCommand(Mt5CommandType.CopyRealVolume, commandParameters); return volume_array != null ? volume_array.Length : 0; } /// ///The function gets into volume_array the history data of trade volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of long type. public int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out long[] volume_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; volume_array = sendCommand(Mt5CommandType.CopyRealVolume1, commandParameters); return volume_array != null ? volume_array.Length : 0; } /// ///The function gets into volume_array the history data of trade volumes for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///The start time for the last element to copy. ///Array of long type. public int CopyRealVolume(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out long[] volume_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; volume_array = sendCommand(Mt5CommandType.CopyRealVolume2, commandParameters); return volume_array != null ? volume_array.Length : 0; } /// ///The function gets into spread_array the history data of spread values for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start position for the first element to copy. ///Data count to copy. ///Array of long type. public int CopySpread(string symbol_name, ENUM_TIMEFRAMES timeframe, int start_pos, int count, out int[] spread_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, start_pos, count }; spread_array = sendCommand(Mt5CommandType.CopySpread, commandParameters); return spread_array != null ? spread_array.Length : 0; } /// ///The function gets into spread_array the history data of spread values for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///Data count to copy. ///Array of long type. public int CopySpread(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, int count, out int[] spread_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), count }; spread_array = sendCommand(Mt5CommandType.CopySpread1, commandParameters); return spread_array != null ? spread_array.Length : 0; } /// ///The function gets into spread_array the history data of spread values for the selected symbol-period pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e., starting position of 0 means the current bar. /// ///Symbol name. ///Period. ///The start time for the first element to copy. ///The start time for the last element to copy. ///Array of long type. public int CopySpread(string symbol_name, ENUM_TIMEFRAMES timeframe, DateTime start_time, DateTime stop_time, out int[] spread_array) { var commandParameters = new ArrayList { symbol_name, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(start_time), Mt5TimeConverter.ConvertToMtTime(stop_time) }; spread_array = sendCommand(Mt5CommandType.CopySpread2, commandParameters); return spread_array != null ? spread_array.Length : 0; } #endregion #region Market Info /// ///Returns the number of available (selected in Market Watch or all) symbols. /// ///Request mode. Can be true or false. public int SymbolsTotal(bool selected) { var commandParameters = new ArrayList { selected }; return sendCommand(Mt5CommandType.SymbolsTotal, commandParameters); } /// ///Returns the name of a symbol. /// ///Order number of a symbol. ///Request mode. If the value is true, the symbol is taken from the list of symbols selected in MarketWatch. If the value is false, the symbol is taken from the general list. public string SymbolName(int pos, bool selected) { var commandParameters = new ArrayList { pos, selected }; return sendCommand(Mt5CommandType.SymbolName, commandParameters); } /// ///Selects a symbol in the Market Watch window or removes a symbol from the window. /// ///Symbol name. ///Switch. If the value is false, a symbol should be removed from MarketWatch, otherwise a symbol should be selected in this window. A symbol can't be removed if the symbol chart is open, or there are open positions for this symbol. public bool SymbolSelect(string name, bool selected) { var commandParameters = new ArrayList { name, selected }; return sendCommand(Mt5CommandType.SymbolSelect, commandParameters); } /// ///The function checks whether data of a selected symbol in the terminal are synchronized with data on the trade server. /// ///Symbol name. public bool SymbolIsSynchronized(string name) { var commandParameters = new ArrayList { name }; return sendCommand(Mt5CommandType.SymbolIsSynchronized, commandParameters); } /// ///Returns the corresponding property of a specified symbol. /// ///Symbol name. ///Identifier of a symbol property. public double SymbolInfoDouble(string name, ENUM_SYMBOL_INFO_DOUBLE prop_id) { var commandParameters = new ArrayList { name, (int)prop_id }; return sendCommand(Mt5CommandType.SymbolInfoDouble, commandParameters); } /// ///Returns the corresponding property of a specified symbol. /// ///Symbol name. ///Identifier of a symbol property. public long SymbolInfoInteger(string name, ENUM_SYMBOL_INFO_INTEGER prop_id) { var commandParameters = new ArrayList { name, (int)prop_id }; return sendCommand(Mt5CommandType.SymbolInfoInteger, commandParameters); } /// ///Returns the corresponding property of a specified symbol. /// ///Symbol name. ///Identifier of a symbol property. public string SymbolInfoString(string name, ENUM_SYMBOL_INFO_STRING prop_id) { var commandParameters = new ArrayList { name, (int)prop_id }; return sendCommand(Mt5CommandType.SymbolInfoString, commandParameters); } /// ///The function returns current prices of a specified symbol in a variable of the MqlTick type. ///The function returns true if successful, otherwise returns false. /// ///Symbol name. /// Link to the structure of the MqlTick type, to which the current prices and time of the last price update will be placed. public bool SymbolInfoTick(string symbol, out MqlTick tick) { var commandParameters = new ArrayList { symbol }; var retVal = sendCommand(Mt5CommandType.SymbolInfoTick, commandParameters); tick = null; if (retVal != null) { tick = new MqlTick(Mt5TimeConverter.ConvertFromMtTime(retVal.time), retVal.bid, retVal.ask, retVal.last, retVal.volume); } return tick != null; } /// ///Allows receiving time of beginning and end of the specified quoting sessions for a specified symbol and weekday. /// ///Symbol name. ///Day of the week ///Ordinal number of a session, whose beginning and end time we want to receive. Indexing of sessions starts with 0. ///Session beginning time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. ///Session end time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. public bool SymbolInfoSessionQuote(string name, ENUM_DAY_OF_WEEK day_of_week, uint session_index, out DateTime from, out DateTime to) { var commandParameters = new ArrayList { name, (int)day_of_week, session_index }; string strResult = sendCommand(Mt5CommandType.SymbolInfoSessionQuote, commandParameters); return strResult.ParseResult(PARAM_SEPARATOR, out from, out to); } /// ///Allows receiving time of beginning and end of the specified trading sessions for a specified symbol and weekday. /// ///Symbol name. ///Day of the week ///Ordinal number of a session, whose beginning and end time we want to receive. Indexing of sessions starts with 0. ///Session beginning time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. ///Session end time in seconds from 00 hours 00 minutes, in the returned value date should be ignored. public bool SymbolInfoSessionTrade(string name, ENUM_DAY_OF_WEEK day_of_week, uint session_index, out DateTime from, out DateTime to) { var commandParameters = new ArrayList { name, (int)day_of_week, session_index }; string strResult = sendCommand(Mt5CommandType.SymbolInfoSessionTrade, commandParameters); return strResult.ParseResult(PARAM_SEPARATOR, out from, out to); } /// ///Provides opening of Depth of Market for a selected symbol, and subscribes for receiving notifications of the DOM changes. /// ///Symbol name. public bool MarketBookAdd(string symbol) { var commandParameters = new ArrayList { symbol }; return sendCommand(Mt5CommandType.MarketBookAdd, commandParameters); } /// ///Provides closing of Depth of Market for a selected symbol, and cancels the subscription for receiving notifications of the DOM changes. /// ///Symbol name. public bool MarketBookRelease(string symbol) { var commandParameters = new ArrayList { symbol }; return sendCommand(Mt5CommandType.MarketBookRelease, commandParameters); } /// ///Returns a structure array MqlBookInfo containing records of the Depth of Market of a specified symbol. /// ///Symbol name. ///Reference to an array of Depth of Market records. public bool MarketBookGet(string symbol, out MqlBookInfo[] book) { var commandParameters = new ArrayList { symbol }; var retVal = sendCommand(Mt5CommandType.MarketBookGet, commandParameters); book = null; if (retVal != null) { book = new MqlBookInfo[retVal.Length]; for (int i = 0; i < retVal.Length; i++) { book[0] = new MqlBookInfo((ENUM_BOOK_TYPE)retVal[i].type, retVal[i].price, retVal[i].volume); } } return book != null; } #endregion #endregion #region Properties /// ///Connection status of MetaTrader API. /// public Mt5ConnectionState ConnectionState { get; private set; } #endregion #region Events public event QuoteHandler QuoteUpdated; public event EventHandler QuoteAdded; public event EventHandler QuoteRemoved; public event EventHandler ConnectionStateChanged; #endregion #region Private Methods private void Connect(string host, int port) { ConnectionState = Mt5ConnectionState.Connecting; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Connecting, "Connecting to " + host + ":" + port)); try { mClient.Open(host, port); mClient.Connect(); } catch (Exception e) { ConnectionState = Mt5ConnectionState.Failed; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Failed, "Failed connection to " + host + ":" + port + ". " + e.Message)); return; } ConnectionState = Mt5ConnectionState.Connected; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Connected, "Connected to " + host + ":" + port)); } private void Connect(int port) { ConnectionState = Mt5ConnectionState.Connecting; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Connecting, "Connecting to 'localhost':" + port)); try { mClient.Open(port); mClient.Connect(); } catch (Exception e) { ConnectionState = Mt5ConnectionState.Failed; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Failed, "Failed connection to 'localhost':" + port + ". " + e.Message)); return; } ConnectionState = Mt5ConnectionState.Connected; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Connected, "Connected to 'localhost':" + port)); } private void Disconnect() { mClient.Disconnect(); mClient.Close(); ConnectionState = Mt5ConnectionState.Disconnected; ConnectionStateChanged.FireEvent(this, new Mt5ConnectionEventArgs(Mt5ConnectionState.Disconnected, "Disconnected")); } private T sendCommand(Mt5CommandType commandType, ArrayList commandParameters) { var response = mClient.SendCommand((int)commandType, commandParameters); if (response is MtResponseDouble) return (T)Convert.ChangeType(((MtResponseDouble)response).Value, typeof(T)); if (response is MtResponseInt) return (T)Convert.ChangeType(((MtResponseInt)response).Value, typeof(T)); if (response is MtResponseLong) return (T)Convert.ChangeType(((MtResponseLong)response).Value, typeof(T)); if (response is MtResponseULong) return (T)Convert.ChangeType(((MtResponseULong)response).Value, typeof(T)); if (response is MtResponseBool) return (T)Convert.ChangeType(((MtResponseBool)response).Value, typeof(T)); if (response is MtResponseString) return (T)Convert.ChangeType(((MtResponseString)response).Value, typeof(T)); if (response is MtResponseDoubleArray) return (T)Convert.ChangeType(((MtResponseDoubleArray)response).Value, typeof(T)); if (response is MtResponseIntArray) return (T)Convert.ChangeType(((MtResponseIntArray)response).Value, typeof(T)); if (response is MtResponseLongArray) return (T)Convert.ChangeType(((MtResponseLongArray)response).Value, typeof(T)); if (response is MtResponseArrayList) return (T)Convert.ChangeType(((MtResponseArrayList)response).Value, typeof(T)); if (response is MtResponseMqlRatesArray) return (T)Convert.ChangeType(((MtResponseMqlRatesArray)response).Value, typeof(T)); if (response is MtResponseMqlTick) return (T)Convert.ChangeType(((MtResponseMqlTick)response).Value, typeof(T)); if (response is MtResponseMqlBookInfoArray) return (T)Convert.ChangeType(((MtResponseMqlBookInfoArray)response).Value, typeof(T)); return default(T); } private void mClient_QuoteUpdated(MtQuote quote) { if (quote != null) { if (QuoteUpdated != null) { QuoteUpdated(this, quote.Instrument, quote.Bid, quote.Ask); } } } private void mClient_ServerDisconnected(object sender, EventArgs e) { ConnectionState = Mt5ConnectionState.Disconnected; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Disconnected, "MtApi is disconnected")); } private void mClient_ServerFailed(object sender, EventArgs e) { ConnectionState = Mt5ConnectionState.Failed; ConnectionStateChanged.FireEvent(this , new Mt5ConnectionEventArgs(Mt5ConnectionState.Failed, "Failed connection with MtApi")); } private void mClient_QuoteRemoved(MtQuote quote) { QuoteRemoved.FireEvent(this, new Mt5QuoteEventArgs(quote.Parse())); } private void mClient_QuoteAdded(MtQuote quote) { QuoteAdded.FireEvent(this, new Mt5QuoteEventArgs(quote.Parse())); } #endregion #region Private Fields private readonly MtClient mClient = new MtClient(); #endregion } }