Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing metatrader in python

I am trying to use the Metatrader library to extract market data and build algorithms. The first lines to get started with this library just don't work

import MetaTrader5 as mt5
mt5.initialize()

These lines of code always return an output of False meaning that mt5 has not initialized, i have not seen this issue addressed anywhere else so i would really appreciate some help.

like image 343
Python Maester Avatar asked Jul 31 '26 04:07

Python Maester


1 Answers

You need to precise your login, your password, your server and download the MetaTrader 5 terminal EXE file() in order to connect to Metatrader.

if not mt5.initialize(login=25115284, server="MetaQuotes-Demo",password="4zatlbqx"):
    print("initialize() failed, error code =",mt5.last_error())
    quit()

(cf. https://www.mql5.com/en/docs/integration/python_metatrader5/mt5initialize_py)

You should also take a look at the last_error() section (https://www.mql5.com/en/docs/integration/python_metatrader5/mt5lasterror_py) of the Metatrader documentation and install Metatrader if it's not already https://www.metatrader5.com/en/automated-trading

like image 195
Mattherix Avatar answered Aug 02 '26 18:08

Mattherix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!