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

ParameterWhat it is
symbolThe symbol name. Required.
enableTrue to add the symbol, False to remove it. Optional; leaving it out adds the symbol.

What it returns

  • True when the change worked.
  • False when it did not, for example an unknown symbol, or a removal the terminal refused. Check mt5.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.

Related error codes

All MetaTrader5 Python functions

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.