MetaTrader 5 functions
78 documented functions of the MetaTrader5 Python package and MQL5, 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.
MT5 Python: Account
1 function
MT5 Python: Bars and ticks
5 functions
- copy_rates_from()Returns a number of bars for one instrument and timeframe, counting back from a date.
- copy_rates_from_pos()Returns a number of bars for one instrument and timeframe, starting from a bar index where 0 is the bar now forming.
- copy_rates_range()Returns the bars for one instrument and timeframe that open between two dates.
- copy_ticks_from()Returns a number of ticks for one instrument, starting from a date.
- copy_ticks_range()Returns the ticks for one instrument between two dates.
MT5 Python: Connection
6 functions
- initialize()Connects the Python package to a MetaTrader 5 terminal on the same computer, starting the terminal if it is not running, and can log in to a trading account in the same call.
- last_error()Returns the code and description of the last error raised by a call to the package. The codes are the package's own, not the terminal's.
- login()Switches the connected terminal to a trading account, by account number, with the password and server optional.
- shutdown()Closes the connection that initialize() opened between the Python package and the terminal.
- terminal_info()Returns the status and settings of the connected terminal in one call.
- version()Returns the version of the connected MetaTrader 5 terminal, with its build number and the date of that build.
MT5 Python: History
4 functions
- history_deals_get()Returns deals from the account's trading history: those between two dates, optionally filtered by symbol, or those of one order, or those of one position.
- history_deals_total()Returns how many deals are in the account's trading history between two dates.
- history_orders_get()Returns orders from the account's trading history: those between two dates, optionally filtered by symbol, or the one with a given ticket, or those of one position.
- history_orders_total()Returns how many orders are in the account's trading history between two dates.
MT5 Python: Market depth
3 functions
- market_book_add()Subscribes the terminal to changes in the depth of market for one instrument, which is what makes market_book_get() return data.
- market_book_get()Returns the current depth of market for one instrument, once market_book_add() has subscribed the terminal to it.
- market_book_release()Ends the terminal's subscription to depth of market changes for one instrument.
MT5 Python: Orders
6 functions
- order_calc_margin()Works out the margin, in the account's currency, that a trade of a given type, symbol, volume and price would need.
- order_calc_profit()Works out the profit or loss, in the account's currency, of a trade opened at one price and closed at another.
- order_check()Checks whether the account has the funds for a trade request without sending it, and returns what the balance, equity and margin would be.
- order_send()Sends a trade request from the terminal to the trade server. One call covers a market order, a pending order, a change to an order or position, a cancellation and a close: the request's action field says which.
- orders_get()Returns the active pending orders on the account: all of them, those in one symbol, those whose symbol matches a filter, or the one with a given ticket.
- orders_total()Returns how many pending orders are active on the account.
MT5 Python: Positions
2 functions
MT5 Python: Symbols
5 functions
- symbol_info()Returns the terminal's data on one financial instrument: its contract and dealing properties as well as its latest prices.
- symbol_info_tick()Returns the last tick the terminal has for one financial instrument.
- symbol_select()Adds a financial instrument to the terminal's Market Watch window, or removes it.
- symbols_get()Returns the financial instruments in the terminal, all of them or those whose names match a filter.
- symbols_total()Returns how many financial instruments the terminal holds.
MQL5: Account
3 functions
- AccountInfoDouble()Returns one floating point property of the trading account, such as its balance, equity or free margin.
- AccountInfoInteger()Returns one integer property of the trading account, such as its number, its leverage or whether trading is allowed.
- AccountInfoString()Returns one text property of the trading account, such as its currency, the server's name or the broker's company name.
MQL5: Bars and ticks
3 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.
- CopyTicks()Copies ticks of a symbol into an array of MqlTick structures, from a time onwards or the most recent ones. The oldest tick copied is at index 0.
- CopyTicksRange()Copies the ticks of a symbol between two times into an array of MqlTick structures. The oldest tick copied is at index 0.
MQL5: History
14 functions
- HistoryDealGetDouble()Returns one floating point property of a deal in the account's history, by ticket.
- HistoryDealGetInteger()Returns one integer or date property of a deal in the account's history, by ticket.
- HistoryDealGetString()Returns one text property of a deal in the account's history, by ticket.
- HistoryDealGetTicket()Returns the ticket of the deal at a place in the loaded history, and selects that deal for the history deal functions.
- HistoryDealSelect()Selects one deal in the account's history by its ticket, so the history deal functions can read it.
- HistoryDealsTotal()Returns how many deals are in the history that was last loaded.
- HistoryOrderGetDouble()Returns one floating point property of an order in the account's history, by ticket.
- HistoryOrderGetInteger()Returns one integer or date property of an order in the account's history, by ticket.
- HistoryOrderGetString()Returns one text property of an order in the account's history, by ticket.
- HistoryOrderGetTicket()Returns the ticket of the order at a place in the loaded history.
- HistoryOrderSelect()Selects one order in the account's history by its ticket, so the history order functions can read it.
- HistoryOrdersTotal()Returns how many orders are in the history that was last loaded.
- HistorySelect()Loads the account's history of deals and orders for a period of server time, so the other history functions have something to read.
- HistorySelectByPosition()Loads the deals and orders that belong to one position, by the position's identifier.
MQL5: Pending orders
6 functions
- OrderGetDouble()Returns one floating point property of a pending order. It reads the order last selected with OrderGetTicket() or OrderSelect().
- OrderGetInteger()Returns one integer or date property of a pending order. It reads the order last selected with OrderGetTicket() or OrderSelect().
- OrderGetString()Returns one text property of a pending order. It reads the order last selected with OrderGetTicket() or OrderSelect().
- OrderGetTicket()Returns the ticket of the pending order at a position in the list of current orders, and selects that order so its properties can be read.
- OrderSelect()Selects a pending order by its ticket, so that OrderGetDouble(), OrderGetInteger() and OrderGetString() read that order.
- OrdersTotal()Returns how many pending orders are current on the account.
MQL5: Positions
8 functions
- PositionGetDouble()Returns one floating point property of an open position. It reads the position last selected with PositionGetSymbol() or PositionSelect().
- PositionGetInteger()Returns one integer or date property of an open position. It reads the position last selected with PositionGetSymbol() or PositionSelect().
- PositionGetString()Returns one text property of an open position. It reads the position last selected with PositionGetSymbol() or PositionSelect().
- PositionGetSymbol()Returns the symbol of the open position at a place in the list of positions, and selects that position so its properties can be read.
- PositionGetTicket()Returns the ticket of the open position at an index in the list of positions, and selects that position so its properties can be read.
- PositionSelect()Selects the open position in a symbol, so that PositionGetDouble(), PositionGetInteger() and PositionGetString() read it.
- PositionSelectByTicket()Selects an open position by its ticket, so that PositionGetDouble(), PositionGetInteger() and PositionGetString() read it.
- PositionsTotal()Returns how many positions are open on the account.
MQL5: Sending orders
5 functions
- OrderCalcMargin()Works out the margin, in the account's currency, that an order of a given type, symbol, volume and price would need on the account as it stands.
- OrderCalcProfit()Works out the profit or loss, in the account's currency, of a trade opened at one price and closed at another, on the account and market as they stand.
- OrderCheck()Checks whether there is enough money for a trade request without sending it, and writes what the account would look like into a result structure.
- OrderSend()Sends a trade request to the trade server and waits for its answer. One function covers a market order, a pending order, a change, a cancellation and a close: the action field of the request says which.
- OrderSendAsync()Sends a trade request to the trade server without waiting for its answer. The page describes it as made for high frequency trading, where waiting for the server is not acceptable.
MQL5: Symbols and prices
7 functions
- SymbolInfoDouble()Returns one floating point property of a symbol, such as its bid, its ask or its point size.
- SymbolInfoInteger()Returns one integer property of a symbol, such as its spread, or whether that spread floats.
- SymbolInfoString()Returns one text property of a symbol, such as its description or its base and profit currencies.
- SymbolInfoTick()Writes the current prices of a symbol, with the time they were last updated, into an MqlTick structure.
- SymbolName()Returns the name of the symbol at a place in the list of symbols.
- SymbolSelect()Adds a symbol to the Market Watch window, or removes it.
- SymbolsTotal()Returns how many symbols are available: those selected in Market Watch, or all of them.