GetOrderType
Syntax
GetOrderType(): TTradePositionTypeReturn Value
Description
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
Last updated