index - A number representing the index or ticket number of the order to select.
selectionMode - An EOrderSelectMode value indicating how to interpret the index parameter.
searchMode - (Optional) A TSearchMode value indicating which group of orders to search in. Default is DATA_MODE_TRADES (active orders).
Return Value
Returns a boolean value:
true if the order was successfully selected
false if the order was not found
Description
The SelectOrder method selects an order for further operations. Most order information methods require an order to be selected first before they can be used. This method allows you to select an order either by its position in the list of orders or by its ticket number.
EOrderSelectMode values
TSearchMode values
Example
Notes
This method must be called before using most order information methods.
The order selection is maintained until another order is selected or the strategy execution ends.
To select an order by its ticket number, use EOrderSelectMode.SELECT_ORDER_BY_TICKET.
To select an order by its position in the list, use EOrderSelectMode.SELECT_ORDER_BY_POS.
To select from active orders, use TSearchMode.DATA_MODE_TRADES (default).
To select from historical orders, use TSearchMode.DATA_MODE_HISTORY.
// Select an order by its ticket number
if (this.api.SelectOrder(12345, EOrderSelectMode.SELECT_ORDER_BY_TICKET)) {
// Order successfully selected, now we can get information about it
const profit = this.api.GetOrderProfit();
const volume = this.api.GetOrderVolume();
console.log(`Order #12345 profit: ${profit}, volume: ${volume}`);
} else {
console.log("Order not found");
}
// Select the first historical order
if (
this.api.SelectOrder(
0,
EOrderSelectMode.SELECT_ORDER_BY_POS,
TSearchMode.DATA_MODE_HISTORY
)
) {
// Get information about the first historical order
const symbol = this.api.GetOrderSymbol();
const openPrice = this.api.GetOrderOpenPrice();
console.log(`First historical order: ${symbol} at ${openPrice}`);
}