GetOrderType

Returns the type of the currently selected order.

Syntax

GetOrderType(): TTradePositionType

Return Value

Returns a TTradePositionType enum value representing the type of the currently selected order:

  • TTradePositionType.BUY: A buy (long) position

  • TTradePositionType.SELL: A sell (short) position

Description

The GetOrderType method returns the type of the currently selected order, indicating whether it's a buy (long) or sell (short) position. This information is essential for implementing logic that depends on the direction of the trade, such as calculating proper stop loss and take profit levels, or determining if a specific market condition is favorable for the position.

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 type
  const orderType = this.api.GetOrderType();

  // Apply different logic based on order type
  if (orderType === TTradePositionType.BUY) {
    console.log("Order #12345 is a BUY position");
    // Logic for processing buy positions

    // For a buy position, price needs to go up for profit
    const currentPrice = this.api.GetSymbolNumberProperty(this.api.Symbol(), ENUM_SYMBOL_INFO_NUMBER.SYMBOL_PRICE_BID);
    const openPrice = this.api.GetOrderOpenPrice();
    const point = this.api.GetSymbolNumberProperty(this.api.Symbol(), ENUM_SYMBOL_INFO_NUMBER.SYMBOL_POINT_VALUE);
    const profitPips = (currentPrice - openPrice) / point / 10;
  } else {
    console.log("Order #12345 is a SELL position");
    // Logic for processing sell positions

    // For a sell position, price needs to go down for profit
    const currentPrice = this.api.GetSymbolNumberProperty(this.api.Symbol(), ENUM_SYMBOL_INFO_NUMBER.SYMBOL_PRICE_ASK);
    const openPrice = this.api.GetOrderOpenPrice();
    const point = this.api.GetSymbolNumberProperty(this.api.Symbol(), ENUM_SYMBOL_INFO_NUMBER.SYMBOL_POINT_VALUE);
    const profitPips = (openPrice - currentPrice) / point / 10;
}
    console.log(`Current profit: ${profitPips} pips`);
  }
}

Notes

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

  • This method returns the position type (BUY or SELL) and does not distinguish between market orders, limit orders, stop orders, etc. For that information, you would need to check additional properties of the order.

Last updated