MQL4 and MQL5 Programming Articles

icon

Study the MQL5 language for programming trading strategies in numerous published articles mostly written by you - the community members. The articles are grouped into categories to help you quicker find answers to any questions related to programming: Integration, Tester, Trading Strategies, etc.

Follow our new publications and discuss them on the Forum!

Add a new article
latest | best
Interview with Andrey Bobryashov (ATC 2011)
Interview with Andrey Bobryashov (ATC 2011)

Interview with Andrey Bobryashov (ATC 2011)

Since the first Automated Trading Championship we have seen plenty of trading robots in our TOP-10 created with the use of various methods. Excellent results were shown both by the Exper Advisors based on standard indicators, and complicated analytical complexes with weekly automatic optimization of their own parameters.
preview
Neural networks made easy (Part 48): Methods for reducing overestimation of Q-function values

Neural networks made easy (Part 48): Methods for reducing overestimation of Q-function values

In the previous article, we introduced the DDPG method, which allows training models in a continuous action space. However, like other Q-learning methods, DDPG is prone to overestimating Q-function values. This problem often results in training an agent with a suboptimal strategy. In this article, we will look at some approaches to overcome the mentioned issue.
Interview with Antonio Morillas (ATC 2011)
Interview with Antonio Morillas (ATC 2011)

Interview with Antonio Morillas (ATC 2011)

Antonio Morillas from Spain (sallirom, by the way - it is reversed surname!) was first who doubled his starting balance from the beginning of the Championship and thus attracted our attention. His trading strategy is extremely risky. We decided to talk to Antonio about risk and luck as these are part and parcel of Automated Trading Championship.
preview
Multilayer perceptron and backpropagation algorithm (Part 3): Integration with the Strategy Tester - Overview (I).

Multilayer perceptron and backpropagation algorithm (Part 3): Integration with the Strategy Tester - Overview (I).

The multilayer perceptron is an evolution of the simple perceptron which can solve non-linear separable problems. Together with the backpropagation algorithm, this neural network can be effectively trained. In Part 3 of the Multilayer Perceptron and Backpropagation series, we'll see how to integrate this technique into the Strategy Tester. This integration will allow the use of complex data analysis aimed at making better decisions to optimize your trading strategies. In this article, we will discuss the advantages and problems of this technique.
preview
Integrate Your Own LLM into EA (Part 2): Example of Environment Deployment

Integrate Your Own LLM into EA (Part 2): Example of Environment Deployment

With the rapid development of artificial intelligence today, language models (LLMs) are an important part of artificial intelligence, so we should think about how to integrate powerful LLMs into our algorithmic trading. For most people, it is difficult to fine-tune these powerful models according to their needs, deploy them locally, and then apply them to algorithmic trading. This series of articles will take a step-by-step approach to achieve this goal.
preview
Brute force approach to patterns search (Part V): Fresh angle

Brute force approach to patterns search (Part V): Fresh angle

In this article, I will show a completely different approach to algorithmic trading I ended up with after quite a long time. Of course, all this has to do with my brute force program, which has undergone a number of changes that allow it to solve several problems simultaneously. Nevertheless, the article has turned out to be more general and as simple as possible, which is why it is also suitable for those who know nothing about brute force.
Interview with Vitaly Antonov (ATC 2011)
Interview with Vitaly Antonov (ATC 2011)

Interview with Vitaly Antonov (ATC 2011)

It was only this summer that Vitaly Antonov (beast) has learned about the upcoming Automated Trading Championship and got to know MetaTrader 5 terminal. Time was running out, besides, Vitaly was a newcomer. So, he randomly chose GBPUSD currency pair to develop his trading system. And the choice turned out to be successful. It would have been impossible to use other symbols with the strategy.
preview
Integrating ML models with the Strategy Tester (Part 3): Managing CSV files (II)

Integrating ML models with the Strategy Tester (Part 3): Managing CSV files (II)

This material provides a complete guide to creating a class in MQL5 for efficient management of CSV files. We will see the implementation of methods for opening, writing, reading, and transforming data. We will also consider how to use them to store and access information. In addition, we will discuss the limitations and the most important aspects of using such a class. This article ca be a valuable resource for those who want to learn how to process CSV files in MQL5.
preview
Python, ONNX and MetaTrader 5: Creating a RandomForest model with RobustScaler and PolynomialFeatures data preprocessing

Python, ONNX and MetaTrader 5: Creating a RandomForest model with RobustScaler and PolynomialFeatures data preprocessing

