GetActiveOrderCount
Syntax
GetActiveOrderCount(): numberReturn Value
Description
Example
// Get the number of active orders
const activeCount = this.api.GetActiveOrderCount();
console.log(`Total active orders: ${activeCount}`);
// Check if there's room for more orders
const maxAllowedPositions = 5;
if (activeCount < maxAllowedPositions) {
// Place a new order
this.api.PlaceOrder(
"EURUSD",
TTradePositionType.BUY,
0, // Market order (price = 0)
1.0, // Lot size
1.1, // Stop loss
1.15, // Take profit
"Strategy order",
12345 // Magic number
);
} else {
console.log("Maximum allowed positions reached");
}
// Iterate through active orders
for (let i = 0; i < activeCount; i++) {
if (this.api.SelectOrder(i, EOrderSelectMode.SELECT_ORDER_BY_POS)) {
const ticket = this.api.GetOrderTicket();
const type = this.api.GetOrderType();
console.log(`Active order #${ticket}, type: ${type}`);
}
}Notes
Last updated