PlaceOrder

Places a new trading order.

Syntax

PlaceOrder(
  symbol: string,
  orderType: TTradePositionType,
  lotSize: number,
  price: number,
  slippage: number,
  stopLoss: number,
  takeProfit: number,
  comment: string,
  magicNumber: number
): number

Parameters

  • symbol: The trading symbol (currency pair) for the order (e.g., "EURUSD").

  • orderType: The type of order to place (TTradePositionType.BUY or TTradePositionType.SELL).

  • lotSize: The volume of the order in lots.

  • price: The price at which to execute the order.

  • slippage: Maximum allowed price deviation for market orders (in points).

  • stopLoss: Stop loss level for the order (0 for no stop loss).

  • takeProfit: Take profit level for the order (0 for no take profit).

  • comment : A comment to attach to the order.

  • magicNumber : A unique identifier for the order to distinguish orders placed by different strategies.

Return Value

Returns a number representing the ticket number of the placed order. If the order placement fails, returns 0 or a negative value.

Description

The PlaceOrder method creates and submits a new trading order to the trading server. The order can be either a buy (long) or sell (short) position. You can specify various order parameters including stop loss and take profit levels, as well as optional metadata like comments and magic numbers.

Example

Last updated