In this article, we will create a random forest model in Python, train the model, and save it as an ONNX pipeline with data preprocessing. After that we will use the model in the MetaTrader 5 terminal.
preview
Developing an MQL5 RL agent with RestAPI integration (Part 2): MQL5 functions for HTTP interaction with the tic-tac-toe game REST API

Developing an MQL5 RL agent with RestAPI integration (Part 2): MQL5 functions for HTTP interaction with the tic-tac-toe game REST API

In this article we will talk about how MQL5 can interact with Python and FastAPI, using HTTP calls in MQL5 to interact with the tic-tac-toe game in Python. The article discusses the creation of an API using FastAPI for this integration and provides a test script in MQL5, highlighting the versatility of MQL5, the simplicity of Python, and the effectiveness of FastAPI in connecting different technologies to create innovative solutions.
ATC Champions League: Interview with Roman Zamozhniy (ATC 2011)
ATC Champions League: Interview with Roman Zamozhniy (ATC 2011)

ATC Champions League: Interview with Roman Zamozhniy (ATC 2011)

This is the first interview in the "ATC Champions League" project. Roman Zamozhniy (Rich) from Ukraine was the winner of the first Automated Trading Championship in 2006. In addition, he is a regular participant of our Championships - he has not missed a single contest. In this interview, we talked about Roman's first place and tried to figure out what is necessary for successful participation.
preview
DoEasy. Controls (Part 28): Bar styles in the ProgressBar control

DoEasy. Controls (Part 28): Bar styles in the ProgressBar control

In this article, I will develop display styles and description text for the progress bar of the ProgressBar control.
ATC Champions League: Interview with Olexandr Topchylo (ATC 2011)
ATC Champions League: Interview with Olexandr Topchylo (ATC 2011)

ATC Champions League: Interview with Olexandr Topchylo (ATC 2011)

Interview with Olexandr Topchylo (Better) is the second publication within the "ATC Champions League" project. Having won the Automated Trading Championship 2007, this professional trader caught the attention of investors. Olexandr says that his first place in the ATC 2007 is one of the major events of his trading experience. However, later on this popularity helped him discover the biggest disappointment - it is so easy to lose investors after the first drawdown on an investor account.
preview
DoEasy. Controls (Part 22): SplitContainer. Changing the properties of the created object

DoEasy. Controls (Part 22): SplitContainer. Changing the properties of the created object

In the current article, I will implement the ability to change the properties and appearance of the newly created SplitContainer control.
Interview with Andrei Moraru (ATC 2011)
Interview with Andrei Moraru (ATC 2011)

Interview with Andrei Moraru (ATC 2011)

Ukrainian programmer Andrei Moraru (enivid) is an active participant of the Automated Trading Championship beginning from 2007. Andrei had already come in our view at that time and now we have decided to find out if there occured any changes in his attitude towards trading and selection of trading strategies for the past four years, and also to know about his new Expert Advisor.
preview
Data Science and Machine Learning (Part 19): Supercharge Your AI models with AdaBoost

Data Science and Machine Learning (Part 19): Supercharge Your AI models with AdaBoost

AdaBoost, a powerful boosting algorithm designed to elevate the performance of your AI models. AdaBoost, short for Adaptive Boosting, is a sophisticated ensemble learning technique that seamlessly integrates weak learners, enhancing their collective predictive strength.
preview
Developing an MQTT client for MetaTrader 5: a TDD approach

Developing an MQTT client for MetaTrader 5: a TDD approach

This article reports the first attempts in the development of a native MQTT client for MQL5. MQTT is a Client Server publish/subscribe messaging transport protocol. It is lightweight, open, simple, and designed to be easy to implement. These characteristics make it ideal for use in many situations.
preview
Category Theory in MQL5 (Part 7): Multi, Relative and Indexed Domains

Category Theory in MQL5 (Part 7): Multi, Relative and Indexed Domains

Category Theory is a diverse and expanding branch of Mathematics which is only recently getting some coverage in the MQL5 community. These series of articles look to explore and examine some of its concepts & axioms with the overall goal of establishing an open library that provides insight while also hopefully furthering the use of this remarkable field in Traders' strategy development.
preview
Developing a trading Expert Advisor from scratch (Part 25): Providing system robustness (II)

Developing a trading Expert Advisor from scratch (Part 25): Providing system robustness (II)

In this article, we will make the final step towards the EA's performance. So, be prepared for a long read. To make our Expert Advisor reliable, we will first remove everything from the code that is not part of the trading system.
preview
How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 7): ZigZag with Awesome Oscillator Indicators Signal

