GetOrderProfit

Returns the current profit of the selected order in account currency.

Syntax

GetOrderProfit(): number

Return Value

Returns a number representing the current profit or loss (in account currency) of the selected order.

Description

The GetOrderProfit method returns the current profit or loss for the currently selected order in the account's base currency.

Before using this method, you must first select an order using the SelectOrder method.

Example

// Select an order by ticket number
if (this.api.SelectOrder(12345, EOrderSelectMode.SELECT_ORDER_BY_TICKET)) {
  // Get the order profit
  const profit = this.api.GetOrderProfit();

  // Check if the trade is profitable
  if (profit > 0) {
    console.log(`Order #12345 is in profit: ${profit.toFixed(2)}`);
  } else if (profit < 0) {
    console.log(`Order #12345 is in loss: ${profit.toFixed(2)}`);
  } else {
    console.log(`Order #12345 is at breakeven`);
  }

  // Get order volume for calculating profit per lot
  const volume = this.api.GetOrderVolume();
  const profitPerLot = volume > 0 ? profit / volume : 0;

  console.log(`Profit per lot: ${profitPerLot.toFixed(2)}`);
}

Notes

  • An order must be selected first using SelectOrder before calling this method.

Last updated