MetaTrader 4 functions
28 documented functions of the MQL4, grouped by what they do. Each has its signature, arguments, return value and the source it was read from.
Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.
These are functions of a programming language, not HTTP endpoints: none has a method, a path or an address. For that reason they are in no OpenAPI file on this site and the request builder does not list them. A function that is not listed is not recorded here, which is not evidence that it does not exist.
Account
5 functions
- AccountBalance()Returns the balance of the account the terminal is logged in to.
- AccountEquity()Returns the equity of the account the terminal is logged in to.
- AccountFreeMargin()Returns the free margin of the account the terminal is logged in to.
- AccountFreeMarginCheck()Returns the free margin that would be left after opening an order of a given symbol, direction and size at the current price.
- AccountInfoDouble()Returns one floating point property of the account, chosen by an identifier.
Finding orders
3 functions
- OrderSelect()Selects one order, by its place in a list or by its ticket, so that the functions which read an order's properties read that one.
- OrdersHistoryTotal()Returns how many closed orders are in the account history the terminal has loaded.
- OrdersTotal()Returns how many market and pending orders the account has.
Prices and bars
6 functions
- CopyRates()Copies historical bars of a symbol and timeframe into an array of MqlRates structures, by start position and count, by start time and count, or between two times.
- iClose()Returns the close price of one bar of a symbol and timeframe, counted back from the current bar.
- MarketInfo()Returns one item of data about a symbol in the Market Watch window, chosen by a request identifier: a price, or a dealing property such as the stop level.
- RefreshRates()Refreshes the predefined price variables and series arrays that a running program holds its own copy of.
- SymbolInfoDouble()Returns one floating point property of a symbol, chosen by an identifier.
- SymbolInfoTick()Writes the current prices of a symbol, with the time they were last updated, into an MqlTick structure.
Reading the selected order
9 functions
- OrderLots()Returns the size, in lots, of the order now selected.
- OrderMagicNumber()Returns the magic number of the order now selected, the identifier a program gave it when it was sent.
- OrderOpenPrice()Returns the open price of the order now selected.
- OrderProfit()Returns the profit of the order now selected, before swaps and commission.
- OrderStopLoss()Returns the stop loss level of the order now selected.
- OrderSymbol()Returns the symbol of the order now selected.
- OrderTakeProfit()Returns the take profit level of the order now selected.
- OrderTicket()Returns the ticket number of the order now selected.
- OrderType()Returns the operation type of the order now selected, which says whether it is a buy or a sell and whether it is open or pending.
Sending orders
5 functions
- OrderClose()Closes an open order, in full or for a given number of lots, at a price you pass.
- OrderCloseBy()Closes an open order against another open order in the opposite direction.
- OrderDelete()Deletes a pending order that was placed earlier.
- OrderModify()Changes an open or pending order: its stop loss and take profit, and for a pending order its price and expiry too.
- OrderSend()Opens a market order or places a pending order. The page calls it the main function for doing either.