0

I got this error initialize() failed, error code = (-10005, 'IPC timeout') when execute this code:

import MetaTrader5 as mt5
# display data on the MetaTrader 5 package
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
 
# establish connection to the MetaTrader 5 terminal
if not mt5.initialize(login=999999, server="xyz-Demo",password="abcdef"):
    print("initialize() failed, error code =",mt5.last_error())
    mt5.shutdown()

Can anyone help me please? Thanks in advance

dcabello
  • 1
  • 2

3 Answers3

3

This is how I solved it. I divided the process into two:

  1. I did the initialization and then,
  2. I logged in.

Importantly, I'm using a Windows PC and everything started working when I changed the path from

"C:\Program Files\MetaTrader 5\terminal64.exe"

to

"C:/Program Files/MetaTrader 5/terminal64.exe"

The code:

def account_login(login = name,password=key, server= serv,):
    if mt5.login(login,password,server):
        print("logged in succesffully")
    else: 
        print("login failed, error code: {}".format(mt5.last_error()))

def initialize(login = name, server=serv, password=key, path=path):
    
    if not mt5.initialize(path):
        print("initialize() failed, error code {}", mt5.last_error())
    else:
        account_login(login, password, server)
chem.cs
  • 53
  • 8
  • This should be marked as the accepted answer. Clean code, detailed explanation and just works. – Huy Mar 12 '23 at 06:58
1

There might be some solutions to your problem:

  1. Try initializing a connection to the MT5 terminal using mt5.initialize() then login into the trading account using mt5.login(account, server, password).
  2. Try closing all previous connections to the mt5 terminal using mt5.shutdown() on all previous scripts
Martin Maati
  • 121
  • 1
  • 5
-6

Maybe, We must launch the app. In actually, I solved same issue by launch the app.

hoge
  • 1