MQL4 Reference Trade Functions

Trade Functions

This is the group of functions intended for managing trading activities.

Trading functions can be used in Expert Advisors and scripts. OrderSend(), OrderClose(), OrderCloseBy(), OrderModify(), OrderDelete() trading functions changing the state of a trading account can be called only if trading by Expert Advisors is allowed (the "Allow live trading" checkbox is enabled in the Expert Advisor or script properties).

Trading can be allowed or prohibited depending on various factors described in the Trade Permission section.

Function

Action

OrderClose

Closes opened order

OrderCloseBy

Closes an opened order by another opposite opened order

OrderClosePrice

Returns close price of the currently selected order

OrderCloseTime

Returns close time of the currently selected order

OrderComment

Returns comment of the currently selected order

OrderCommission

Returns calculated commission of the currently selected order

OrderDelete

Deletes previously opened pending order

OrderExpiration

Returns expiration date of the selected pending order

OrderLots

Returns amount of lots of the selected order

OrderMagicNumber

Returns an identifying (magic) number of the currently selected order

OrderModify

Modification of characteristics of the previously opened or pending orders

OrderOpenPrice

Returns open price of the currently selected order

OrderOpenTime

Returns open time of the currently selected order

OrderPrint

Prints information about the selected order in the log

OrderProfit

Returns profit of the currently selected order

OrderSelect

The function selects an order for further processing

OrderSend

The main function used to open an order or place a pending order

OrdersHistoryTotal

Returns the number of closed orders in the account history loaded into the terminal

OrderStopLoss

Returns stop loss value of the currently selected order

OrdersTotal

Returns the number of market and pending orders

OrderSwap

Returns swap value of the currently selected order

OrderSymbol

Returns symbol name of the currently selected order

OrderTakeProfit

Returns take profit value of the currently selected order

OrderTicket

Returns ticket number of the currently selected order

OrderType

Returns order operation type of the currently selected order

 

What's new in MQL5

Added the functions for working with orders, deals and positions to conduct trading operations. An order is a request to buy or sell. The order execution leads to a deal resulting in opening, modifying or closing a position.

If you develop trading robots, pay attention to the new OrderSendAsync function intended for asynchronous trading operations. This function is executed in less than 1 millisecond (it does not wait till the trade server responds to a sent request) and returns control immediately. Low network costs, high Depth of Market refresh rates and asynchronous order sending accelerate trading operations dozens of times. For intraday systems, the speed of trading operations can be a key factor.