GetActiveOrderCount

Returns the number of active (open) orders.

Syntax

GetActiveOrderCount(): number

Return Value

Returns a number representing the total count of active orders.

Description

The GetActiveOrderCount method returns the total number of currently active orders. This includes all open market positions and pending orders that have not been executed, canceled, or closed.

This method is useful for monitoring the number of active positions, implementing position limits, or performing risk management calculations based on the number of open trades.

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

  • This method counts both open market positions and pending orders.

  • To count closed orders, use the GetHistoricalOrderCount method.

Last updated