Skip to content

Metatrader trade#

About#

Contains trade command.

Fields#

Name Type Required Description
actionType string Yes action type, enum: ORDER_TYPE_SELL, ORDER_TYPE_BUY, ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT,ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP, POSITION_MODIFY, POSITION_PARTIAL, POSITION_CLOSE_ID,POSITIONS_CLOSE_SYMBOL, ORDER_MODIFY, ORDER_CANCEL, POSITION_CLOSE_BY, ORDER_TYPE_BUY_STOP_LIMIT, ORDER_TYPE_SELL_STOP_LIMIT.
symbol string symbol to trade
volume number order volume
openPrice number order limit or stop price
stopLoss number stop loss price
takeProfit number take profit price
stopLossUnits string stop loss units. ABSOLUTE_PRICE means the that the value of stopLoss field is a final stop loss value. RELATIVE_* means that the stopLoss field value contains relative stop loss expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
takeProfitUnits string take profit units. ABSOLUTE_PRICE means the that the value of takeProfit field is a final take profit value. RELATIVE_* means that the takeProfit field value contains relative take profit expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
orderId string order id, must be specified for order modification commands
positionId string position id, must be specified for position modification commands
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value can be assigned when submitting a trade and will be present on position, history orders and history deals related to the trade. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
expiration object pending order expiration settings. See Pending order expiration settings section.
closeByPositionId string identifier of an opposite position used for closing by order, required in case actionType is POSITION_CLOSE_BY
stopLimitPrice string optional price at which the StopLimit order will be placed. Required for stop limit orders

Pending order expiration settings#

Name Type Required Description
type string Yes pending order expiration type. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_time for the list of possible options. MetaTrader4 platform supports only ORDER_TIME_SPECIFIED expiration type. enum: ORDER_TIME_GTC, ORDER_TIME_DAY, ORDER_TIME_SPECIFIED, ORDER_TIME_SPECIFIED_DAY.
time datetime pending order expiration time. Ignored if expiration type is not one of ORDER_TIME_DAY or ORDER_TIME_SPECIFIED

The following describes schemas for each type of command.

ORDER_TYPE_SELL or ORDER_TYPE_BUY#

Submits market order to the trading terminal

Name Type Required Description
actionType string Yes action type, enum: ORDER_TYPE_SELL, ORDER_TYPE_BUY
symbol string Yes symbol to trade
volume number Yes order volume, min: 0
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
stopLossUnits string stop loss units. ABSOLUTE_PRICE means the that the value of stopLoss field is a final stop loss value. RELATIVE_* means that the stopLoss field value contains relative stop loss expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
takeProfitUnits string take profit units. ABSOLUTE_PRICE means the that the value of takeProfit field is a final take profit value. RELATIVE_* means that the takeProfit field value contains relative take profit expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on position, history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#
{
  "actionType": "ORDER_TYPE_SELL",
  "symbol":"AUDNZD",
  "volume": 0.01,
  "takeProfit": 1.03
}

ORDER_TYPE_BUY_LIMIT or ORDER_TYPE_SELL_LIMIT or ORDER_TYPE_BUY_STOP or ORDER_TYPE_SELL_STOP#

Submits pending order to the trading terminal

Name Type Required Description
actionType string Yes action type, enum: ORDER_TYPE_BUY_LIMIT, ORDER_TYPE_SELL_LIMIT, ORDER_TYPE_BUY_STOP, ORDER_TYPE_SELL_STOP
symbol string Yes symbol to trade
volume number Yes order volume, min: 0
openPrice number Yes order limit or stop price, min: 0
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
stopLossUnits string stop loss units. ABSOLUTE_PRICE means the that the value of stopLoss field is a final stop loss value. RELATIVE_* means that the stopLoss field value contains relative stop loss expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
takeProfitUnits string take profit units. ABSOLUTE_PRICE means the that the value of takeProfit field is a final take profit value. RELATIVE_* means that the takeProfit field value contains relative take profit expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on position, history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
expiration object pending order expiration settings. See Pending order expiration settings section.
Examples#
{
  "actionType": "ORDER_TYPE_BUY_LIMIT",
  "symbol":"AUDNZD",
  "volume": 0.01,
  "openPrice": 1.03
}

ORDER_TYPE_BUY_STOP_LIMIT or ORDER_TYPE_SELL_STOP_LIMIT#

Submits pending stop limit order to the trading terminal

