MetaTrader 5 Python User Group - the summary - page 32

 

Self Optimizing Expert Advisor With MQL5 And Python (Part V): Deep Markov Models

Self Optimizing Expert Advisor With MQL5 And Python (Part V): Deep Markov Models

In our previous discussion on Markov Chains, linked here, we demonstrated how to use a transition matrix to understand the probabilistic behavior of the market. Our transition matrix summarized a lot of information for us. It not only guided us on when to buy and sell, it also informed us whether our market had strong trends or was mostly mean reverting. In today's discussion, we shall change our definition of the system state from the moving averages we used in our first discussion to the Relative Strength Indicator (RSI) indicator instead.
Self Optimizing Expert Advisor With MQL5 And Python (Part V): Deep Markov Models
Self Optimizing Expert Advisor With MQL5 And Python (Part V): Deep Markov Models
  • www.mql5.com
In this discussion, we will apply a simple Markov Chain on an RSI Indicator, to observe how price behaves after the indicator passes through key levels. We concluded that the strongest buy and sell signals on the NZDJPY pair are generated when the RSI is in the 11-20 range and 71-80 range, respectively. We will demonstrate how you can manipulate your data, to create optimal trading strategies that are learned directly from the data you have. Furthermore, we will demonstrate how to train a deep neural network to learn to use the transition matrix optimally.
 
Sergey Golubev #:

Developing a robot in Python and MQL5 (Part 1): Data preprocessing

We will look at the development cycle of a trading robot: data collection, processing, sample expansion, feature engineering, model selection and training, creating a trading system via Python, and monitoring trades.

Working in Python has its own advantages: speed in the field of machine learning, as well as the ability to select and generate features. Exporting models to ONNX requires exactly the same feature generation logic as in Python, which is not easy. That is why I have selected online trading via Python.

Developing a robot in Python and MQL5 (Part 2): Model selection, creation and training, Python custom tester

Developing a robot in Python and MQL5 (Part 2): Model selection, creation and training, Python custom tester

In the previous article, we talked a bit about machine learning, performed data augmentation, developed features for the future model and selected the best of them. Now it is time to move on and create a working machine learning model that will learn from our features and trade (hopefully successfully). To evaluate the model, we will write a custom Python tester that will help us evaluate the performance of the model and the beauty of the test graphs. For more beautiful test graphs and greater model stability, we will also develop a number of classic machine learning features along the way.

Our ultimate goal is to create a working and maximally profitable model for price forecasting and trading. All code will be in Python, with inclusions of the MQL5 library.

Developing a robot in Python and MQL5 (Part 2): Model selection, creation and training, Python custom tester
Developing a robot in Python and MQL5 (Part 2): Model selection, creation and training, Python custom tester
  • www.mql5.com
We continue the series of articles on developing a trading robot in Python and MQL5. Today we will solve the problem of selecting and training a model, testing it, implementing cross-validation, grid search, as well as the problem of model ensemble.
 

Data Science and ML (Part 31): Using CatBoost AI Models for Trading

Data Science and ML (Part 31): Using CatBoost AI Models for Trading

CatBoost is an open-source software library with gradient-boosting algorithms on decision trees, it was designed specifically to address the challenges of handling categorical features and data in machine learning.

It was developed by Yandex and was made open-source in the year of 2017, read more.

Despite being introduced recently compared to machine learning techniques such as Linear regression or SVM's, CatBoost gained massive popularity among AI communities and rose to the top of the most used machine learning models on platforms like Kaggle.

What made CatBoost gain this much attention is its ability to automatically handle categorical features in the dataset, which can be challenging to many machine learning algorithms.

Data Science and ML (Part 31): Using CatBoost AI Models for Trading
Data Science and ML (Part 31): Using CatBoost AI Models for Trading
  • www.mql5.com
CatBoost AI models have gained massive popularity recently among machine learning communities due to their predictive accuracy, efficiency, and robustness to scattered and difficult datasets. In this article, we are going to discuss in detail how to implement these types of models in an attempt to beat the forex market.
 
