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
DoEasy. Controls (Part 19): Scrolling tabs in TabControl, WinForms object events

DoEasy. Controls (Part 19): Scrolling tabs in TabControl, WinForms object events

In this article, I will create the functionality for scrolling tab headers in TabControl using scrolling buttons. The functionality is meant to place tab headers into a single line from either side of the control.
preview
DoEasy. Controls (Part 18): Functionality for scrolling tabs in TabControl

DoEasy. Controls (Part 18): Functionality for scrolling tabs in TabControl

In this article, I will place header scrolling control buttons in TabControl WinForms object in case the header bar does not fit the size of the control. Besides, I will implement the shift of the header bar when clicking on the cropped tab header.
preview
Developing a trading Expert Advisor from scratch (Part 28): Towards the future (III)

Developing a trading Expert Advisor from scratch (Part 28): Towards the future (III)

There is still one task which our order system is not up to, but we will FINALLY figure it out. The MetaTrader 5 provides a system of tickets which allows creating and correcting order values. The idea is to have an Expert Advisor that would make the same ticket system faster and more efficient.
preview
DoEasy. Controls (Part 17): Cropping invisible object parts, auxiliary arrow buttons WinForms objects

DoEasy. Controls (Part 17): Cropping invisible object parts, auxiliary arrow buttons WinForms objects

In this article, I will create the functionality for hiding object sections located beyond their containers. Besides, I will create auxiliary arrow button objects to be used as part of other WinForms objects.
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.
DIY technical indicator
DIY technical indicator

DIY technical indicator

In this article, I will consider the algorithms allowing you to create your own technical indicator. You will learn how to obtain pretty complex and interesting results with very simple initial assumptions.
Market math: profit, loss and costs
Market math: profit, loss and costs

Market math: profit, loss and costs

In this article, I will show you how to calculate the total profit or loss of any trade, including commission and swap. I will provide the most accurate mathematical model and use it to write the code and compare it with the standard. Besides, I will also try to get on the inside of the main MQL5 function to calculate profit and get to the bottom of all the necessary values from the specification.
preview
Developing a trading Expert Advisor from scratch (Part 27): Towards the future (II)

Developing a trading Expert Advisor from scratch (Part 27): Towards the future (II)

Let's move on to a more complete order system directly on the chart. In this article, I will show a way to fix the order system, or rather, to make it more intuitive.
preview
DoEasy. Controls (Part 15): TabControl WinForms object — several rows of tab headers, tab handling methods

DoEasy. Controls (Part 15): TabControl WinForms object — several rows of tab headers, tab handling methods

In this article, I will continue working on the TabControl WinForm object — I will create a tab field object class, make it possible to arrange tab headers in several rows and add methods for handling object tabs.
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.
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.
Population optimization algorithms
Population optimization algorithms

Population optimization algorithms

This is an introductory article on optimization algorithm (OA) classification. The article attempts to create a test stand (a set of functions), which is to be used for comparing OAs and, perhaps, identifying the most universal algorithm out of all widely known ones.
preview
DoEasy. Controls (Part 14): New algorithm for naming graphical elements. Continuing work on the TabControl WinForms object

DoEasy. Controls (Part 14): New algorithm for naming graphical elements. Continuing work on the TabControl WinForms object

In this article, I will create a new algorithm for naming all graphical elements meant for building custom graphics, as well as continue developing the TabControl WinForms object.
preview
DoEasy. Controls (Part 13): Optimizing interaction of WinForms objects with the mouse, starting the development of the TabControl WinForms object

DoEasy. Controls (Part 13): Optimizing interaction of WinForms objects with the mouse, starting the development of the TabControl WinForms object

In this article, I will fix and optimize handling the appearance of WinForms objects after moving the mouse cursor away from the object, as well as start the development of the TabControl WinForms object.
preview
DoEasy. Controls (Part 12): Base list object, ListBox and ButtonListBox WinForms objects

DoEasy. Controls (Part 12): Base list object, ListBox and ButtonListBox WinForms objects

