Skip to content

Order Properties

Order Properties

Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions OrderGet…() and HistoryOrderGet…().

For functions OrderGetInteger() and HistoryOrderGetInteger()

ENUM_ORDER_PROPERTY_INTEGER

IdentifierDescriptionType
ORDER_TICKETOrder ticket. Unique number assigned to each orderlong
ORDER_TIME_SETUPOrder setup timedatetime
ORDER_TYPEOrder typeENUM_ORDER_TYPE
ORDER_STATEOrder stateENUM_ORDER_STATE
ORDER_TIME_EXPIRATIONOrder expiration timedatetime
ORDER_TIME_DONEOrder execution or cancellation timedatetime
ORDER_TIME_SETUP_MSCThe time of placing an order for execution in milliseconds since 01.01.1970long
ORDER_TIME_DONE_MSCOrder execution/cancellation time in milliseconds since 01.01.1970long
ORDER_TYPE_FILLINGOrder filling typeENUM_ORDER_TYPE_FILLING
ORDER_TYPE_TIMEOrder lifetimeENUM_ORDER_TYPE_TIME
ORDER_MAGICID of an Expert Advisor that has placed the order (designed to ensure that each Expert Advisor places its own unique number)long
ORDER_REASONThe reason or source for placing an orderENUM_ORDER_REASON
ORDER_POSITION_IDPosition identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of exactly this position is set to the executed order at this moment.long
ORDER_POSITION_BY_IDIdentifier of an opposite position used for closing by order ORDER_TYPE_CLOSE_BYlong

For functions OrderGetDouble() and HistoryOrderGetDouble()

ENUM_ORDER_PROPERTY_DOUBLE

IdentifierDescriptionType
ORDER_VOLUME_INITIALOrder initial volumedouble
ORDER_VOLUME_CURRENTOrder current volumedouble
ORDER_PRICE_OPENPrice specified in the orderdouble
ORDER_SLStop Loss valuedouble
ORDER_TPTake Profit valuedouble
ORDER_PRICE_CURRENTThe current price of the order symboldouble
ORDER_PRICE_STOPLIMITThe Limit order price for the StopLimit orderdouble

For functions OrderGetString() and HistoryOrderGetString()

ENUM_ORDER_PROPERTY_STRING

IdentifierDescriptionType
ORDER_SYMBOLSymbol of the orderstring
ORDER_COMMENTOrder commentstring
ORDER_EXTERNAL_IDOrder identifier in an external trading system (on the Exchange)string

When sending a trade request using the OrderSend() function, some operations require the indication of the order type. The order type is specified in the type field of the special structure MqlTradeRequest, and can accept values of the ENUM_ORDER_TYPE enumeration.

ENUM_ORDER_TYPE

IdentifierDescription
ORDER_TYPE_BUYMarket Buy order
ORDER_TYPE_SELLMarket Sell order
ORDER_TYPE_BUY_LIMITBuy Limit pending order
ORDER_TYPE_SELL_LIMITSell Limit pending order
ORDER_TYPE_BUY_STOPBuy Stop pending order
ORDER_TYPE_SELL_STOPSell Stop pending order
ORDER_TYPE_BUY_STOP_LIMITUpon reaching the order price, a pending Buy Limit order is placed at the StopLimit price
ORDER_TYPE_SELL_STOP_LIMITUpon reaching the order price, a pending Sell Limit order is placed at the StopLimit price
ORDER_TYPE_CLOSE_BYOrder to close a position by an opposite one

Each order has a status that describes its state. To obtain information, use OrderGetInteger() or HistoryOrderGetInteger() with the ORDER_STATE modifier. Allowed values are stored in the ENUM_ORDER_STATE enumeration.

ENUM_ORDER_STATE

IdentifierDescription
ORDER_STATE_STARTEDOrder checked, but not yet accepted by broker
ORDER_STATE_PLACEDOrder accepted
ORDER_STATE_CANCELEDOrder canceled by client
ORDER_STATE_PARTIALOrder partially executed
ORDER_STATE_FILLEDOrder fully executed
ORDER_STATE_REJECTEDOrder rejected
ORDER_STATE_EXPIREDOrder expired
ORDER_STATE_REQUEST_ADDOrder is being registered (placing to the trading system)
ORDER_STATE_REQUEST_MODIFYOrder is being modified (changing its parameters)
ORDER_STATE_REQUEST_CANCELOrder is being deleted (deleting from the trading system)

When sending a trade request for execution at the current time (time in force), the price and the required buy/sell volume should be specified. Also, keep in mind that financial markets provide no guarantee that the entire requested volume is available for a certain financial instrument at the desired price. Therefore, trading operations in real time are regulated using the price and volume execution modes. The modes, or execution policies, define the rules for cases when the price has changed or the requested volume cannot be completely fulfilled at the moment.

Price execution mode can be obtained from the SYMBOL_TRADE_EXEMODE symbol property containing the combination of flags from the ENUM_SYMBOL_TRADE_EXECUTION enumeration.

Execution modeDescriptionThe value in ENUM_SYMBOL_TRADE_EXECUTION
Execution mode
(Request Execution)
Executing a market order at the price previously received from the broker.
Prices for a certain market order are requested from the broker before the order is sent. Upon receiving the prices, order execution at the given price can be either confirmed or rejected.
SYMBOL_TRADE_EXECUTION_REQUEST
Instant Execution
(Instant Execution)
Executing a market order at the specified price immediately.
When sending a trade request to be executed, the platform automatically adds the current prices to the order.
- If the broker accepts the price, the order is executed.
- If the broker does not accept the requested price, a “Requote” is sent — the broker returns prices, at which this order can be executed.
SYMBOL_TRADE_EXECUTION_INSTANT
Market Execution
(Market Execution)
A broker makes a decision about the order execution price without any additional discussion with the trader.
Sending the order in such a mode means advance consent to its execution at this price.
SYMBOL_TRADE_EXECUTION_MARKET
Exchange Execution
(Exchange Execution)
Trade operations are executed at the prices of the current market offers.SYMBOL_TRADE_EXECUTION_EXCHANGE

