pipsocketDOCS
Guides / Reference

MT5 field map

Which MT5 field each API field is, and what each call fills in itself.

Fields keep MT5's names and meanings, with readable values in place of MT5's numbers: "type": "buy_limit" is ORDER_TYPE_BUY_LIMIT, "type_filling": "ioc" is ORDER_FILLING_IOC.

The trade request

Every trade call records one MqlTradeRequest and sends it once; every answer shows it as sent, field for field (whether it reached MT5 is the answer's state and result). Fields a call doesn't use carry MT5's empty values: 0, "", fok for type_filling and gtc for type_time.

API fieldMT5 fieldMeaning
actionactionWhat the request does.
symbolsymbolThe symbol, exactly as the broker names it.
typetypeThe order type.
volumevolumeLots.
pricepriceThe price: a pending order's, or the one instant and request execution trade at.
stoplimitstoplimitA stop-limit order's limit price, placed once price is reached.
slslStop loss price; 0 for none.
tptpTake profit price; 0 for none.
deviationdeviationThe largest difference from price MT5 accepts, in points.
type_fillingtype_fillingHow the order may fill.
type_timetype_timeHow long a pending order lasts.
expirationexpirationBroker server time, seconds since 1970, as MT5 takes it.
orderorderThe pending order the request is about (modify, remove).
positionpositionThe position the request is about (close, stops, close by).
position_byposition_byThe opposite position, for close by.
magicmagicYour own number, kept by MT5 on the order, its deals and its position.
commentcommentUp to 31 characters, kept by MT5 on the order.

What each call fills in, beyond the fields you send:

CallactionAlso filled in
Place an orderdeal for buy and sell, else pendingNothing else.
Modify an ordermodifyorder from the path, and symbol from the pending order.
Cancel an orderremoveorder from the path.
Set stopssltpposition from the path, and symbol from the position.
Close a positiondealposition from the path; symbol from the position; type the other way (sell closes a buy).
Close byclose_byposition from the path, type: close_by, and symbol from the position.
Kill switchremove for each pending order, deal for each positionFor a close: the position's whole volume, the current bid or ask as price, the first filling mode the symbol allows (fok, else ioc, else return), your deviation, and the comment kill switch.

Nothing else is set for you: no price for a market order, no filling mode, no rounding. A dry run sends the same request to MT5's OrderCheck without trading.

Bodies you send

Place an order and Check an order:

API fieldMT5 fieldMeaning
symbolsymbolThe symbol exactly as the broker names it, such as EURUSD.
typetypeWhat to send.
volumevolumeLots.
type_fillingtype_fillingHow the order may fill.
pricepriceRequired for pending orders: the price the order waits for.
stoplimitstoplimitRequired for buy_stop_limit and sell_stop_limit: the price of the limit order placed once price is reached.
slslStop loss price, set in the same request.
tptpTake profit price, set in the same request.
deviationdeviationThe largest difference from price MT5 accepts, in points, for instant or request execution.
type_timetype_timeHow long a pending order lasts.
expirationexpirationWhen a pending order expires: broker server time, seconds since 1970.
magicmagicYour own number for the order, kept by MT5 on the order, its deals and its position.
commentcommentUp to 31 characters, kept by MT5 on the order.

Modify an order:

API fieldMT5 fieldMeaning
pricepriceThe price the order waits for.
slslStop loss price; 0 removes it.
tptpTake profit price; 0 removes it.
type_timetype_timeHow long the order lasts.
stoplimitstoplimitRequired when the order is a stop-limit order: the price of the limit order placed once price is reached.
expirationexpirationWhen the order expires: broker server time, seconds since 1970.

Close a position:

API fieldMT5 fieldMeaning
volumevolumeLots to close: the position's whole volume, or part of it.
type_fillingtype_fillingHow the closing deal may fill.
pricepriceSent as given (0 if left out): brokers with instant or request execution need it, those with market or exchange execution ignore it.
deviationdeviationThe largest difference from price MT5 accepts, in points, for instant or request execution.
magicmagicYour own number, kept by MT5 on the closing deal.
commentcommentUp to 31 characters, kept by MT5 on the closing deal.

Set stops (PositionLevels) and Close by (CloseBy):

API fieldMT5 fieldMeaning
slslStop loss price; 0 removes it.
tptpTake profit price; 0 removes it.
API fieldMT5 fieldMeaning
position_byposition_byThe opposite position's ticket.

MT5's answer

A trade's result is MT5's MqlTradeResult:

API fieldMT5 fieldMeaning
retcoderetcodeMT5's return code: see Errors and retcodes.
retcode_namePipsocketThe return code's name; UNKNOWN for a code MT5 doesn't document.
commentcommentThe broker's comment on the answer.
orderorderThe order's ticket, if one was placed.
dealdealThe deal's ticket, if one was made.
positionPipsocketThe position's ticket, where the trade server gives it.
volumevolumeThe volume dealt.
pricepriceThe price dealt.
bidbidThe bid when the request was handled (requotes).
askaskThe ask when the request was handled (requotes).
retcode_externalretcode_externalThe external trading system's code, if the broker routes to one.

A dry run's result is MT5's MqlTradeCheckResult:

API fieldMT5 fieldMeaning
passedPipsocketWhether OrderCheck passed the request.
retcoderetcodeMT5's return code: 0 when the check passed.
retcode_namePipsocketThe return code's name; UNKNOWN for a code MT5 doesn't document.
commentcomment
balancebalanceThe balance after the trade.
equityequityThe equity after the trade.
profitprofitThe floating profit after the trade.
marginmarginThe margin the trade takes.
margin_freemargin_freeThe free margin after the trade.
margin_levelmargin_levelThe margin level after the trade, in percent.

The account's state

Positions (POSITION_*):

API fieldMT5 fieldMeaning
ticketPOSITION_TICKETThe position's ticket: use it to close the position or set its stops.
identifierPOSITION_IDENTIFIERThe position's id, which stays the same if the broker changes the ticket.
symbolPOSITION_SYMBOL
typePipsocketbuy or sell (MT5's POSITION_TYPE).
volumePOSITION_VOLUME
price_openPOSITION_PRICE_OPEN
slPOSITION_SL
tpPOSITION_TP
magicPOSITION_MAGIC
commentPOSITION_COMMENT
time_mscPOSITION_TIME_MSCWhen it was opened: broker server time, milliseconds since 1970.

Pending orders (ORDER_*):

API fieldMT5 fieldMeaning
ticketORDER_TICKET
symbolORDER_SYMBOL
typeORDER_TYPEMT5's ENUM_ORDER_TYPE: buy and sell are market orders (ORDER_TYPE_BUY, ORDER_TYPE_SELL); buy_limit, sell_limit, buy_stop, sell_stop, buy_stop_limit and sell_stop_limit are pending orders (ORDER_TYPE_BUY_LIMIT and so on); close_by is ORDER_TYPE_CLOSE_BY.
volume_initialORDER_VOLUME_INITIAL
volume_currentORDER_VOLUME_CURRENT
price_openORDER_PRICE_OPEN
slORDER_SL
tpORDER_TP
magicORDER_MAGIC
commentORDER_COMMENT
positionORDER_POSITION_IDThe position the order belongs to, if any.

Deals (DEAL_*), in history and on the stream:

API fieldMT5 fieldMeaning
ticketDEAL_TICKET
orderDEAL_ORDERThe order that made the deal.
positionDEAL_POSITION_IDThe position's id (identifier).
symbolDEAL_SYMBOL
typePipsocketMT5's DEAL_TYPE: buy, sell, or a balance operation.
entryPipsocketMT5's DEAL_ENTRY: in opens or adds, out closes, inout reverses, out_by closes by an opposite position.
reasonPipsocketMT5's DEAL_REASON: who or what made the deal (expert for the API, sl, tp, so for a stop out).
volumeDEAL_VOLUME
priceDEAL_PRICE
profitDEAL_PROFIT
commissionDEAL_COMMISSION
swapDEAL_SWAP
feeDEAL_FEE
magicDEAL_MAGIC
commentDEAL_COMMENT
time_mscDEAL_TIME_MSCBroker server time, milliseconds since 1970.

Past orders:

API fieldMT5 fieldMeaning
ticketORDER_TICKET
symbolORDER_SYMBOL
typeORDER_TYPEMT5's ENUM_ORDER_TYPE: buy and sell are market orders (ORDER_TYPE_BUY, ORDER_TYPE_SELL); buy_limit, sell_limit, buy_stop, sell_stop, buy_stop_limit and sell_stop_limit are pending orders (ORDER_TYPE_BUY_LIMIT and so on); close_by is ORDER_TYPE_CLOSE_BY.
statePipsocketMT5's ORDER_STATE.
volume_initialORDER_VOLUME_INITIAL
volume_currentORDER_VOLUME_CURRENT
price_openORDER_PRICE_OPEN
magicORDER_MAGIC
commentORDER_COMMENT
positionORDER_POSITION_ID
time_setup_mscORDER_TIME_SETUP_MSCBroker server time, milliseconds since 1970.
time_done_mscORDER_TIME_DONE_MSCBroker server time, milliseconds since 1970.

A symbol (SYMBOL_*):

API fieldMT5 fieldMeaning
nameSYMBOL_NAME
availablePipsocketWhether the terminal could read its properties; when false the rest are empty values.
descriptionSYMBOL_DESCRIPTION
digitsSYMBOL_DIGITS
pointSYMBOL_POINT
tick_sizeSYMBOL_TRADE_TICK_SIZE
tick_valueSYMBOL_TRADE_TICK_VALUE
contract_sizeSYMBOL_TRADE_CONTRACT_SIZE
volume_minSYMBOL_VOLUME_MIN
volume_maxSYMBOL_VOLUME_MAX
volume_stepSYMBOL_VOLUME_STEP
stops_levelSYMBOL_TRADE_STOPS_LEVELThe closest stops may be to the price, in points.
freeze_levelSYMBOL_TRADE_FREEZE_LEVELHow close to the price an order or stop is frozen, in points.
filling_modeSYMBOL_FILLING_MODEMT5's flags, as filling_modes spells them out.
trade_modeSYMBOL_TRADE_MODEMT5's value, as trading spells it out.
execution_modeSYMBOL_TRADE_EXEMODEMT5's value, as execution spells it out.
order_modeSYMBOL_ORDER_MODEMT5's flags, as order_types spells them out.
expiration_modeSYMBOL_EXPIRATION_MODEMT5's flags, as expirations spells them out.
currency_baseSYMBOL_CURRENCY_BASE
currency_profitSYMBOL_CURRENCY_PROFIT
currency_marginSYMBOL_CURRENCY_MARGIN
filling_modesPipsocketThe type_filling modes MT5's SYMBOL_FILLING_MODE flags allow.
executionPipsocketMT5's SYMBOL_TRADE_EXEMODE.
order_typesPipsocketThe orders the symbol allows (MT5's SYMBOL_ORDER_MODE).
expirationsPipsocketThe type_time values the symbol allows (MT5's SYMBOL_EXPIRATION_MODE).
tradingPipsocketMT5's SYMBOL_TRADE_MODE: whether and which way the symbol can be traded.

A tick (MqlTick):

API fieldMT5 fieldMeaning
symbolPipsocket
bidbid
askask
time_msctime_mscBroker server time, milliseconds since 1970.
lastlast
volumevolume_real
flagsflagsMT5's TICK_FLAG_* bits: what changed.