|
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
|
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 Limit 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 |
position |
Ticket of a position. Should be filled in when a position is modified or closed to identify the position. As a rule it is equal to the ticket of the order, based on which the position was opened. |
position_by |
Ticket of an opposite position. Used when a position is closed by an opposite one open for the same symbol in the opposite direction. |
When modifying or closing a position in the hedging system, make sure to specify its ticket (MqlTradeRequest::position). The ticket can also be specified in the netting system, though a position is identified by the symbol name. |
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 requested prices). 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 current 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.
Exchange Execution
This is a trade order to open a position in the Exchange Execution mode. It requires to specify the following 5 fields:
Also it is possible to specify the "magic" and "comment" field values.
Example of the TRADE_ACTION_DEAL trade operation for opening a Buy position:
#define EXPERT_MAGIC 123456 // MagicNumber of the expert |
Example of the TRADE_ACTION_DEAL trade operation for opening a Sell position:
#define EXPERT_MAGIC 123456 // MagicNumber of the expert |
Example of the TRADE_ACTION_DEAL trade operation for closing positions:
#define EXPERT_MAGIC 123456 // MagicNumber of the expert |
SL & TP Modification
Trade order to modify the StopLoss and/or TakeProfit price levels. It requires to specify the following 4 fields:
Example of the TRADE_ACTION_SLTP trade operation for modifying the Stop Loss and Take Profit values of an open position:
#define EXPERT_MAGIC 123456 // MagicNumber of the expert |
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.
Example of the TRADE_ACTION_PENDING trade operation for placing a pending order:
#property description "Example of placing pending orders" |
Modify Pending Order
Trade order to modify the prices of a pending order. It requires to specify the following 7 fields:
Example of the TRADE_ACTION_MODIFY trade operation for modifying the price levels of pending orders:
#define EXPERT_MAGIC 123456 // MagicNumber of the expert |
Delete Pending Order
Trade order to delete a pending order. It requires to specify the following 2 fields:
Example of the TRADE_ACTION_REMOVE trade operation for deleting pending orders:
#define EXPERT_MAGIC 123456 // MagicNumber of the expert
|
See also