Trade Functions in MQL4

This post contains affiliate links. If you use these links to register at one of the trusted brokers, I may earn a commission. This helps me to create more free content for you. Thanks!
Trade Functions will be probably the most important part of the code when creating any automated strategy in MQ4. Let’s look at the list of all trade functions and their description:
Execution Errors | Any trade operation (OrderSend, OrderClose, OrderCloseBy, OrderDelete or OrderModify functions) can unsuccessfully end for a score of reasons and return either the negative ticket number or FALSE. You can find out the reason of failure by using the GetLastError function. Every error should be processed in its own way. The table below contains the general recommendations. |
OrderClose | It closes position. It returns TRUE, if the function has ended successfully. It returns FALSE, if the function fails to end. |
OrderCloseBy | It closes one open position with the other that is opened in the opposite direction for the same symbol. It returns TRUE. if the function has ended successfully. It returns FALSE, if the function fails to end. |
OrderClosePrice | It returns the close price of the selected order. |
OrderCloseTime | It returns the time of closing for the selected order. |
OrderComment | It returns the comment of the selected order. |
OrderCommission | It returns the calculated commission value of the selected order. |
OrderDelete | It deletes the previously placed pending order. It returns TRUE, if the function has ended successfully. It returns FALSE, if the function fails to end. |
OrderExpiration | It returns the date of expiration of the selected pending order. |
OrderLots | It returns the amount of lots of the selected order. |
OrderMagicNumber | It returns the identifying (“magic”) number of the selected order. |
OrderModify | It modifies the parameters of the previously opened orders and pending orders. It returns TRUE if the function has ended successfully. It returns FALSE, if the function fails to end. |
OrderOpenPrice | It returns the open price of the selected order. |
OrderOpenTime | It returns the opening time of the selected order. |
OrderPrint | It enters the order information to the journal. |
OrderProfit | It returns the net profit (without regard to swaps and commissions) of the selected order. It is the unrealized profit for the opened orders and fixed profit for the closed orders. |
OrderSelect | The function chooses the order to work with subsequently. It returns TRUE if the function has ended successfully. It returns FALSE, if the function fails to end. |
OrderSend | The main function for opening orders and placing pending orders. It returns the number of the ticket that was assigned to the order by the trade server, or -1, in case of failing to end the operation. |
OrdersHistoryTotal | It returns the number of closed positions and deleted orders in the history of the current account, loaded to the client terminal. |
OrderStopLoss | It returns close price of the position when it reaches the loss level (stop loss) of the currently selected order. |
OrdersTotal | It returns the total number of open and pending orders. |
OrderSwap | It returns the swap value of the currently selected order. |
OrderSymbol | It returns the symbol name for the currently selected order. |
OrderTakeProfit | It returns the close price when it reaches the profit level (take profit) of the currently selected order. |
OrderTicket | It returns the ticket number of the currently selected order. |
OrderType | It returns the operation type of the currently selected order. |
The basic application of the most common trade functions can be found in the post: Basics of Trade Management in MQ4.
Still, have no trading account yet? Open an account at one of my trusted brokers suitable for algorithmic trading completely for free and start testing today!

This post contains affiliate links. If you use these links to register at one of the trusted brokers, I may earn a commission. This helps me to create more free content for you. Thanks!