Articles with MQL5 programming examples

icon

Access a huge collection of articles with code examples showing how to create indicators and trading robots for the MetaTrader platform in the MQL5 language. Source codes are attached to the articles, so you can open them in MetaEditor and run them to see how the applications work.

These articles will be useful both for those who have just started exploring automated trading and for professional traders with programming experience. They feature not only examples, but also contain new ideas.

Add a new article
latest | best
preview
Implementing an ARIMA training algorithm in MQL5

Implementing an ARIMA training algorithm in MQL5

In this article we will implement an algorithm that applies the Box and Jenkins Autoregressive Integrated Moving Average model by using Powells method of function minimization. Box and Jenkins stated that most time series could be modeled by one or both of two frameworks.
preview
Population optimization algorithms: ElectroMagnetism-like algorithm (ЕМ)

Population optimization algorithms: ElectroMagnetism-like algorithm (ЕМ)

The article describes the principles, methods and possibilities of using the Electromagnetic Algorithm in various optimization problems. The EM algorithm is an efficient optimization tool capable of working with large amounts of data and multidimensional functions.
preview
Population optimization algorithms: Saplings Sowing and Growing up (SSG)

Population optimization algorithms: Saplings Sowing and Growing up (SSG)

Saplings Sowing and Growing up (SSG) algorithm is inspired by one of the most resilient organisms on the planet demonstrating outstanding capability for survival in a wide variety of conditions.
preview
Population optimization algorithms: Harmony Search (HS)

Population optimization algorithms: Harmony Search (HS)

In the current article, I will study and test the most powerful optimization algorithm - harmonic search (HS) inspired by the process of finding the perfect sound harmony. So what algorithm is now the leader in our rating?
preview
Backpropagation Neural Networks using MQL5 Matrices

Backpropagation Neural Networks using MQL5 Matrices

The article describes the theory and practice of applying the backpropagation algorithm in MQL5 using matrices. It provides ready-made classes along with script, indicator and Expert Advisor examples.
preview
Population optimization algorithms: Gravitational Search Algorithm (GSA)

Population optimization algorithms: Gravitational Search Algorithm (GSA)

GSA is a population optimization algorithm inspired by inanimate nature. Thanks to Newton's law of gravity implemented in the algorithm, the high reliability of modeling the interaction of physical bodies allows us to observe the enchanting dance of planetary systems and galactic clusters. In this article, I will consider one of the most interesting and original optimization algorithms. The simulator of the space objects movement is provided as well.
preview
Understand and Efficiently use OpenCL API by Recreating built-in support as DLL on Linux (Part 2): OpenCL Simple DLL implementation

Understand and Efficiently use OpenCL API by Recreating built-in support as DLL on Linux (Part 2): OpenCL Simple DLL implementation

Continued from the part 1 in the series, now we proceed to implement as a simple DLL then test with MetaTrader 5. This will prepare us well before developing a full-fledge OpenCL as DLL support in the following part to come.
preview
Implementing the Janus factor in MQL5

Implementing the Janus factor in MQL5

Gary Anderson developed a method of market analysis based on a theory he dubbed the Janus Factor. The theory describes a set of indicators that can be used to reveal trends and assess market risk. In this article we will implement these tools in mql5.
preview
Canvas based indicators: Filling channels with transparency

Canvas based indicators: Filling channels with transparency

In this article I'll introduce a method for creating custom indicators whose drawings are made using the class CCanvas from standard library and see charts properties for coordinates conversion. I'll approach specially indicators which need to fill the area between two lines using transparency.
preview
Category Theory in MQL5 (Part 4): Spans, Experiments, and Compositions

Category Theory in MQL5 (Part 4): Spans, Experiments, and Compositions

Category Theory is a diverse and expanding branch of Mathematics which as of yet is relatively uncovered in the MQL5 community. These series of articles look to introduce and examine some of its concepts with the overall goal of establishing an open library that provides insight while hopefully furthering the use of this remarkable field in Traders' strategy development.
preview
MQL5 Cookbook — Macroeconomic events database

MQL5 Cookbook — Macroeconomic events database