Sergey Golubev #:

Data Science and ML (Part 31): Using CatBoost artificial intelligence models for trading

CatBoost is an open-source software library with gradient-based decision tree bousting algorithms that was developed specifically to solve problems related to categorical feature and data processing in machine learning.

It was developed by Yandex and was open sourced in 2017, read more.

Despite being introduced recently compared to machine learning methods such as linear regression or SVM, CatBoost has gained immense popularity among AI communities and has risen to the top of the most used machine learning models on platforms such as Kaggle.

The reason for this attention to CatBoost was its ability to automatically handle categorical features in a dataset that can be challenging for many machine learning algorithms.

So yeah, yandex is just a supermodel for business. Talked to developers, no one there could tolerate more than half a year. Just inexperienced juniors.

 

Feature Engineering With Python And MQL5 (Part I): Forecasting Moving Averages For Long-Range AI Models

Feature Engineering With Python And MQL5 (Part I): Forecasting Moving Averages For Long-Range AI Models

When applying AI to any task, we must try our best to give the model as much useful information about the real world as we can. To describe different properties of the market to our AI models, we must manipulate and transform the input data, this process is referred to as feature engineering. This series of articles will teach you how to transform your market data, to reduce the error levels of your models. Today, I will focus on how to use moving averages to increase the forecasting range of your AI models in a fashion that gives complete control and a reasonable understanding of the global effectiveness of the strategy.
Feature Engineering With Python And MQL5 (Part I): Forecasting Moving Averages For Long-Range AI Models
Feature Engineering With Python And MQL5 (Part I): Forecasting Moving Averages For Long-Range AI Models
  • www.mql5.com
The moving averages are by far the best indicators for our AI models to predict. However, we can improve our accuracy even further by carefully transforming our data. This article will demonstrate, how you can build AI Models capable of forecasting further into the future than you may currently be practicing without significant drops to your accuracy levels. It is truly remarkable, how useful the moving averages are.
 

Self Optimizing Expert Advisor With MQL5 And Python (Part VI): Taking Advantage of Deep Double Descent

Self Optimizing Expert Advisor With MQL5 And Python (Part VI): Taking Advantage of Deep Double Descent

Overfitting in machine learning can take on many different forms. Most commonly, it happens when an AI model learns too much of the noise in the data, and fails to make any useful generalizations. This leads to dismal performance when we assess the model on data it has not seen before. There are many techniques that have been developed to mitigate overfitting, but such methods can often prove challenging to implement, especially when you are just getting started on your journey. However, a recent paper, published by a group of diligent Harvard Alumni, suggests that on certain tasks, overfitting may be a problem of the past. This article will walk you through the research paper, and demonstrate how you can build world-class AI models, inline with the world's leading research.

Self Optimizing Expert Advisor With MQL5 And Python (Part VI): Taking Advantage of Deep Double Descent
Self Optimizing Expert Advisor With MQL5 And Python (Part VI): Taking Advantage of Deep Double Descent
  • www.mql5.com
Traditional machine learning teaches practitioners to be vigilant not to overfit their models. However, this ideology is being challenged by new insights published by diligent researches from Harvard, who have discovered that what appears to be overfitting may in some circumstances be the results of terminating your training procedures prematurely. We will demonstrate how we can use the ideas published in the research paper, to improve our use of AI in forecasting market returns.
 

Multiple Symbol Analysis With Python And MQL5 (Part II): Principal Components Analysis For Portfolio Optimization

Multiple Symbol Analysis With Python And MQL5 (Part II): Principal Components Analysis For Portfolio Optimization

For members of our community looking to sell Expert Advisors, this article will demonstrate how you can create a seamless experience for your end users. Our trading application will flexible and robust at the same time. I will show you how to create trading applications that will allow your clients to easily switch between high, medium and low-risk trading modes. While the PCA algorithm will take care of the heavy lifting for your end users in the background.

