MT5Initialize

Establish a connection with the MetaTrader 5 terminal.

MT5Initialize(
   path=None      // path to the MetaTrader 5 terminal EXE file
   )

Parameters

path=None

[in]  Path to the metatrader.exe or metatrader64.exe file. If the path is not specified, the module attempts to find the executable file on its own.

Return Value

Returns True in case of successful connection to the MetaTrader 5 terminal, otherwise - False.

Note

If required, the MetaTrader 5 terminal is launched to establish connection when executing the MT5Initialize() call.

Example:

from datetime import datetime
from MetaTrader5 import *
 
# connect to MetaTrader 5
MT5Initialize()
# wait till MetaTrader 5 connects to the trade server
MT5WaitForTerminal()
# display data on connection status, server name and trading account
print(MT5TerminalInfo())
# display data on MetaTrader 5 version
print(MT5Version())
# shut down connection to the MetaTrader 5 terminal
MT5Shutdown()

See also

MT5Shutdown, MT5WaitForTerminal, MT5TerminalInfo, MT5Version