GetHistoricalOrderCount

Returns the number of closed orders in the history.

Syntax

GetHistoricalOrderCount(): number

Return Value

Returns a number representing the total count of closed orders in the history.

Description

The GetHistoricalOrderCount method returns the total number of orders that have been closed and are now in the order history. This includes all orders that were previously opened and have since been closed, regardless of their outcome (profit, loss, or breakeven).

This method can be useful for various statistical analyses, such as calculating win/loss ratios or tracking trading activity over time.

Example

// Get the number of historical orders
const historyCount = this.api.GetHistoricalOrderCount();
console.log(`Total historical orders: ${historyCount}`);

// Iterate through historical orders
for (let i = 0; i < historyCount; i++) {
  if (
    this.api.selectOrder(
      i,
      EOrderSelectMode.SELECT_ORDER_BY_POS,
      TSearchMode.DATA_MODE_HISTORY
    )
  ) {
    const ticket = this.api.GetOrderTicket();
    const profit = this.api.GetOrderProfit();

    console.log(`Historical order #${ticket} had a profit of ${profit}`);
  }
}

Notes

  • This method only counts orders that have been closed and are in the history.

  • To count active/open orders, use the GetActiveOrderCount method.

  • The count includes all types of closed orders (market and pending).

Last updated