Name Type Required Description
actionType string Yes action type, enum: ORDER_TYPE_BUY_STOP_LIMIT, ORDER_TYPE_SELL_STOP_LIMIT
symbol string Yes symbol to trade
volume number Yes order volume, min: 0
openPrice number Yes order limit or stop price, min: 0
stopLimitPrice string Yes price at which the StopLimit order will be placed, min: 0
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
stopLossUnits string stop loss units. ABSOLUTE_PRICE means the that the value of stopLoss field is a final stop loss value. RELATIVE_* means that the stopLoss field value contains relative stop loss expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
takeProfitUnits string take profit units. ABSOLUTE_PRICE means the that the value of takeProfit field is a final take profit value. RELATIVE_* means that the takeProfit field value contains relative take profit expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on position, history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
expiration object pending order expiration settings. See Pending order expiration settings section.
Examples#
{
  "actionType": "ORDER_TYPE_BUY_STOP_LIMIT",
  "symbol":"AUDNZD",
  "volume": 0.01,
  "openPrice": 1.03,
  "stopLimitPrice": 1.01
}

POSITION_MODIFY#

Modifies a position TP/SL price

Name Type Required Description
actionType string Yes action type, enum: POSITION_MODIFY
positionId string Yes position id (ticket number)
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
stopLossUnits string stop loss units. ABSOLUTE_PRICE means the that the value of stopLoss field is a final stop loss value. RELATIVE_* means that the stopLoss field value contains relative stop loss expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
takeProfitUnits string take profit units. ABSOLUTE_PRICE means the that the value of takeProfit field is a final take profit value. RELATIVE_* means that the takeProfit field value contains relative take profit expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
Examples#
{
  "actionType": "POSITION_MODIFY",
  "positionId":"46648037",
  "takeProfit": 1.06
}

POSITION_PARTIAL#

Partially closes a position

Name Type Required Description
actionType string Yes action type, enum: POSITION_PARTIAL
positionId string Yes position id
volume number Yes volume to close, min: 0
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#
{
  "actionType": "POSITION_PARTIAL",
  "positionId":"46648037",
  "volume": 0.01
}

POSITION_CLOSE_ID#

Closes a position fully

Name Type Required Description
actionType string Yes action type, enum: POSITION_CLOSE_ID
positionId string Yes position id
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#
{
  "actionType": "POSITION_CLOSE_ID",
  "positionId":"46648037"
}

POSITIONS_CLOSE_SYMBOL#

Close positions by symbol

Name Type Required Description
actionType string Yes action type, enum: POSITIONS_CLOSE_SYMBOL
symbol string Yes symbol to trade
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
slippage number slippage in points. Should be greater or equal to zero. In not set, default value specified in account entity will be used. Slippage is ignored on position modification, order modification and order cancellation calls. Slippage is also ignored if execution mode set in symbol specification is SYMBOL_TRADE_EXECUTION_MARKET.
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#
{
  "actionType": "POSITIONS_CLOSE_SYMBOL",
  "symbol": "AUDNZD"
}

POSITION_CLOSE_BY#

Closes a position by an opposite position

Name Type Required Description
actionType string Yes action type, enum: POSITION_CLOSE_BY
positionId string Yes position id
closeByPositionId string Yes identifier of an opposite position used for closing by order
comment string order comment. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
clientId string client-assigned id. The id value will be present on history orders and history deals related to this order. You can use this field to bind your trades to objects in your application and then track trade progress. The sum of the line lengths of the comment and the clientId must be less than or equal to 26. For more information see clientId usage
magic number magic number (expert adviser id)
fillingModes array allowed filling modes in the order of priority. Default is to allow all filling modes and prefer ORDER_FILLING_FOK over ORDER_FILLING_IOC. See https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties#enum_order_type_filling for extra explanation.
Examples#
{
  "actionType": "POSITION_CLOSE_BY",
  "positionId":"46648037",
  "closeByPositionId":"46648046"
}

ORDER_MODIFY#

Modifies an order

Name Type Required Description
actionType string Yes action type, enum: ORDER_MODIFY
orderId string Yes order id (ticket number)
openPrice number Yes limit or stop price, required for a pending order, min: 0
stopLoss number stop loss price, min: 0
takeProfit number take profit price, min: 0
stopLossUnits string stop loss units. ABSOLUTE_PRICE means the that the value of stopLoss field is a final stop loss value. RELATIVE_* means that the stopLoss field value contains relative stop loss expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
takeProfitUnits string take profit units. ABSOLUTE_PRICE means the that the value of takeProfit field is a final take profit value. RELATIVE_* means that the takeProfit field value contains relative take profit expressed either in price, points, account currency or balance percentage. Default is ABSOLUTE_PRICE. enum: ABSOLUTE_PRICE, RELATIVE_PRICE, RELATIVE_POINTS, RELATIVE_CURRENCY, RELATIVE_BALANCE_PERCENTAGE
Examples#
{
  "actionType": "ORDER_MODIFY",
  "orderId":"47067192",
  "openPrice": 1.03,
  "stopLoss": 1.05
}

ORDER_CANCEL#

Cancels an order

Name Type Required Description
actionType string Yes action type, enum: ORDER_CANCEL
orderId string Yes order id (ticket number)
Examples#
{
  "actionType": "ORDER_CANCEL",
  "orderId":"47067192"
}

Usages#