The article discusses the possibilities of handling databases based on the SQLite engine. The CDatabase class has been formed for convenience and efficient use of OOP principles. It is subsequently involved in the creation and management of the database of macroeconomic events. The article provides the examples of using multiple methods of the CDatabase class.
preview
Population optimization algorithms: Bacterial Foraging Optimization (BFO)

Population optimization algorithms: Bacterial Foraging Optimization (BFO)

E. coli bacterium foraging strategy inspired scientists to create the BFO optimization algorithm. The algorithm contains original ideas and promising approaches to optimization and is worthy of further study.
preview
Population optimization algorithms: Invasive Weed Optimization (IWO)

Population optimization algorithms: Invasive Weed Optimization (IWO)

The amazing ability of weeds to survive in a wide variety of conditions has become the idea for a powerful optimization algorithm. IWO is one of the best algorithms among the previously reviewed ones.
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.
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
DoEasy. Controls (Part 31): Scrolling the contents of the ScrollBar control

DoEasy. Controls (Part 31): Scrolling the contents of the ScrollBar control

In this article, I will implement the functionality of scrolling the contents of the container using the buttons of the horizontal scrollbar.
preview
Population optimization algorithms: Firefly Algorithm (FA)

Population optimization algorithms: Firefly Algorithm (FA)

In this article, I will consider the Firefly Algorithm (FA) optimization method. Thanks to the modification, the algorithm has turned from an outsider into a real rating table leader.
preview
DoEasy. Controls (Part 30): Animating the ScrollBar control

DoEasy. Controls (Part 30): Animating the ScrollBar control

In this article, I will continue the development of the ScrollBar control and start implementing the mouse interaction functionality. In addition, I will expand the lists of mouse state flags and events.
preview
Measuring Indicator Information

Measuring Indicator Information

Machine learning has become a popular method for strategy development. Whilst there has been more emphasis on maximizing profitability and prediction accuracy , the importance of processing the data used to build predictive models has not received a lot of attention. In this article we consider using the concept of entropy to evaluate the appropriateness of indicators to be used in predictive model building as documented in the book Testing and Tuning Market Trading Systems by Timothy Masters.
preview
Population optimization algorithms: Fish School Search (FSS)

Population optimization algorithms: Fish School Search (FSS)

Fish School Search (FSS) is a new optimization algorithm inspired by the behavior of fish in a school, most of which (up to 80%) swim in an organized community of relatives. It has been proven that fish aggregations play an important role in the efficiency of foraging and protection from predators.
preview
DoEasy. Controls (Part 29): ScrollBar auxiliary control

DoEasy. Controls (Part 29): ScrollBar auxiliary control

In this article, I will start developing the ScrollBar auxiliary control element and its derivative objects — vertical and horizontal scrollbars. A scrollbar is used to scroll the content of the form if it goes beyond the container. Scrollbars are usually located at the bottom and to the right of the form. The horizontal one at the bottom scrolls content left and right, while the vertical one scrolls up and down.
preview
Develop a Proof-of-Concept DLL with C++ multi-threading support for MetaTrader 5 on Linux

Develop a Proof-of-Concept DLL with C++ multi-threading support for MetaTrader 5 on Linux

We will begin the journey to explore the steps and workflow on how to base development for MetaTrader 5 platform solely on Linux system in which the final product works seamlessly on both Windows and Linux system. We will get to know Wine, and Mingw; both are the essential tools to make cross-platform development works. Especially Mingw for its threading implementations (POSIX, and Win32) that we need to consider in choosing which one to go with. We then build a proof-of-concept DLL and consume it in MQL5 code, finally compare the performance of both threading implementations. All for your foundation to expand further on your own. You should be comfortable building MT related tools on Linux after reading this article.
preview
MQL5 Cookbook — Services

MQL5 Cookbook — Services

The article describes the versatile capabilities of services — MQL5 programs that do not require binding graphs. I will also highlight the differences of services from other MQL5 programs and emphasize the nuances of the developer's work with services. As examples, the reader is offered various tasks covering a wide range of functionality that can be implemented as a service.
preview
Population optimization algorithms: Cuckoo Optimization Algorithm (COA)

Population optimization algorithms: Cuckoo Optimization Algorithm (COA)