Multiple Symbol Analysis With Python And MQL5 (Part II): Principal Components Analysis For Portfolio Optimization
Multiple Symbol Analysis With Python And MQL5 (Part II): Principal Components Analysis For Portfolio Optimization
  • www.mql5.com
Managing trading account risk is a challenge for all traders. How can we develop trading applications that dynamically learn high, medium, and low-risk modes for various symbols in MetaTrader 5? By using PCA, we gain better control over portfolio variance. I’ll demonstrate how to create applications that learn these three risk modes from market data fetched from MetaTrader 5.
 

Feature Engineering With Python And MQL5 (Part II): Angle Of Price

Feature Engineering With Python And MQL5 (Part II): Angle Of Price

Machine learning models are very sensitive instruments. In this series of articles, we will pay significantly more attention to how the transformations we apply to our data, affects our model's performance. Likewise, our models are also sensitive to how the relationship between the input and the target is conveyed. This means, we may need to create new features from the data we have at hand, in order for our model to effectively learn.

Feature Engineering With Python And MQL5 (Part II): Angle Of Price
Feature Engineering With Python And MQL5 (Part II): Angle Of Price
  • www.mql5.com
There are many posts in the MQL5 Forum asking for help calculating the slope of price changes. This article will demonstrate one possible way of calculating the angle formed by the changes in price in any market you wish to trade. Additionally, we will answer if engineering this new feature is worth the extra effort and time invested. We will explore if the slope of the price can improve any of our AI model's accuracy when forecasting the USDZAR pair on the M1.
 

From Python to MQL5: A Journey into Quantum-Inspired Trading Systems

From Python to MQL5: A Journey into Quantum-Inspired Trading Systems

This article explores the application of quantum-inspired concepts in trading systems, bridging theoretical quantum computing with practical implementation in MQL5. We’ll introduce essential quantum principles and guide you from Python prototyping to MQL5 integration, with real-world performance data.

From Python to MQL5: A Journey into Quantum-Inspired Trading Systems
From Python to MQL5: A Journey into Quantum-Inspired Trading Systems
  • www.mql5.com
The article explores the development of a quantum-inspired trading system, transitioning from a Python prototype to an MQL5 implementation for real-world trading. The system uses quantum computing principles like superposition and entanglement to analyze market states, though it runs on classical computers using quantum simulators. Key features include a three-qubit system for analyzing eight market states simultaneously, 24-hour lookback periods, and seven technical indicators for market analysis. While the accuracy rates might seem modest, they provide a significant edge when combined with proper risk management strategies.
 

Hello, I found a bug: copy_rates_range returns the wrong data - it should return OHLC bar data, but it returns tick data. I didn't know where to report it.

I used the sample code from the reference book with other dates and instrument:

from datetime import datetime
import MetaTrader5 as mt5
# выведем данные о пакете MetaTrader5
print("MetaTrader5 package author: ",mt5.__author__)
print("MetaTrader5 package version: ",mt5.__version__)
  
# импортируем модуль pandas для вывода полученных данных в табличной форме
import pandas as pd
pd.set_option('display.max_columns', 500) # сколько столбцов показываем
pd.set_option('display.width', 1500)      # макс. ширина таблицы для показа
# импортируем модуль pytz для работы с таймзоной
import pytz

# установим подключение к терминалу MetaTrader 5
if not mt5.initialize():
    print("initialize() failed, error code =",mt5.last_error())
    quit()

# установим таймзону в UTC
timezone = pytz.timezone("Etc/UTC")
# создадим объекты datetime в таймзоне UTC, чтобы не применялось смещение локальной таймзоны
utc_from = datetime(2024, 1, 10, tzinfo=timezone)
utc_to = datetime(2024, 1, 11, hour = 13, tzinfo=timezone)
# получим бары с USDJPY M5 в интервале 2020.01.10 00:00 - 2020.01.11 13:00 в таймзоне UTC
rates = mt5.copy_rates_range("EURUSDb", mt5.TIMEFRAME_M5, utc_from, utc_to)

