Python and MT5: mt5.initialize() problem

 

Hi, im new here and have a problem trying to conect mt5 with python; i have this code:

import MetaTrader5 as mt5

import pandas as pd

mt5

.initialize()

And this is the result:

# Intenta inicializar MetaTrader 5
mt5.initialize(path)


Out[3]: False

Does anyone know what the problem is? I've been watching videos, and it usually works.

 
Sebastian Diaz:

Hi, im new here and have a problem trying to conect mt5 with python; i have this code:

And this is the result:

Does anyone know what the problem is? I've been watching videos, and it usually works.

if you're running this on windows or wine, this happens because your MT5 is not fully intialized yet.

If you are run mt5 with GUI you will realise you need to select the server and login to your account on the first round you are launching it before mt5.initialize() even works.
If this defeats your automation goal, then the way around is to:

1. launch mt5 and then go ahead and select your server and login (the same popups im referring to)
2. save a copy of the entire Config folder located at "C:/Program Files/MetaTrader 5/Config"

^ These files contain the login details and configurations that you have done on the first login.

3. Override the Config file with the one saved for every new instance of MT5 that you launch. 


The above should prevent the popup when starting MT5 for the first time, and hence now your mt5.initialize() should work with no issues.