GetOrderStopLoss

Returns the stop loss level of the currently selected order.

Syntax

GetOrderStopLoss(): number

Return Value

Returns a number representing the stop loss price level of the selected order.

Description

The GetOrderStopLoss method returns the stop loss price level that was set for the currently selected order. The stop loss is a price level at which the order will be automatically closed to limit potential losses.

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 details
  const symbol = this.api.GetOrderSymbol();
  const type = this.api.GetOrderType();
  const openPrice = this.api.GetOrderOpenPrice();
  const stopLoss = this.api.GetOrderStopLoss();
  const takeProfit = this.api.GetOrderTakeProfit();

  console.log(`Order #12345 on ${symbol}:`);
  console.log(`- Type: ${type === TTradePositionType.BUY ? "Buy" : "Sell"}`);
  console.log(`- Open Price: ${openPrice}`);
  console.log(`- Stop Loss: ${stopLoss}`);
  console.log(`- Take Profit: ${takeProfit}`);
}

Notes

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

  • You can use this method to determine if an order has a stop loss by checking if the returned value is greater than 0.

Last updated