# завершим подключение к терминалу MetaTrader 5
mt5.shutdown()
# выведем каждый элемент полученных данных на новой строке
print("Выведем полученные данные как есть")
counter=0
for rate in rates:
    counter+=1
    if counter<=10:
        print(rate)

# создадим из полученных данных DataFrame
rates_frame = pd.DataFrame(rates)
# сконвертируем время в виде секунд в формат datetime
rates_frame['time']=pd.to_datetime(rates_frame['time'], unit='s')

# выведем данные
print("\nВыведем датафрейм с данными")
print(rates_frame.head(10))

and the output I get:

MetaTrader5 package author:  MetaQuotes Ltd.

MetaTrader5 package version:  5.0.4682

Выведем полученные данные как есть

(1704844800, 1.09291, 1.09291, 1.09262, 4607600487953426211, 6, 18, 0.)

(1704845100, 1.09284, 1.09285, 1.09237, 4607599271981526821, 19, 7, 0.)

(1704845400, 1.09263, 1.09284, 1.09263, 4607599587233500737, 15, 16, 0.)

(1704845700, 1.09257, 1.09288, 1.09257, 4607600487953426211, 8, 13, 0.)

(1704846000, 1.09283, 1.09287, 1.09283, 4607600532989422485, 64, 15, 0.)

(1704846300, 1.09285, 1.09286, 1.09265, 4607599992557467200, 17, 15, 0.)

(1704846600, 1.09273, 1.09286, 1.09273, 4607600623061415032, 23, 19, 0.)

(1704846900, 1.09286, 1.09288, 1.09283, 4607600713133407580, 11, 17, 0.)

(1704847200, 1.09288, 1.09288, 1.09282, 4607600713133407580, 9, 13, 0.)

(1704847500, 1.09288, 1.09289, 1.09286, 4607600758169403853, 12, 11, 0.)


Выведем датафрейм с данными

                 time      bid      ask     last               volume  time_msc  flags  volume_real

0 2024-01-10 00:00:00  1.09291  1.09291  1.09262  4607600487953426211         6     18          0.0

1 2024-01-10 00:05:00  1.09284  1.09285  1.09237  4607599271981526821        19      7          0.0

2 2024-01-10 00:10:00  1.09263  1.09284  1.09263  4607599587233500737        15     16          0.0

3 2024-01-10 00:15:00  1.09257  1.09288  1.09257  4607600487953426211         8     13          0.0

4 2024-01-10 00:20:00  1.09283  1.09287  1.09283  4607600532989422485        64     15          0.0

5 2024-01-10 00:25:00  1.09285  1.09286  1.09265  4607599992557467200        17     15          0.0

6 2024-01-10 00:30:00  1.09273  1.09286  1.09273  4607600623061415032        23     19          0.0

7 2024-01-10 00:35:00  1.09286  1.09288  1.09283  4607600713133407580        11     17          0.0

8 2024-01-10 00:40:00  1.09288  1.09288  1.09282  4607600713133407580         9     13          0.0

9 2024-01-10 00:45:00  1.09288  1.09289  1.09286  4607600758169403853        12     11          0.0

And should have received a type of data like this:

MetaTrader5 package author:  MetaQuotes Software Corp. 

MetaTrader5 package version:  5.0.29 

Выведем полученные данные как есть 

(1578614400, 109.513, 109.527, 109.505, 109.521, 43, 2, 0) 

(1578614700, 109.521, 109.549, 109.518, 109.543, 215, 8, 0) 

(1578615000, 109.543, 109.543, 109.466, 109.505, 98, 10, 0) 

(1578615300, 109.504, 109.534, 109.502, 109.517, 155, 8, 0) 

(1578615600, 109.517, 109.539, 109.513, 109.527, 71, 4, 0) 

(1578615900, 109.526, 109.537, 109.484, 109.52, 106, 9, 0) 

(1578616200, 109.52, 109.524, 109.508, 109.51, 205, 7, 0) 

