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