How to create a simple Multi-Currency Expert Advisor using MQL5 (Part 7): ZigZag with Awesome Oscillator Indicators Signal

The multi-currency expert advisor in this article is an expert advisor or automated trading that uses ZigZag indicator which are filtered with the Awesome Oscillator or filter each other's signals.
preview
Neural networks made easy (Part 47): Continuous action space

Neural networks made easy (Part 47): Continuous action space

In this article, we expand the range of tasks of our agent. The training process will include some aspects of money and risk management, which are an integral part of any trading strategy.
preview
Developing a Replay System (Part 26): Expert Advisor project — C_Terminal class

Developing a Replay System (Part 26): Expert Advisor project — C_Terminal class

We can now start creating an Expert Advisor for use in the replay/simulation system. However, we need something improved, not a random solution. Despite this, we should not be intimidated by the initial complexity. It's important to start somewhere, otherwise we end up ruminating about the difficulty of a task without even trying to overcome it. That's what programming is all about: overcoming obstacles through learning, testing, and extensive research.
preview
Developing a trading Expert Advisor from scratch (Part 26): Towards the future (I)

Developing a trading Expert Advisor from scratch (Part 26): Towards the future (I)

Today we will take our order system to the next level. But before that, we need to solve a few problems. Now we have some questions that are related to how we want to work and what things we do during the trading day.
Grouped File Operations
Grouped File Operations

Grouped File Operations

It is sometimes necessary to perform identical operations with a group of files. If you have a list of files included into a group, then it is no problem. However, if you need to make this list yourself, then a question arises: "How can I do this?" The article proposes doing this using functions FindFirstFile() and FindNextFile() included in kernel32.dll.
preview
DoEasy. Controls (Part 16): TabControl WinForms object — several rows of tab headers, stretching headers to fit the container

DoEasy. Controls (Part 16): TabControl WinForms object — several rows of tab headers, stretching headers to fit the container

In this article, I will continue the development of TabControl and implement the arrangement of tab headers on all four sides of the control for all modes of setting the size of headers: Normal, Fixed and Fill To Right.
Idleness is the Stimulus to Progress. Semiautomatic Marking a Template
Idleness is the Stimulus to Progress. Semiautomatic Marking a Template

Idleness is the Stimulus to Progress. Semiautomatic Marking a Template

Among the dozens of examples of how to work with charts, there is a method of manual marking a template. Trend lines, channels, support/resistance levels, etc. are imposed in a chart. Surely, there are some special programs for this kind of work. Everyone decides on his/her own which method to use. In this article, I offer you for your consideration the methods of manual marking with subsequent automating some elements of the repeated routine actions.
preview
Neural networks made easy (Part 34): Fully Parameterized Quantile Function

Neural networks made easy (Part 34): Fully Parameterized Quantile Function

We continue studying distributed Q-learning algorithms. In previous articles, we have considered distributed and quantile Q-learning algorithms. In the first algorithm, we trained the probabilities of given ranges of values. In the second algorithm, we trained ranges with a given probability. In both of them, we used a priori knowledge of one distribution and trained another one. In this article, we will consider an algorithm which allows the model to train for both distributions.
preview
Developing a Replay System (Part 32): Order System (I)

Developing a Replay System (Part 32): Order System (I)

Of all the things that we have developed so far, this system, as you will probably notice and eventually agree, is the most complex. Now we need to do something very simple: make our system simulate the operation of a trading server. This need to accurately implement the way the trading server operates seems like a no-brainer. At least in words. But we need to do this so that the everything is seamless and transparent for the user of the replay/simulation system.
preview
DoEasy. Controls (Part 27): Working on ProgressBar WinForms object

DoEasy. Controls (Part 27): Working on ProgressBar WinForms object

In this article, I will continue the development of the ProgressBar control. In particular, I will create the functionality for managing the progress bar and visual effects.
Interview with Sergey Nikitin (ATC 2011)
Interview with Sergey Nikitin (ATC 2011)

Interview with Sergey Nikitin (ATC 2011)

In the second week of the competition, the Expert Advisor of Sergey Nikitin (VNIK) trading on two currency pairs EURUSD and EURJPY got featured on the very top drawing away from the rest. Multicurrency Expert Advisors always attract attention in the Championship, especially those that show good results. We talked with Sergey about the role of luck in a trader's life and his way of trading.
preview
Automated exchange grid trading using stop pending orders on Moscow Exchange (MOEX)

