Python Integration : -10003, 'IPC initialize failed, MetaTrader 5 x64 not found'

 

Hi all,

Mostly posting this in case someone else runs into this issue, this may fix the error in the title.

I started from a fresh install of MT5, and upon trying to run a python script, the python Initialize function would produce " -10003, 'IPC initialize failed, MetaTrader 5 x64 not found' " error.

Steps taken to produce and subsequently fix (?) :


1) error would occur regardless of correct specification of terminal64.exe path ( example: mt5.initialize("C:\\Program Files\\MetaTrader 5\\terminal64.exe") ), and omission of the path also produced the same error.

2) created a portable mode of MT5 files from the same files located in C: drive on my D: drive. Running the same script (without path specified in initialize function) would now open and use the portable terminal64.exe file.

3) specifying the path to the C: drive terminal64.exe would now use that one instead.

4) deleted everything in the folder containing the D drive MT5 portable files EXCEPT terminal64.exe

5) specifying path to C drive .exe continues to work, and if path is omitted the same error occurs.

6) Deleting the D drive terminal64.exe (and the folder it was in) results in the new behavior persisting (if no path specified, the function produces the error; otherwise with path, script works).


Script used is as shown below. Issue appears to be resolved by creating some second terminal64.exe outside C drive.

import MetaTrader5 as mt5
import numpy as np
import random
from datetime import datetime
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt  

if __name__ == "__main__":
  if not mt5.initialize("C:\\Program Files\\MetaTrader 5\\terminal64.exe"):
    print("initialize() failed, error code =", mt5.last_error())
  print("connected")
  #-----------------------------------------------------------------------------------------
  
  symbol = "AUDNZD.a"
  bars = 24
  bar_start = 1692144000       # 2023.08.16 00:00:00
  bar_end = (int)(bar_start + 86099)        # retrieve bars from 00:00 to 23:50 (leave 23:55 bar out on M5)
  temp = mt5.copy_rates_from(symbol, mt5.TIMEFRAME_H1, bar_end, bars)
  print(temp)

  exit()
Documentation on MQL5: Python Integration / initialize
Documentation on MQL5: Python Integration / initialize
  • www.mql5.com
initialize - Python Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5