Volume filling policy is specified in the ORDER_TYPE_FILLING order property and may contain only the values from the ENUM_ORDER_TYPE_FILLING enumeration

Fill policyDescriptionThe value in ENUM_ORDER_TYPE_FILLING
Fill or KillAn order can be executed in the specified volume only.
If the necessary amount of a financial instrument is currently unavailable in the market, the order will not be executed.
The desired volume can be made up of several available offers.
The possibility of using FOK orders is determined at the trade server.
ORDER_FILLING_FOK
Immediate or CancelA trader agrees to execute a deal with the volume maximally available in the market within that indicated in the order.
If the request cannot be filled completely, an order with the available volume will be executed, and the remaining volume will be canceled.
The possibility of using IOC orders is determined at the trade server.
ORDER_FILLING_IOC
Passive (Book or Cancel)The BoC order assumes that the order can only be placed in the Depth of Market and cannot be immediately executed. If the order can be executed immediately when placed, then it is canceled.
In fact, the BOC policy guarantees that the price of the placed order will be worse than the current market. BoC orders are used to implement passive trading, so that the order is not executed immediately when placed and does not affect current liquidity.
Only limit and stop limit orders are supported (ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP_LIMIT, ORDER_TYPE_SELL_STOP_LIMIT).
ORDER_FILLING_BOC
ReturnIn case of partial filling, an order with remaining volume is not canceled but processed further.
Return orders are not allowed in the Market Execution mode (market execution — SYMBOL_TRADE_EXECUTION_MARKET).
ORDER_FILLING_RETURN

When sending a trade request using the OrderSend() function, the necessary volume execution policy can be set in the type_filling field, namely in the special MqlTradeRequest structure. The values from the ENUM_ORDER_TYPE_FILLING enumeration are available. To get the property value in a specific active/completed order, use the OrderGetInteger() or HistoryOrderGetInteger() function with the ORDER_TYPE_FILLING modifier.

Before sending an order with the current execution time, for the correct setting of the ORDER_TYPE_FILLING value (volume execution type), you can use the SymbolInfoInteger() function with each financial instrument to get the SYMBOL_FILLING_MODE property value, which shows volume execution types allowed for the symbol as a combination of flags. The ORDER_FILLING_RETURN filling type is enabled at all times except for the “Market execution” mode (SYMBOL_TRADE_EXECUTION_MARKET).

The use of filling types depending on the execution mode can be shown as the following table:

Type of Execution\Fill PolicyFill or Kill (FOK ORDER_FILLING_FOK)Immediate or Cancel (IOC ORDER_FILLING_IOC)Return (Return ORDER_FILLING_RETURN)
Instant Execution
(SYMBOL_TRADE_EXECUTION_INSTANT)
+ (regardless of a symbol setting)+ (regardless of a symbol setting)+ (always)
Request Execution
SYMBOL_TRADE_EXECUTION_REQUEST
+ (regardless of a symbol setting)+ (regardless of a symbol setting)+ (always)
Market Execution
SYMBOL_TRADE_EXECUTION_MARKET
+ (set in the symbol settings)+ (set in the symbol settings)- (disabled regardless of the symbol settings)
Exchange Execution
SYMBOL_TRADE_EXECUTION_EXCHANGE
+ (set in the symbol settings)+ (set in the symbol settings)+ (always)

In case of pending orders, the ORDER_FILLING_RETURN filling type should be used regardless of an execution type (SYMBOL_TRADE_EXEMODE), since such orders are not meant for execution at the time of sending. When using pending orders, a trader agrees in advance that, when conditions for a deal on this order are met, the broker will use the filling type supported by the exchange.

The order validity period can be set in the type_time field of the special structure MqlTradeRequest when sending a trade request using the OrderSend() function. Values of the ENUM_ORDER_TYPE_TIME enumeration are allowed. To obtain the value of this property use the function OrderGetInteger() or HistoryOrderGetInteger() with the ORDER_TYPE_TIME modifier.

ENUM_ORDER_TYPE_TIME

IdentifierDescription
ORDER_TIME_GTCGood till cancel order
ORDER_TIME_DAYGood till current trade day order
ORDER_TIME_SPECIFIEDGood till expired order
ORDER_TIME_SPECIFIED_DAYThe order will be effective till 23:59:59 of the specified day. If this time is outside a trading session, the order expires in the nearest trading time.

The reason for order placing is contained in the ORDER_REASON property. An order can be placed by an MQL5 program, from a mobile application, as a result of StopOut, etc. Possible values of ORDER_REASON are described in the ENUM_ORDER_REASON enumeration.

ENUM_ORDER_REASON

IdentifierDescription
ORDER_REASON_CLIENTThe order was placed from a desktop terminal
ORDER_REASON_MOBILEThe order was placed from a mobile application
ORDER_REASON_WEBThe order was placed from a web platform
ORDER_REASON_EXPERTThe order was placed from an MQL5-program, i.e. by an Expert Advisor or a script
ORDER_REASON_SLThe order was placed as a result of Stop Loss activation
ORDER_REASON_TPThe order was placed as a result of Take Profit activation
ORDER_REASON_SOThe order was placed as a result of the Stop Out event
Last updated on