Automated exchange grid trading using stop pending orders on Moscow Exchange (MOEX)

The article considers the grid trading approach based on stop pending orders and implemented in an MQL5 Expert Advisor on the Moscow Exchange (MOEX). When trading in the market, one of the simplest strategies is a grid of orders designed to "catch" the market price.
preview
Understand and efficiently use OpenCL API by recreating built-in support as DLL on Linux (Part 1): Motivation and validation

Understand and efficiently use OpenCL API by recreating built-in support as DLL on Linux (Part 1): Motivation and validation

Bulit-in OpenCL support in MetaTrader 5 still has a major problem especially the one about device selection error 5114 resulting from unable to create an OpenCL context using CL_USE_GPU_ONLY, or CL_USE_GPU_DOUBLE_ONLY although it properly detects GPU. It works fine with directly using of ordinal number of GPU device we found in Journal tab, but that's still considered a bug, and users should not hard-code a device. We will solve it by recreating an OpenCL support as DLL with C++ on Linux. Along the journey, we will get to know OpenCL from concept to best practices in its API usage just enough for us to put into great use later when we deal with DLL implementation in C++ and consume it with MQL5.
Simultaneous Displaying of the Signals of Several Indicators from the Four Timeframes
Simultaneous Displaying of the Signals of Several Indicators from the Four Timeframes

Simultaneous Displaying of the Signals of Several Indicators from the Four Timeframes

While manual trading you have to keep an eye on the values of several indicators. It is a little bit different from mechanical trading. If you have two or three indicators and you have chosen a one timeframe for trading, it is not a complicated task. But what will you do if you have five or six indicators and your trading strategy requires considering the signals on the several timeframes?
Interview with Matúš German (ATC 2011)
Interview with Matúš German (ATC 2011)

Interview with Matúš German (ATC 2011)

On the second day of the Championship the Expert Advisor created by Matúš German (gery18) increased its capital by 2.5 times and took the lead being ahead of all competitors. Matúš himself doubts his Expert Advisor will win, he thinks that luck and high risk were the reasons of such unexpected rise.
Interview with Ilnur Khasanov (ATC 2011)
Interview with Ilnur Khasanov (ATC 2011)

Interview with Ilnur Khasanov (ATC 2011)

The Expert Advisor of Ilnur Khasanov (aharata) is holding its place in our TOP-10 chart of the Automated Trading Championship 2011 participants from the third week already, though Ilnur's acquaintance with Forex has started only a year ago. The idea that forms the basis of the Expert Advisor is simple but the trading robot contains self-optimization elements. Perhaps, that is the key to its survival? Besides, the author had to change the Expert Advisor planned to be submitted for the Championship...
preview
Developing a Replay System — Market simulation (Part 11): Birth of the SIMULATOR (I)

Developing a Replay System — Market simulation (Part 11): Birth of the SIMULATOR (I)

In order to use the data that forms the bars, we must abandon replay and start developing a simulator. We will use 1 minute bars because they offer the least amount of difficulty.
preview
Developing a Replay System — Market simulation (Part 14): Birth of the SIMULATOR (IV)

Developing a Replay System — Market simulation (Part 14): Birth of the SIMULATOR (IV)

In this article we will continue the simulator development stage. this time we will see how to effectively create a RANDOM WALK type movement. This type of movement is very intriguing because it forms the basis of everything that happens in the capital market. In addition, we will begin to understand some concepts that are fundamental to those conducting market analysis.
preview
Introduction to MQL5 (Part 7): Beginner's Guide to Building Expert Advisors and Utilizing AI-Generated Code in MQL5

Introduction to MQL5 (Part 7): Beginner's Guide to Building Expert Advisors and Utilizing AI-Generated Code in MQL5

Discover the ultimate beginner's guide to building Expert Advisors (EAs) with MQL5 in our comprehensive article. Learn step-by-step how to construct EAs using pseudocode and harness the power of AI-generated code. Whether you're new to algorithmic trading or seeking to enhance your skills, this guide provides a clear path to creating effective EAs.
preview
Population optimization algorithms: Bat algorithm (BA)

Population optimization algorithms: Bat algorithm (BA)

In this article, I will consider the Bat Algorithm (BA), which shows good convergence on smooth functions.
preview
Neural networks made easy (Part 60): Online Decision Transformer (ODT)

Neural networks made easy (Part 60): Online Decision Transformer (ODT)

The last two articles were devoted to the Decision Transformer method, which models action sequences in the context of an autoregressive model of desired rewards. In this article, we will look at another optimization algorithm for this method.