(1578616500, 109.51, 109.51, 109.491, 109.496, 44, 8, 0) 

(1578616800, 109.496, 109.509, 109.487, 109.5, 85, 5, 0) 

(1578617100, 109.5, 109.504, 109.487, 109.489, 82, 7, 0) 

  

Выведем датафрейм с данными 

                 time     open     high      low    close  tick_volume  spread  real_volume 

0 2020-01-10 00:00:00  109.513  109.527  109.505  109.521           43       2            0 

1 2020-01-10 00:05:00  109.521  109.549  109.518  109.543          215       8            0 

2 2020-01-10 00:10:00  109.543  109.543  109.466  109.505           98      10            0 

3 2020-01-10 00:15:00  109.504  109.534  109.502  109.517          155       8            0 

4 2020-01-10 00:20:00  109.517  109.539  109.513  109.527           71       4            0 

5 2020-01-10 00:25:00  109.526  109.537  109.484  109.520          106       9            0 

6 2020-01-10 00:30:00  109.520  109.524  109.508  109.510          205       7            0 

7 2020-01-10 00:35:00  109.510  109.510  109.491  109.496           44       8            0 

8 2020-01-10 00:40:00  109.496  109.509  109.487  109.500           85       5            0 

9 2020-01-10 00:45:00  109.500  109.504  109.487  109.489           82       7            0

I downgraded the MetaTrader5 library to version 5.0.4200 and it worked fine:

MetaTrader5 package author:  MetaQuotes Ltd.

MetaTrader5 package version:  5.0.4200

Выведем полученные данные как есть

(1704844800, 1.09291, 1.09291, 1.09262, 1.09283, 6, 18, 0)

(1704845100, 1.09284, 1.09285, 1.09237, 1.09256, 19, 7, 0)

(1704845400, 1.09263, 1.09284, 1.09263, 1.09263, 15, 16, 0)

(1704845700, 1.09257, 1.09288, 1.09257, 1.09283, 8, 13, 0)

(1704846000, 1.09283, 1.09287, 1.09283, 1.09284, 64, 15, 0)

(1704846300, 1.09285, 1.09286, 1.09265, 1.09272, 17, 15, 0)

(1704846600, 1.09273, 1.09286, 1.09273, 1.09286, 23, 19, 0)

(1704846900, 1.09286, 1.09288, 1.09283, 1.09288, 11, 17, 0)

(1704847200, 1.09288, 1.09288, 1.09282, 1.09288, 9, 13, 0)

(1704847500, 1.09288, 1.09289, 1.09286, 1.09289, 12, 11, 0)


Выведем датафрейм с данными

                 time     open     high      low    close  tick_volume  spread  real_volume

0 2024-01-10 00:00:00  1.09291  1.09291  1.09262  1.09283            6      18            0

1 2024-01-10 00:05:00  1.09284  1.09285  1.09237  1.09256           19       7            0

2 2024-01-10 00:10:00  1.09263  1.09284  1.09263  1.09263           15      16            0

3 2024-01-10 00:15:00  1.09257  1.09288  1.09257  1.09283            8      13            0

4 2024-01-10 00:20:00  1.09283  1.09287  1.09283  1.09284           64      15            0

5 2024-01-10 00:25:00  1.09285  1.09286  1.09265  1.09272           17      15            0

6 2024-01-10 00:30:00  1.09273  1.09286  1.09273  1.09286           23      19            0

7 2024-01-10 00:35:00  1.09286  1.09288  1.09283  1.09288           11      17            0

8 2024-01-10 00:40:00  1.09288  1.09288  1.09282  1.09288            9      13            0

9 2024-01-10 00:45:00  1.09288  1.09289  1.09286  1.09289           12      11            0

Документация по MQL5: Python интеграция / copy_rates_range
Документация по MQL5: Python интеграция / copy_rates_range
  • www.mql5.com
Получает бары в указанном диапазоне дат из терминала MetaTrader 5. Параметры symbol [in]  Имя финансового инструмента, например, ...