CloseOrderByOpposite
Closes two opposing orders for the same symbol against each other.
Syntax
CloseOrderByOpposite(orderTicket1: number, orderTicket2: number): booleanParameters
orderTicket1: The ticket number of the first order.orderTicket2: The ticket number of the second order, which must be of the opposite type to the first order.
Return Value
Returns a boolean value indicating whether the orders were successfully closed against each other.
true: Orders were successfully closed.false: Failed to close the orders.
Description
The CloseOrderByOpposite method closes two opposing positions (one buy and one sell) for the same symbol against each other. This is useful for hedging strategies or when you want to close offsetting positions in a specific manner.
For this method to work correctly, the orders must:
Be on the same symbol (currency pair)
Have opposite types (one BUY and one SELL)
When executed successfully, both orders are closed, profit/loss is calculated and applied to the account balance, and the orders are moved to the order history.
Example
Notes
Both orders must exist and be active.
Orders must be on the same symbol (currency pair).
One order must be a buy (long) position and the other must be a sell (short) position.
This method is particularly useful for hedging strategies or for unwinding opposing positions in a controlled manner.
Last updated