// ReSharper disable InconsistentNaming
using System;
using System.Collections.Generic;
using System.Linq;
using MTApiService;
using System.Collections;
using System.ServiceModel;
using MtApi5.Requests;
using Newtonsoft.Json;
using System.Threading.Tasks;
using MtApi5.Events;
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 ParamSeparator = ';';
private const string LogProfileName = "MtApi5Client";
public delegate void QuoteHandler(object sender, string symbol, double bid, double ask);
#region Private Fields
private static readonly MtLog Log = LogConfigurator.GetLogger(typeof(MtApi5Client));
private MtClient _client;
private readonly object _locker = new object();
private volatile bool _isBacktestingMode;
private Mt5ConnectionState _connectionState = Mt5ConnectionState.Disconnected;
private int _executorHandle;
#endregion
#region Public Methods
public MtApi5Client()
{
LogConfigurator.Setup(LogProfileName);
}
///
///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)
{
Task.Factory.StartNew(() => Connect(host, port));
}
///
///Connect with MetaTrader API. Async method.
///
///Port of host connection (default 8222)
public void BeginConnect(int port)
{
Task.Factory.StartNew(() => Connect(port));
}
///
///Disconnect from MetaTrader API. Async method.
///
public void BeginDisconnect()
{
Task.Factory.StartNew(() => Disconnect(false));
}
///
///Load quotes connected into MetaTrader API.
///
public IEnumerable GetQuotes()
{
var client = Client;
var quotes = client?.GetQuotes();
return quotes?.Select(q => new Mt5Quote(q));
}
///
///Checks if the Expert Advisor runs in the testing mode..
///
public bool IsTesting()
{
return SendCommand(Mt5CommandType.IsTesting, 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)
{
Log.Debug($"OrderSend: request = {request}");
if (request == null)
{
Log.Warn("OrderSend: request is not defined!");
result = null;
return false;
}
var response = SendRequest(new OrderSendRequest
{
TradeRequest = request
});
result = response?.TradeResult;
return response != null && response.RetVal;
}
///
///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 };
var strResult = SendCommand(Mt5CommandType.OrderCalcMargin, commandParameters);
return strResult.ParseResult(ParamSeparator, 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 priceOpen, double priceClose, out double profit)
{
var commandParameters = new ArrayList { (int)action, symbol, volume, priceOpen, priceClose };
var strResult = SendCommand(Mt5CommandType.OrderCalcProfit, commandParameters);
return strResult.ParseResult(ParamSeparator, 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)
{
Log.Debug($"OrderCheck: request = {request}");
if (request == null)
{
Log.Warn("OrderCheck: request is not defined!");
result = null;
return false;
}
var response = SendRequest(new OrderCheckRequest
{
TradeRequest = request
});
result = response?.TradeCheckResult;
return response != null && response.RetVal;
}
///
///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);
}
///
///Selects an open position to work with based on the ticket number specified in the position. If successful, returns true. Returns false if the function failed.
///
///Position ticket.
public bool PositionSelectByTicket(ulong ticket)
{
var commandParameters = new ArrayList { ticket };
return SendCommand(Mt5CommandType.PositionSelectByTicket, 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 propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
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 propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
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 propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
return SendCommand(Mt5CommandType.PositionGetString, commandParameters);
}
///
///The function returns the ticket of a position with the specified index in the list of open positions and automatically selects the position to work with using functions PositionGetDouble, PositionGetInteger, PositionGetString.
///
///Identifier of a position property.
public ulong PositionGetTicket(int index)
{
var commandParameters = new ArrayList { index };
return SendCommand(Mt5CommandType.PositionGetTicket, 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 propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
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 propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
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 propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
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 fromDate, DateTime toDate)
{
var commandParameters = new ArrayList { Mt5TimeConverter.ConvertToMtTime(fromDate), Mt5TimeConverter.ConvertToMtTime(toDate) };
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 positionId)
{
var commandParameters = new ArrayList { positionId };
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 ticketNumber, ENUM_ORDER_PROPERTY_DOUBLE propertyId)
{
var commandParameters = new ArrayList { ticketNumber, (int)propertyId };
return SendCommand(Mt5CommandType.HistoryOrderGetDouble, commandParameters);
}
///
///Returns the requested property of an order.
///
///Order ticket.
///Identifier of the order property.
public long HistoryOrderGetInteger(ulong ticketNumber, ENUM_ORDER_PROPERTY_INTEGER propertyId)
{
var commandParameters = new ArrayList { ticketNumber, (int)propertyId };
return SendCommand(Mt5CommandType.HistoryOrderGetInteger, commandParameters);
}
///
///Returns the requested property of an order.
///
///Order ticket.
///Identifier of the order property.
public string HistoryOrderGetString(ulong ticketNumber, ENUM_ORDER_PROPERTY_STRING propertyId)
{
var commandParameters = new ArrayList { ticketNumber, (int)propertyId };
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 ticketNumber, ENUM_DEAL_PROPERTY_DOUBLE propertyId)
{
var commandParameters = new ArrayList { ticketNumber, (int)propertyId };
return SendCommand(Mt5CommandType.HistoryDealGetDouble, commandParameters);
}
///
///Returns the requested property of a deal.
///
///Deal ticket.
/// Identifier of a deal property.
public long HistoryDealGetInteger(ulong ticketNumber, ENUM_DEAL_PROPERTY_INTEGER propertyId)
{
var commandParameters = new ArrayList { ticketNumber, (int)propertyId };
return SendCommand(Mt5CommandType.HistoryDealGetInteger, commandParameters);
}
///
///Returns the requested property of a deal.
///
///Deal ticket.
/// Identifier of a deal property.
public string HistoryDealGetString(ulong ticketNumber, ENUM_DEAL_PROPERTY_STRING propertyId)
{
var commandParameters = new ArrayList { ticketNumber, (int)propertyId };
return SendCommand(Mt5CommandType.HistoryDealGetString, commandParameters);
}
///
///Close all open positions.
///
public bool OrderCloseAll()
{
return SendCommand(Mt5CommandType.OrderCloseAll, null);
}
///
///Closes a position with the specified ticket.
///
///Ticket of the closed position.
///Maximal deviation from the current price (in points).
public bool PositionClose(ulong ticket, ulong deviation = ulong.MaxValue)
{
var commandParameters = new ArrayList { ticket, deviation };
return SendCommand(Mt5CommandType.PositionClose, commandParameters);
}
///
/// Opens a position with the specified parameters.
///
/// symbol
/// order type to open position
/// position volume
/// execution price
/// Stop Loss price
/// Take Profit price
/// comment
/// true - successful check of the basic structures, otherwise - false.
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment = "")
{
var commandParameters = new ArrayList { symbol, (int) orderType, volume, price, sl, tp, comment };
return SendCommand(Mt5CommandType.PositionOpen, commandParameters);
}
///
/// Opens a position with the specified parameters.
///
/// symbol
/// order type to open position
/// position volume
/// execution price
/// Stop Loss price
/// Take Profit price
/// comment
/// output result
/// true - successful check of the basic structures, otherwise - false.
public bool PositionOpen(string symbol, ENUM_ORDER_TYPE orderType, double volume, double price, double sl, double tp, string comment , out MqlTradeResult result)
{
Log.Debug($"PositionOpen: symbol = {symbol}, orderType = {orderType}, volume = {volume}, price = {price}, sl = {sl}, tp = {tp}, comment = {comment}");
var response = SendRequest(new PositionOpenRequest
{
Symbol = symbol,
OrderType = orderType,
Volume = volume,
Price = price,
Sl = sl,
Tp = tp,
Comment = comment
});
result = response?.TradeResult;
return response != null && response.RetVal;
}
#endregion
#region Account Information functions
///
///Returns the value of the corresponding account property.
///
///Identifier of the property.
public double AccountInfoDouble(ENUM_ACCOUNT_INFO_DOUBLE propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
return SendCommand(Mt5CommandType.AccountInfoDouble, commandParameters);
}
///
///Returns the value of the corresponding account property.
///
///Identifier of the property.
public long AccountInfoInteger(ENUM_ACCOUNT_INFO_INTEGER propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
return SendCommand(Mt5CommandType.AccountInfoInteger, commandParameters);
}
///
///Returns the value of the corresponding account property.
///
///Identifier of the property.
public string AccountInfoString(ENUM_ACCOUNT_INFO_STRING propertyId)
{
var commandParameters = new ArrayList { (int)propertyId };
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 long SeriesInfoInteger(string symbolName, ENUM_TIMEFRAMES timeframe, ENUM_SERIES_INFO_INTEGER propId)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, (int)propId };
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 symbolName, ENUM_TIMEFRAMES timeframe)
{
var commandParameters = new ArrayList { symbolName, (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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
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 indicatorHandle)
{
var commandParameters = new ArrayList { indicatorHandle };
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 indicatorHandle, int bufferNum, int startPos, int count, out double[] buffer)
{
var commandParameters = new ArrayList { indicatorHandle, bufferNum, startPos, count };
buffer = SendCommand(Mt5CommandType.CopyBuffer, commandParameters);
return 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 indicatorHandle, int bufferNum, DateTime startTime, int count, out double[] buffer)
{
var commandParameters = new ArrayList { indicatorHandle, bufferNum, Mt5TimeConverter.ConvertToMtTime(startTime), count };
buffer = SendCommand(Mt5CommandType.CopyBuffer1, commandParameters);
return 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 indicatorHandle, int bufferNum, DateTime startTime, DateTime stopTime, out double[] buffer)
{
var commandParameters = new ArrayList { indicatorHandle, bufferNum, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
buffer = SendCommand(Mt5CommandType.CopyBuffer1, commandParameters);
return buffer?.Length ?? 0;
}
///
///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray 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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out MqlRates[] ratesArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
ratesArray = null;
var retVal = SendCommand(Mt5CommandType.CopyRates, commandParameters);
if (retVal != null)
{
ratesArray = new MqlRates[retVal.Length];
for(var i = 0; i < retVal.Length; i++)
{
ratesArray[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 ratesArray?.Length ?? 0;
}
///
///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray 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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out MqlRates[] ratesArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
ratesArray = null;
var retVal = SendCommand(Mt5CommandType.CopyRates1, commandParameters);
if (retVal != null)
{
ratesArray = new MqlRates[retVal.Length];
for (var i = 0; i < retVal.Length; i++)
{
ratesArray[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 ratesArray?.Length ?? 0;
}
///
///Gets history data of MqlRates structure of a specified symbol-period in specified quantity into the ratesArray 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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out MqlRates[] ratesArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
ratesArray = null;
var retVal = SendCommand(Mt5CommandType.CopyRates2, commandParameters);
if (retVal != null)
{
ratesArray = new MqlRates[retVal.Length];
for (var i = 0; i < retVal.Length; i++)
{
ratesArray[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 ratesArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out DateTime[] timeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
timeArray = null;
var retVal = SendCommand(Mt5CommandType.CopyTime, commandParameters);
if (retVal != null)
{
timeArray = new DateTime[retVal.Length];
for (var i = 0; i < retVal.Length; i++)
{
timeArray[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]);
}
}
return timeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out DateTime[] timeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
timeArray = null;
var retVal = SendCommand(Mt5CommandType.CopyTime1, commandParameters);
if (retVal != null)
{
timeArray = new DateTime[retVal.Length];
for (var i = 0; i < retVal.Length; i++)
{
timeArray[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]);
}
}
return timeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out DateTime[] timeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
timeArray = null;
var retVal = SendCommand(Mt5CommandType.CopyTime2, commandParameters);
if (retVal != null)
{
timeArray = new DateTime[retVal.Length];
for (var i = 0; i < retVal.Length; i++)
{
timeArray[i] = Mt5TimeConverter.ConvertFromMtTime(retVal[i]);
}
}
return timeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] openArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
openArray = SendCommand(Mt5CommandType.CopyOpen, commandParameters);
return openArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] openArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
openArray = SendCommand(Mt5CommandType.CopyOpen1, commandParameters);
return openArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] openArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
openArray = SendCommand(Mt5CommandType.CopyOpen2, commandParameters);
return openArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] highArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
highArray = SendCommand(Mt5CommandType.CopyHigh, commandParameters);
return highArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] highArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
highArray = SendCommand(Mt5CommandType.CopyHigh1, commandParameters);
return highArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] highArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
highArray = SendCommand(Mt5CommandType.CopyHigh2, commandParameters);
return highArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] lowArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
lowArray = SendCommand(Mt5CommandType.CopyLow, commandParameters);
return lowArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] lowArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
lowArray = SendCommand(Mt5CommandType.CopyLow1, commandParameters);
return lowArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] lowArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
lowArray = SendCommand(Mt5CommandType.CopyLow2, commandParameters);
return lowArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out double[] closeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
closeArray = SendCommand(Mt5CommandType.CopyClose, commandParameters);
return closeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out double[] closeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
closeArray = SendCommand(Mt5CommandType.CopyClose1, commandParameters);
return closeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out double[] closeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
closeArray = SendCommand(Mt5CommandType.CopyClose2, commandParameters);
return closeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out long[] volumeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
volumeArray = SendCommand(Mt5CommandType.CopyTickVolume, commandParameters);
return volumeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out long[] volumeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
volumeArray = SendCommand(Mt5CommandType.CopyTickVolume1, commandParameters);
return volumeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out long[] volumeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
volumeArray = SendCommand(Mt5CommandType.CopyTickVolume2, commandParameters);
return volumeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out long[] volumeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
volumeArray = SendCommand(Mt5CommandType.CopyRealVolume, commandParameters);
return volumeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out long[] volumeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
volumeArray = SendCommand(Mt5CommandType.CopyRealVolume1, commandParameters);
return volumeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out long[] volumeArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
volumeArray = SendCommand(Mt5CommandType.CopyRealVolume2, commandParameters);
return volumeArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, int startPos, int count, out int[] spreadArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, startPos, count };
spreadArray = SendCommand(Mt5CommandType.CopySpread, commandParameters);
return spreadArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, int count, out int[] spreadArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), count };
spreadArray = SendCommand(Mt5CommandType.CopySpread1, commandParameters);
return spreadArray?.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 symbolName, ENUM_TIMEFRAMES timeframe, DateTime startTime, DateTime stopTime, out int[] spreadArray)
{
var commandParameters = new ArrayList { symbolName, (int)timeframe, Mt5TimeConverter.ConvertToMtTime(startTime), Mt5TimeConverter.ConvertToMtTime(stopTime) };
spreadArray = SendCommand(Mt5CommandType.CopySpread2, commandParameters);
return spreadArray?.Length ?? 0;
}
///
///The function receives ticks in the MqlTick format into ticks_array. In this case, ticks are indexed from the past to the present, i.e. the 0 indexed tick is the oldest one in the array. For tick analysis, check the flags field, which shows what exactly has changed in the tick.
///
///Symbol name.
///The flag that determines the type of received ticks.
///The date from which you want to request ticks. In milliseconds since 1970.01.01. If from=0, the last count ticks will be returned.
///The number of ticks that you want to receive. If the 'from' and 'count' parameters are not specified, all available recent ticks (but not more than 2000) will be written to result.
///
public List CopyTicks(string symbolName, CopyTicksFlag flags = CopyTicksFlag.All, ulong from = 0, uint count = 0)
{
var response = SendRequest>(new CopyTicksRequest
{
SymbolName = symbolName,
Flags = (int)flags,
From = from,
Count = count
});
return response;
}
///
///The function returns the handle of a specified technical indicator created based on the array of parameters of MqlParam type.
///
///Name of a symbol, on data of which the indicator is calculated. NULL means the current symbol.
///The value of the timeframe can be one of values of the ENUM_TIMEFRAMES enumeration, 0 means the current timeframe.
///Indicator type, can be one of values of the ENUM_INDICATOR enumeration.
///An array of MqlParam type, whose elements contain the type and value of each input parameter of a technical indicator.
public int IndicatorCreate(string symbol, ENUM_TIMEFRAMES period, ENUM_INDICATOR indicatorType, List parameters = null)
{
var response = SendRequest(new IndicatorCreateRequest
{
Symbol = symbol,
Period = period,
IndicatorType = indicatorType,
Parameters = parameters
});
return response;
}
public bool IndicatorRelease(int indicatorHandle)
{
var commandParameters = new ArrayList { indicatorHandle };
return SendCommand(Mt5CommandType.IndicatorRelease, commandParameters);
}
#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 symbolName, bool selected)
{
var commandParameters = new ArrayList { symbolName, 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 symbolName)
{
var commandParameters = new ArrayList { symbolName };
return SendCommand(Mt5CommandType.SymbolIsSynchronized, commandParameters);
}
///
///Returns the corresponding property of a specified symbol.
///
///Symbol name.
///Identifier of a symbol property.
public double SymbolInfoDouble(string symbolName, ENUM_SYMBOL_INFO_DOUBLE propId)
{
var commandParameters = new ArrayList { symbolName, (int)propId };
return SendCommand(Mt5CommandType.SymbolInfoDouble, commandParameters);
}
///
///Returns the corresponding property of a specified symbol.
///
///Symbol name.
///Identifier of a symbol property.
public long SymbolInfoInteger(string symbolName, ENUM_SYMBOL_INFO_INTEGER propId)
{
var commandParameters = new ArrayList { symbolName, (int)propId };
return SendCommand(Mt5CommandType.SymbolInfoInteger, commandParameters);
}
///
///Returns the corresponding property of a specified symbol.
///
///Symbol name.
///Identifier of a symbol property.
public string SymbolInfoString(string symbolName, ENUM_SYMBOL_INFO_STRING propId)
{
var commandParameters = new ArrayList { symbolName, (int)propId };
return SendCommand(Mt5CommandType.SymbolInfoString, commandParameters);
}
///
///Returns the corresponding property of a specified symbol.
///
///Symbol name.
///Identifier of a symbol property.
///Variable of the string type receiving the value of the requested property.
public bool SymbolInfoString(string symbolName, ENUM_SYMBOL_INFO_STRING propId, out string value)
{
var response = SendRequest(new SymbolInfoStringRequest
{
SymbolName = symbolName,
PropId = propId
});
value = response?.StringVar;
return response?.RetVal ?? false;
}
///
///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 { MtTime = retVal.time, ask = retVal.ask, bid = retVal.bid, last = retVal.last, volume = 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 dayOfWeek, uint sessionIndex, out DateTime from, out DateTime to)
{
var commandParameters = new ArrayList { name, (int)dayOfWeek, sessionIndex };
string strResult = SendCommand(Mt5CommandType.SymbolInfoSessionQuote, commandParameters);
return strResult.ParseResult(ParamSeparator, 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 dayOfWeek, uint sessionIndex, out DateTime from, out DateTime to)
{
var commandParameters = new ArrayList { name, (int)dayOfWeek, sessionIndex };
string strResult = SendCommand(Mt5CommandType.SymbolInfoSessionTrade, commandParameters);
return strResult.ParseResult(ParamSeparator, 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 response = SendRequest>(new MarketBookGetRequest
{
Symbol = symbol
});
book = response?.ToArray();
return response != null;
}
#endregion
#region Chart Operations
///
///Returns the ID of the current chart.
///
///
/// Value of long type.
///
public long ChartId()
{
return SendCommand(Mt5CommandType.ChartId, null);
}
///
///This function calls a forced redrawing of a specified chart.
///
///Chart ID. 0 means the current chart.
public void ChartRedraw(long chartId = 0)
{
var commandParameters = new ArrayList { chartId };
SendCommand