The next algorithm I will consider is cuckoo search optimization using Levy flights. This is one of the latest optimization algorithms and a new leader in the leaderboard.
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.
preview
Population optimization algorithms: Grey Wolf Optimizer (GWO)

Population optimization algorithms: Grey Wolf Optimizer (GWO)

Let's consider one of the newest modern optimization algorithms - Grey Wolf Optimization. The original behavior on test functions makes this algorithm one of the most interesting among the ones considered earlier. This is one of the top algorithms for use in training neural networks, smooth functions with many variables.
preview
Population optimization algorithms: Artificial Bee Colony (ABC)

Population optimization algorithms: Artificial Bee Colony (ABC)

In this article, we will study the algorithm of an artificial bee colony and supplement our knowledge with new principles of studying functional spaces. In this article, I will showcase my interpretation of the classic version of the algorithm.
preview
Non-linear indicators

Non-linear indicators

In this article, I will make an attempt to consider some ways of building non-linear indicators and their use in trading. There are quite a few indicators in the MetaTrader trading platform that use non-linear approaches.
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.
preview
DoEasy. Controls (Part 26): Finalizing the ToolTip WinForms object and moving on to ProgressBar development

DoEasy. Controls (Part 26): Finalizing the ToolTip WinForms object and moving on to ProgressBar development

In this article, I will complete the development of the ToolTip control and start the development of the ProgressBar WinForms object. While working on objects, I will develop universal functionality for animating controls and their components.
preview
DoEasy. Controls (Part 25): Tooltip WinForms object

DoEasy. Controls (Part 25): Tooltip WinForms object

In this article, I will start developing the Tooltip control, as well as new graphical primitives for the library. Naturally, not every element has a tooltip, but every graphical object has the ability to set it.
preview
Population optimization algorithms: Ant Colony Optimization (ACO)

Population optimization algorithms: Ant Colony Optimization (ACO)

This time I will analyze the Ant Colony optimization algorithm. The algorithm is very interesting and complex. In the article, I make an attempt to create a new type of ACO.
preview
DoEasy. Controls (Part 24): Hint auxiliary WinForms object

DoEasy. Controls (Part 24): Hint auxiliary WinForms object

In this article, I will revise the logic of specifying the base and main objects for all WinForms library objects, develop a new Hint base object and several of its derived classes to indicate the possible direction of moving the separator.
preview
Adaptive indicators

Adaptive indicators

In this article, I will consider several possible approaches to creating adaptive indicators. Adaptive indicators are distinguished by the presence of feedback between the values of the input and output signals. This feedback allows the indicator to independently adjust to the optimal processing of financial time series values.
preview
DoEasy. Controls (Part 23): Improving TabControl and SplitContainer WinForms objects

DoEasy. Controls (Part 23): Improving TabControl and SplitContainer WinForms objects

In this article, I will add new mouse events relative to the boundaries of the working areas of WinForms objects and fix some shortcomings in the functioning of the TabControl and SplitContainer controls.
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.
preview
Developing an Expert Advisor from scratch (Part 30): CHART TRADE as an indicator?

Developing an Expert Advisor from scratch (Part 30): CHART TRADE as an indicator?

Today we are going to use Chart Trade again, but this time it will be an on-chart indicator which may or may not be present on the chart.
preview
Population optimization algorithms: Particle swarm (PSO)

Population optimization algorithms: Particle swarm (PSO)

In this article, I will consider the popular Particle Swarm Optimization (PSO) algorithm. Previously, we discussed such important characteristics of optimization algorithms as convergence, convergence rate, stability, scalability, as well as developed a test stand and considered the simplest RNG algorithm.
preview
DoEasy. Controls (Part 21): SplitContainer control. Panel separator

DoEasy. Controls (Part 21): SplitContainer control. Panel separator

In this article, I will create the class of an auxiliary panel separator object for the SplitContainer control.
preview
DoEasy. Controls (Part 20): SplitContainer WinForms object

DoEasy. Controls (Part 20): SplitContainer WinForms object

In the current article, I will start developing the SplitContainer control from the MS Visual Studio toolkit. This control consists of two panels separated by a vertical or horizontal movable separator.