Discussing the article: "MQL5 Integration: Python"

 

Check out the new article: MQL5 Integration: Python.

Python is a well-known and popular programming language with many features, especially in the fields of finance, data science, Artificial Intelligence, and Machine Learning. Python is a powerful tool that can be useful in trading as well. MQL5 allows us to use this powerful language as an integration to get our objectives done effectively. In this article, we will share how we can use Python as an integration in MQL5 after learning some basic information about Python.

In this new article, I will give an introduction to an important tool that will add value to your programming skills. We'll look at Python Integration. When it comes to how this can be useful for us as developers it will depend on your objectives of software as Python is a high-level programming language that is easy to read, and it is simple as well. Python is a programming language that provides extensive libraries for areas such as data analysis, statistical computing, and machine learning. So, the integration of Python and MQL5 can provide better insights that can be helpful for financial market participants to improve their results through data processing and predictive analytics.

In this article, I'll share with you what lets you able to use Python with MQL5 by sharing simple basics of Python, and some simple examples after setting up our environment.

XAUUSD_plot

Author: Mohamed Abdelmaaboud

 

Very interesting, unfortunately  metaTrader python library is not available yet on MacOs.

 

Thanks, 

just find an eror in the 3rd application 

import plotly.express as px could not be resolved

from plotly.offline import plot could not be resolved


i resolved this by reinstalling : pandas and  matplotlib

c:\pip install MetaTrader5 pandas matplotlib


then modify code like this :


import MetaTrader5 as mt5
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime

# Initialisation de MetaTrader 5
if not mt5.initialize():
    print("Erreur d'initialisation :", mt5.last_error())
    quit()
print("MT5 initialized Successfully")

# Définir les paramètres
symbol = "XAUUSD"
start_date = datetime(2023, 8, 1)
end_date = datetime(2024, 8, 12)

# Vérifier si le symbole est disponible
if not mt5.symbol_select(symbol, True):
    print(f"Le symbole {symbol} n'est pas disponible.")
    mt5.shutdown()
    quit()

# Récupérer les données historiques
rates = mt5.copy_rates_range(symbol, mt5.TIMEFRAME_D1, start_date, end_date)
if rates is None:
    print("Erreur lors de la récupération des données :", mt5.last_error())
    mt5.shutdown()
    quit()

# Convertir les données en DataFrame pandas
data = pd.DataFrame(rates)
data['time'] = pd.to_datetime(data['time'], unit='s')  # Convertir les timestamps en datetime

# Afficher les premières lignes des données
print(data.head())

# Visualiser les données sous forme de graphique
plt.figure(figsize=(10, 6))
plt.plot(data['time'], data['close'], label=f"Prix de clôture {symbol}", color="blue")
plt.title(f"Prix de l'or ({symbol}) du {start_date.date()} au {end_date.date()}")
plt.xlabel("Date")
plt.ylabel("Prix")
plt.legend()
plt.grid()
plt.show()

# Déconnexion de MetaTrader 5
mt5.shutdown()



Hope it will help

 
Omar Saghir #:

Thanks, 

just find an eror in the 3rd application 

import plotly.express as px could not be resolved

from plotly.offline import plot could not be resolved

i resolved this by reinstalling : pandas and  matplotlib

c:\pip install MetaTrader5 pandas matplotlib

...


It is also possible to install Plotly library:

pip install plotly

More information:

https://plotly.com/python/getting-started/

Getting
  • plotly.com
Copyright © 2024 Plotly. All rights reserved.
 
Thanks to the author, good example. It would be interesting to read an article about using machine learning tools such as scikit-learn, TensorFlow and Keras through MQL5+Python.