In this article, I am going to create the base object of WinForms object lists, as well as the two new objects: ListBox and ButtonListBox.
preview
DoEasy. Controls (Part 11): WinForms objects — groups, CheckedListBox WinForms object

DoEasy. Controls (Part 11): WinForms objects — groups, CheckedListBox WinForms object

The article considers grouping WinForms objects and creation of the CheckBox objects list object.
preview
DoEasy. Controls (Part 10): WinForms objects — Animating the interface

DoEasy. Controls (Part 10): WinForms objects — Animating the interface

It is time to animate the graphical interface by implementing the functionality for object interaction with users and objects. The new functionality will also be necessary to let more complex objects work correctly.
preview
Matrix and Vector operations in MQL5

Matrix and Vector operations in MQL5

Matrices and vectors have been introduced in MQL5 for efficient operations with mathematical solutions. The new types offer built-in methods for creating concise and understandable code that is close to mathematical notation. Arrays provide extensive capabilities, but there are many cases in which matrices are much more efficient.
preview
DoEasy. Controls (Part 9): Re-arranging WinForms object methods, RadioButton and Button controls

DoEasy. Controls (Part 9): Re-arranging WinForms object methods, RadioButton and Button controls

In this article, I will fix the names of WinForms object class methods and create Button and RadioButton WinForms objects.
preview
CCI indicator. Upgrade and new features

CCI indicator. Upgrade and new features

In this article, I will consider the possibility of upgrading the CCI indicator. Besides, I will present a modification of the indicator.
preview
DoEasy. Controls (Part 8): Base WinForms objects by categories, GroupBox and CheckBox controls

DoEasy. Controls (Part 8): Base WinForms objects by categories, GroupBox and CheckBox controls

The article considers creation of 'GroupBox' and 'CheckBox' WinForms objects, as well as the development of base objects for WinForms object categories. All created objects are still static, i.e. they are unable to interact with the mouse.
preview
Complex indicators made easy using objects

Complex indicators made easy using objects

This article provides a method to create complex indicators while also avoiding the problems that arise when dealing with multiple plots, buffers and/or combining data from multiple sources.
preview
Developing a trading Expert Advisor from scratch (Part 17): Accessing data on the web (III)

Developing a trading Expert Advisor from scratch (Part 17): Accessing data on the web (III)

In this article we continue considering how to obtain data from the web and to use it in an Expert Advisor. This time we will proceed to developing an alternative system.
preview
DoEasy. Controls (Part 7): Text label control

DoEasy. Controls (Part 7): Text label control

In the current article, I will create the class of the WinForms text label control object. Such an object will have the ability to position its container anywhere, while its own functionality will repeat the functionality of the MS Visual Studio text label. We will be able to set font parameters for a displayed text.
preview
DoEasy. Controls (Part 6): Panel control, auto resizing the container to fit inner content

DoEasy. Controls (Part 6): Panel control, auto resizing the container to fit inner content

In the article, I will continue my work on the Panel WinForms object and implement its auto resizing to fit the general size of Dock objects located inside the panel. Besides, I will add the new properties to the Symbol library object.
preview
Neural networks made easy (Part 14): Data clustering

Neural networks made easy (Part 14): Data clustering

It has been more than a year since I published my last article. This is quite a lot time to revise ideas and to develop new approaches. In the new article, I would like to divert from the previously used supervised learning method. This time we will dip into unsupervised learning algorithms. In particular, we will consider one of the clustering algorithms—k-means.
preview
DoEasy. Controls (Part 5): Base WinForms object, Panel control, AutoSize parameter

DoEasy. Controls (Part 5): Base WinForms object, Panel control, AutoSize parameter

In the article, I will create the base object of all library WinForms objects and start implementing the AutoSize property of the Panel WinForms object — auto sizing for fitting the object internal content.
preview
DoEasy. Controls (Part 4): Panel control, Padding and Dock parameters

DoEasy. Controls (Part 4): Panel control, Padding and Dock parameters

