Every trading platform, including MetaTrader5, comes equipped with dozens of built-in technical indicators, such as Exponential Moving Averages, Commodity Channel Index, Bollinger Bands, you name it. These platforms usually offer tools to develop custom indicators utilizing prices, volumes, and economic forecasts. None of them, however, provide direct capabilities to use neural network models as indicators or decision-making units within the trading logic.
In this series of articles, I describe the approach and software I developed to integrate trained pattern recognition neural network models into your MetaTrader5 indicators and trading strategies. With this framework and toolkit, you can collect data samples, train your models, and deploy them as MT5 indicators or trading strategies. The best part? All these steps require no coding, allowing you to transform your idea into a machine learning indicator in about 30 minutes.
Price Patterns as Trading Signals
While machine learning models can be applied to virtually every aspect of trading, I have specifically focused on pattern recognition because, in my experience, it is one of the most effective and profitable approaches. After all, in crowded markets with a large number of retail traders, price movements often reflect collective psychology, and we inherently think in patterns.
There are patterns which can be easily detected algorithmically—such as bullish engulfing, head and shoulders, or double tops and bottoms. Others are practically impossible to describe with code, like Elliott Wave patterns or complex harmonic patterns (like the Gartley or Butterfly), which require nuanced interpretation of price movements and trend continuations.
While the software and approach described in this and subsequent articles can be used to detect any price pattern, for demonstration purposes, I will use a relatively simple example. It can be characterized by a non-volatile period followed by a sudden price rise and then a sharp price drop. This pattern typically followed by a sharp price drop and, therefore, can be considered as a sell signal. I have used the same pattern in my previous articles on developing profitable strategies using the DT-Box tool.
Pros and Cons of Using Price Patterns for Trading
Pro: Patterns are very precise and do not have lag, unlike traditional indicators. Con: The quality of trading signals based on patterns greatly depends on the detecting algorithm, which can vary in effectiveness.
Pro: Patterns look the same on every timeframe, trading instruments and even different markets, including cryptocurrencies. Con: They are quite hard to detect using simple conditional logic due to the complexity of pattern formation.
Pro: Patterns are based on price action, which many traders believe is a direct reflection of market sentiment. Con: Recognition can be subjective, leading to inconsistency in signal interpretation.
The tools and methods I developed and describe in these articles are designed to address these cons, primarily by simplifying the complexity of building detection algorithms.
Steps to develop ML-based pattern recognition indicators
In the initial step, we prepare the pattern data needed to train our model. Data collection is complex and time-consuming, typically requiring significant effort. To streamline this process, I developed the CollectPatternData MT5 script, which automates the labor-intensive tasks. Simply mark the price patterns you want your model to recognize on the chart, and the script will handle all the necessary data collection, saving it into CSV files. It automatically divides the pattern data into two groups: a training set, which contains 80% of the data, and a test set, which contains 20%. The data is saved into two separate files ready for immediate use in model training. You can find a detailed description of collecting training and test data using MT5 script in this article.
In the second step, we’ll move to Google Colab to train our model. We normalize the data and visually compare different normalization techniques. We also visualize our normalized training and test datasets to ensure accuracy. Then we create our model architecture using TensorFlow/Keras and train it with the collected data. We interpret the training results to select the best model. Since this process is conducted in Google Colab, you don’t need any special software installed on your PC. Here, you can find detailed description of training your model in Google Colab using data from MetaTrader5.
In the third and most exciting step, we will use the model as a MetaTrader5 indicator. For every bar close, the indicator will display a probability of your pattern being detected, with a probability distribution ranging from 0 to 1. Thus, the indicator will appear the same way as other MT5 oscillators. Since MetaTrader5 does not have the capability to run neural network models directly, I developed the DT-Box-Inference app. This application allows you to run trained models in prediction mode, and the DT-MLIndicator, which connects through a socket to the app and displays the model’s predictions. Here is the step-by-step description of using your ML model as Metatrader5 indicator with DT-Box-Inference.
As mentioned in the article header, with this workflow and the tools provided, the entire process from an idea to a functioning MetaTrader5 pattern recognition indicator can be completed in about 30 minutes.
To demonstrate how exciting price pattern recognition can be, here is an out-of-sample test (October 2024) of a strategy based on the pattern used throughout this article:
If you’re as excited as I am, now is the time to dive into the details of each step. All the articles are designed in a tutorial format, and I strongly encourage you to follow along with the steps as you read. Start with the installation and configuration of DT-Box-Inference and the necessary MetaTrader5 files. Then, proceed through steps one (data collecting), two (model training) and three (using your modes as indicator). Finally, if you wish to customize the source code to better suit your goals, here you will find links to my GitHub repositories.
Enjoy!
Oh, and don’t forget to let me know your feedback – pavel@pavelchigirev.com