The Trade Request Structure (MqlTradeRequest)
Interaction between the client terminal and a trade server for executing the order placing operation, is performed by using trade requests. The trade request is represented by the special predefined structure of MqlTradeRequest type, which contain all the fields necessary to perform trade deals. The request processing result is represented by the structure of MqlTradeResult type.
struct MqlTradeRequest
{
ENUM_TRADE_REQUEST_ACTIONS action; // Trade operation type
ulong magic; // Expert Advisor ID (magic number)
ulong order; // Order ticket
string symbol; // Trade symbol
double volume; // Requested volume for a deal in lots
double price; // Price
double stoplimit; // StopLimit level of the order
double sl; // Stop Loss level of the order
double tp; // Take Profit level of the order
ulong deviation; // Maximal possible deviation from the requested price
ENUM_ORDER_TYPE type; // Order type
ENUM_ORDER_TYPE_FILLING type_filling; // Order execution type
ENUM_ORDER_TYPE_TIME type_time; // Order execution time
datetime expiration; // Order expiration time (for the orders of ORDER_TIME_SPECIFIED type)
string comment; // Order comment
};
Fields description
Field |
Description |
action |
Trade operation type. Can be one of the ENUM_TRADE_REQUEST_ACTIONS enumeration values. |
magic |
Expert Advisor ID. It allows organizing analytical processing of trade orders. Each Expert Advisor can set its own unique ID when sending a trade request. |
order |
Order ticket. It is used for modifying pending orders. |
symbol |
Symbol of the order. It is not necessary for order modification and position close operations. |
volume |
Requested order volume in lots. Note that the real volume of a deal will depend on the order execution type. |
price |
Price, reaching which the order must be executed. Market orders of symbols, whose execution type is "Market Execution" (SYMBOL_TRADE_EXECUTION_MARKET), of TRADE_ACTION_DEAL type, do not require specification of price. |
stoplimit |
The price value, at which the StopLimit pending order will be placed, when price reaches the price value (this condition is obligatory). Until then the pending order is not placed). |
sl |
Stop Loss price in case of the unfavorable price movement |
tp |
Take Profit price in the case of the favorable price movement |
deviation |
The maximal price deviation, specified in points |
type |
Order type. Can be one of the ENUM_ORDER_TYPE enumeration values. |
type_filling |
Order execution type. Can be one of the enumeration ENUM_ORDER_TYPE_FILLING values. |
type_time |
Order expiration type. Can be one of the enumeration ENUM_ORDER_TYPE_TIME values. |
expiration |
Order expiration time (for orders of ORDER_TIME_SPECIFIED type) |
comment |
Order comment |
For sending orders to perform trade operations it is necessary to use the OrderSend() function. For each trade operation it is necessary to specify obligatory fields; optional fields also may be filled. There are seven possible cases to send a trade order:
Request Execution
This is a trade order to open a position in the Request Execution mode (trade upon current prices request). It requires to specify the following 9 fields:
Also it is possible to specify the "magic" and "comment" field values.
Instant Execution
This is a trade order to open a position in the Instant Execution mode (trade by flow prices). It requires specification of the following 9 fields:
Also it is possible to specify the "magic" and "comment" field values.
Market Execution
This is a trade order to open a position in the Market Execution mode. It requires to specify the following 5 fields:
Also it is possible to specify the "magic" and "comment" field values.
SL & TP Modification
Trade order to modify the StopLoss and/or TakeProfit price levels. It requires to specify the following 5 fields:
Pending Order
Trade order to place a pending order. It requires to specify the following 11 fields:
Also it is possible to specify the "magic" and "comment" field values.
Modify Pending Order
Trade order to modify the prices of a pending order. It requires to specify the following 7 fields:
Delete Pending Order
Trade order to delete a pending order. It requires to specify the following 2 fields:
See also
Structures and Classes, Trade Functions, Order Properties
© 2000-2010, MetaQuotes Software Corp.