In this article, I will implement handling Padding (internal indents/margin on all sides of an element) and Dock parameters (the way an object is located inside its container).
preview
How to master Machine Learning

How to master Machine Learning

Check out this selection of useful materials which can assist traders in improving their algorithmic trading knowledge. The era of simple algorithms is passing, and it is becoming harder to succeed without the use of Machine Learning techniques and Neural Networks.
preview
Developing a trading Expert Advisor from scratch (Part 8): A conceptual leap

Developing a trading Expert Advisor from scratch (Part 8): A conceptual leap

What is the easiest way to implement new functionality? In this article, we will take one step back and then two steps forward.
preview
DoEasy. Controls (Part 3): Creating bound controls

DoEasy. Controls (Part 3): Creating bound controls

In this article, I will create subordinate controls bound to the base element. The development will be performed using the base control functionality. In addition, I will tinker with the graphical element shadow object a bit since it still suffers from some logic errors when applied to any of the objects capable of having a shadow.
preview
DoEasy. Controls (Part 2): Working on the CPanel class

DoEasy. Controls (Part 2): Working on the CPanel class

In the current article, I will get rid of some errors related to handling graphical elements and continue the development of the CPanel control. In particular, I will implement the methods for setting the parameters of the font used by default for all panel text objects.
preview
DoEasy. Controls (Part 1): First steps

DoEasy. Controls (Part 1): First steps

This article starts an extensive topic of creating controls in Windows Forms style using MQL5. My first object of interest is creating the panel class. It is already becoming difficult to manage things without controls. Therefore, I will create all possible controls in Windows Forms style.
preview
Graphics in DoEasy library (Part 100): Making improvements in handling extended standard graphical objects

Graphics in DoEasy library (Part 100): Making improvements in handling extended standard graphical objects

In the current article, I will eliminate obvious flaws in simultaneous handling of extended (and standard) graphical objects and form objects on canvas, as well as fix errors detected during the test performed in the previous article. The article concludes this section of the library description.
preview
Data Science and Machine Learning (Part 03): Matrix Regressions

Data Science and Machine Learning (Part 03): Matrix Regressions

This time our models are being made by matrices, which allows flexibility while it allows us to make powerful models that can handle not only five independent variables but also many variables as long as we stay within the calculations limits of a computer, this article is going to be an interesting read, that's for sure.
preview
Graphics in DoEasy library (Part 99): Moving an extended graphical object using a single control point

Graphics in DoEasy library (Part 99): Moving an extended graphical object using a single control point

In the previous article, I implemented the ability to move pivot points of an extended graphical object using control forms. Now I am going to implement the ability to move a composite graphical object using a single graphical object control point (form).
preview
Graphics in DoEasy library (Part 98): Moving pivot points of extended standard graphical objects

Graphics in DoEasy library (Part 98): Moving pivot points of extended standard graphical objects

In the article, I continue the development of extended standard graphical objects and create the functionality for moving pivot points of composite graphical objects using the control points for managing the coordinates of the graphical object pivot points.
preview
Multiple indicators on one chart (Part 03): Developing definitions for users

Multiple indicators on one chart (Part 03): Developing definitions for users

Today we will update the functionality of the indicator system for the first time. In the previous article within the "Multiple indicators on one chart" we considered the basic code which allows using more than one indicator in a chart subwindow. But what was presented was just the starting base of a much larger system.
preview
Multiple indicators on one chart (Part 02): First experiments

Multiple indicators on one chart (Part 02): First experiments

In the previous article "Multiple indicators on one chart" I presented the concept and the basics of how to use multiple indicators on one chart. In this article, I will provide the source code and will explain it in detail.
preview
What you can do with Moving Averages

What you can do with Moving Averages

The article considers several methods of applying the Moving Average indicator. Each method involving a curve analysis is accompanied by indicators visualizing the idea. In most cases, the ideas shown here belong to their respected authors. My sole task was to bring them together to let you see the main approaches and, hopefully, make more reasonable trading decisions. MQL5 proficiency level — basic.