mt5.symbol_select() in MetaTrader5 Python: add a symbol to Market Watch
Adds a symbol to the terminal's Market Watch, or removes it. Most price and data functions need the symbol selected first. Returns True or False.
Signature
mt5.symbol_select(symbol)
mt5.symbol_select(symbol, enable) What it does
The terminal only streams prices for symbols in Market Watch. A symbol the server lists but Market Watch hides has no fresh ticks, and many calls on it fail.
Call symbol_select(symbol, True) once before you read prices, copy ticks or trade a symbol you have not used before.
Parameters
| Parameter | What it is |
|---|---|
symbol | The symbol name. Required. |
enable | True to add the symbol, False to remove it. Optional; leaving it out adds the symbol. |
What it returns
Truewhen the change worked.Falsewhen it did not, for example an unknown symbol, or a removal the terminal refused. Checkmt5.last_error().
Example
import MetaTrader5 as mt5
if not mt5.initialize():
raise SystemExit(mt5.last_error())
for name in ("EURUSD", "XAUUSD"):
info = mt5.symbol_info(name)
if info is None:
print(name, "is not on this server")
elif not info.visible and not mt5.symbol_select(name, True):
print("could not select", name, mt5.last_error())
mt5.shutdown() Common mistakes
- Removal fails while the symbol has an open chart or an open position.
- Right after selecting, the first tick can take a moment to arrive. Wait briefly before you read the price.
- A not-selected symbol shows up as 4302 in the terminal's own codes.
The same with Tickwire on Linux
The package needs a Windows terminal on the same machine. Tickwire runs the terminal for you and gives you a REST API, so the code below runs on Linux, macOS or a server.
On MT5, Tickwire's price and specification reads add a hidden symbol to Market Watch for you, so you never call a select step. There is no route that removes a symbol from Market Watch.
GET /users/current/accounts/{account_id}/symbols/{symbol}/current-priceGET /users/current/accounts/{account_id}/symbols/{symbol}/specification
Related functions
- mt5.symbol_info() in MetaTrader5 Python: read a symbol's settings and limits
- mt5.symbol_info_tick() in MetaTrader5 Python: get the latest bid and ask
- mt5.symbols_get() in MetaTrader5 Python: list symbols, with an optional filter
- mt5.copy_ticks_from() in MetaTrader5 Python: get ticks forward from a date
Related error codes
MT5 from Python, on any machine
One REST API for MT4 and MT5, with idempotent orders and an audit log. Read the MT5 Python API page or the quickstart.