python metatrader5 initialize error

 

Hey there,


i am trying to get python to connect to mt5

when i initialize it, it wont login to my account (i have checked the login and password for the demo account a few times)

if i use this code to initialize, i get this error code


# establish MetaTrader 5 connection to a specified trading account

if not mt5.initialize(C:\Program Files\Alpari MT5\terminal64.exe, login=117347, server="M4markets-MT5", password="oW7036a2"):
    
        print("initialize() failed, error code =", mt5.last_error())
    
        quit()
C:\Users\Administrator\PycharmProjects\mt5-1\venv\Scripts\python.exe C:\Users\Administrator\PycharmProjects\mt5-1\mt5-1.py 
  File "C:\Users\Administrator\PycharmProjects\mt5-1\mt5-1.py", line 8
    if not mt5.initialize(C:\Program Files\Alpari MT5\terminal64.exe, login=117347, server="M4markets-MT5", password="oW7036a2"):
                           ^
SyntaxError: invalid syntax

Process finished with exit code 1


if i use this code


# establish MetaTrader 5 connection to a specified trading account

if not mt5.initialize("C:\Program Files\Alpari MT5\terminal64.exe", login=117347, server="M4markets-MT5", password="oW7036a2"):
    
        print("initialize() failed, error code =", mt5.last_error())
    
        quit()

i get this error

C:\Users\Administrator\PycharmProjects\mt5-1\venv\Scripts\python.exe C:\Users\Administrator\PycharmProjects\mt5-1\mt5-1.py 
MetaTrader5 package author:  MetaQuotes Ltd.
MetaTrader5 package version:  5.0.43
initialize() failed, error code = (-10003, "IPC initialize failed, Process create failed 'C:\\Program Files\\Alpari MT5\terminal64.exe'")

Process finished with exit code 0


and if i use this code

# establish MetaTrader 5 connection to a specified trading account

if not mt5.initialize(login=117347, server="M4markets-MT5", password="oW7036a2"):
    
        print("initialize() failed, error code =", mt5.last_error())
    
        quit()

MT5 opens but i get this error message

C:\Users\Administrator\PycharmProjects\mt5-1\venv\Scripts\python.exe C:\Users\Administrator\PycharmProjects\mt5-1\mt5-1.py 
MetaTrader5 package author:  MetaQuotes Ltd.
MetaTrader5 package version:  5.0.43
initialize() failed, error code = (-10005, 'IPC timeout')

Process finished with exit code 0


How do i get this to work?

 

The error seems to be related to your path.

Did you see there is only one backslash "\" before `terminal64.exe`? 

Try to escape all backslashes (\\) in your path.

This answer from Stackoverflow might also help. 

Best.

metatrader error initialize() failed, error code = (-10005, 'IPC timeout')
metatrader error initialize() failed, error code = (-10005, 'IPC timeout')
  • 2021.03.05
  • dcabello dcabello 1 2 2 bronze badges
  • stackoverflow.com
I got this error initialize() failed, error code = (-10005, 'IPC timeout') when execute this code: Can anyone help me please? Thanks in advance
Reason: