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
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.
preview
Making charts more interesting: Adding a background

Making charts more interesting: Adding a background

Many workstations contain some representative image which shows something about the user. These images make the working environment more beautiful and exciting. Let's see how to make the charts more interesting by adding a background.
preview
Graphics in DoEasy library (Part 97): Independent handling of form object movement

Graphics in DoEasy library (Part 97): Independent handling of form object movement

In this article, I will consider the implementation of the independent dragging of any form objects using a mouse. Besides, I will complement the library by error messages and new deal properties previously implemented into the terminal and MQL5.
preview
Using the CCanvas class in MQL applications

Using the CCanvas class in MQL applications

The article considers the use of the CCanvas class in MQL applications. The theory is accompanied by detailed explanations and examples for thorough understanding of CCanvas basics.
preview
Multiple indicators on one chart (Part 01): Understanding the concepts

Multiple indicators on one chart (Part 01): Understanding the concepts

Today we will learn how to add multiple indicators running simultaneously on one chart, but without occupying a separate area on it. Many traders feel more confident if they monitor multiple indicators at a time (for example, RSI, STOCASTIC, MACD, ADX and some others), or in some cases even at different assets which an index is made of.
Graphics in DoEasy library (Part 96): Graphics in form objects and handling mouse events
Graphics in DoEasy library (Part 96): Graphics in form objects and handling mouse events

Graphics in DoEasy library (Part 96): Graphics in form objects and handling mouse events

In this article, I will start creating the functionality for handling mouse events in form objects, as well as add new properties and their tracking to a symbol object. Besides, I will improve the symbol object class since the chart symbols now have new properties to be considered and tracked.
Graphics in DoEasy library (Part 95): Composite graphical object controls
Graphics in DoEasy library (Part 95): Composite graphical object controls

Graphics in DoEasy library (Part 95): Composite graphical object controls

In this article, I will consider the toolkit for managing composite graphical objects - controls for managing an extended standard graphical object. Today, I will slightly digress from relocating a composite graphical object and implement the handler of change events on a chart featuring a composite graphical object. Besides, I will focus on the controls for managing a composite graphical object.
Graphics in DoEasy library (Part 94): Moving and deleting composite graphical objects
Graphics in DoEasy library (Part 94): Moving and deleting composite graphical objects

Graphics in DoEasy library (Part 94): Moving and deleting composite graphical objects

In this article, I will start the development of various composite graphical object events. We will also partially consider moving and deleting a composite graphical object. In fact, here I am going to fine-tune the things I implemented in the previous article.
Graphics in DoEasy library (Part 93): Preparing functionality for creating composite graphical objects
Graphics in DoEasy library (Part 93): Preparing functionality for creating composite graphical objects

Graphics in DoEasy library (Part 93): Preparing functionality for creating composite graphical objects

In this article, I will start developing the functionality for creating composite graphical objects. The library will support creating composite graphical objects allowing those objects have any hierarchy of connections. I will prepare all the necessary classes for subsequent implementation of such objects.
Graphics in DoEasy library (Part 92): Standard graphical object memory class. Object property change history
Graphics in DoEasy library (Part 92): Standard graphical object memory class. Object property change history

Graphics in DoEasy library (Part 92): Standard graphical object memory class. Object property change history

In the article, I will create the class of the standard graphical object memory allowing the object to save its states when its properties are modified. In turn, this allows retracting to the previous graphical object states.
Graphics in DoEasy library (Part 91): Standard graphical object events. Object name change history
Graphics in DoEasy library (Part 91): Standard graphical object events. Object name change history

Graphics in DoEasy library (Part 91): Standard graphical object events. Object name change history

In this article, I will refine the basic functionality for providing control over graphical object events from a library-based program. I will start from implementing the functionality for storing the graphical object change history using the "Object name" property as an example.
Graphics in DoEasy library (Part 90): Standard graphical object events. Basic functionality
Graphics in DoEasy library (Part 90): Standard graphical object events. Basic functionality

Graphics in DoEasy library (Part 90): Standard graphical object events. Basic functionality

In this article, I will implement the basic functionality for tracking standard graphical object events. I will start from a double click event on a graphical object.
Graphics in DoEasy library (Part 89): Programming standard graphical objects. Basic functionality
Graphics in DoEasy library (Part 89): Programming standard graphical objects. Basic functionality

Graphics in DoEasy library (Part 89): Programming standard graphical objects. Basic functionality

Currently, the library is able to track standard graphical objects on the client terminal chart, including their removal and modification of some of their parameters. At the moment, it lacks the ability to create standard graphical objects from custom programs.
preview
WebSockets for MetaTrader 5 — Using the Windows API

WebSockets for MetaTrader 5 — Using the Windows API

In this article, we will use the WinHttp.dll to create a WebSocket client for MetaTrader 5 programs. The client will ultimately be implemented as a class and also tested against the Deriv.com WebSocket API.
preview
Manual charting and trading toolkit (Part III). Optimization and new tools

Manual charting and trading toolkit (Part III). Optimization and new tools

In this article, we will further develop the idea of drawing graphical objects on charts using keyboard shortcuts. New tools have been added to the library, including a straight line plotted through arbitrary vertices, and a set of rectangles that enable the evaluation of the reversal time and level. Also, the article shows the possibility to optimize code for improved performance. The implementation example has been rewritten, allowing the use of Shortcuts alongside other trading programs. Required code knowledge level: slightly higher than a beginner.
preview
MQL5 Cookbook – Economic Calendar

MQL5 Cookbook – Economic Calendar

The article highlights the programming features of the Economic Calendar and considers creating a class for a simplified access to the calendar properties and receiving event values. Developing an indicator using CFTC non-commercial net positions serves as a practical example.
preview
An attempt at developing an EA constructor

An attempt at developing an EA constructor

In this article, I offer my set of trading functions in the form of a ready-made EA. This method allows getting multiple trading strategies by simply adding indicators and changing inputs.
Graphics in DoEasy library (Part 88): Graphical object collection — two-dimensional dynamic array for storing dynamically changing object properties
Graphics in DoEasy library (Part 88): Graphical object collection — two-dimensional dynamic array for storing dynamically changing object properties

Graphics in DoEasy library (Part 88): Graphical object collection — two-dimensional dynamic array for storing dynamically changing object properties

In this article, I will create a dynamic multidimensional array class with the ability to change the amount of data in any dimension. Based on the created class, I will create a two-dimensional dynamic array to store some dynamically changed properties of graphical objects.
preview
Using AutoIt With MQL5

Using AutoIt With MQL5

Short description. In this article we will explore scripting the MetraTrader 5 terminal by integrating MQL5 with AutoIt. In it we will cover how to automate various tasks by manipulating the terminals' user interface and also present a class that uses the AutoItX library.
preview
Fix PriceAction Stoploss or Fixed RSI (Smart StopLoss)

Fix PriceAction Stoploss or Fixed RSI (Smart StopLoss)

Stop-loss is a major tool when it comes to money management in trading. Effective use of stop-loss, take profit and lot size can make a trader more consistent in trading and overall more profitable. Although stop-loss is a great tool, there are challenges that are encountered when being used. The major one being stop-loss hunt. This article looks on how to reduce stop-loss hunt in trade and compare with the classical stop-loss usage to determine its profitability.
Graphics in DoEasy library (Part 87): Graphical object collection - managing object property modification on all open charts
Graphics in DoEasy library (Part 87): Graphical object collection - managing object property modification on all open charts

Graphics in DoEasy library (Part 87): Graphical object collection - managing object property modification on all open charts

In this article, I will continue my work on tracking standard graphical object events and create the functionality allowing users to control changes in the properties of graphical objects placed on any charts opened in the terminal.
Graphics in DoEasy library (Part 86): Graphical object collection - managing property modification
Graphics in DoEasy library (Part 86): Graphical object collection - managing property modification

Graphics in DoEasy library (Part 86): Graphical object collection - managing property modification

In this article, I will consider tracking property value modification, as well as removing and renaming graphical objects in the library.
preview
Multilayer perceptron and backpropagation algorithm (Part II): Implementation in Python and integration with MQL5

Multilayer perceptron and backpropagation algorithm (Part II): Implementation in Python and integration with MQL5

There is a Python package available for developing integrations with MQL, which enables a plethora of opportunities such as data exploration, creation and use of machine learning models. The built in Python integration in MQL5 enables the creation of various solutions, from simple linear regression to deep learning models. Let's take a look at how to set up and prepare a development environment and how to use use some of the machine learning libraries.
Better Programmer (Part 07): Notes on becoming a successful freelance developer
Better Programmer (Part 07): Notes on becoming a successful freelance developer

Better Programmer (Part 07): Notes on becoming a successful freelance developer

Do you wish to become a successful Freelance developer on MQL5? If the answer is yes, this article is right for you.
Graphics in DoEasy library (Part 85): Graphical object collection - adding newly created objects
Graphics in DoEasy library (Part 85): Graphical object collection - adding newly created objects

Graphics in DoEasy library (Part 85): Graphical object collection - adding newly created objects

In this article, I will complete the development of the descendant classes of the abstract graphical object class and start implementing the ability to store these objects in the collection class. In particular, I will create the functionality for adding newly created standard graphical objects to the collection class.
Graphics in DoEasy library (Part 84): Descendant classes of the abstract standard graphical object
Graphics in DoEasy library (Part 84): Descendant classes of the abstract standard graphical object

Graphics in DoEasy library (Part 84): Descendant classes of the abstract standard graphical object

In this article, I will consider creation of descendant objects for the terminal abstract standard graphical object. The class object describes the properties that are common for all graphical objects. So, it is simply some kind of a graphical object. To clarify its affiliation with a real graphical object, we need to set the properties inherent in this particular graphical object in the descendant object class.
preview
Programming a Deep Neural Network from Scratch using MQL Language

Programming a Deep Neural Network from Scratch using MQL Language

This article aims to teach the reader how to make a Deep Neural Network from scratch using the MQL4/5 language.
Better Programmer (Part 06): 9 habits that lead to effective coding
Better Programmer (Part 06): 9 habits that lead to effective coding

Better Programmer (Part 06): 9 habits that lead to effective coding

It's not always all about writing the code that leads to effective coding. There are certain habits that I have found in my experience that lead to effective coding. We are going to discuss some of them in detail in this article. This is a must-read article for every programmer who wants to improve their ability to write complex algorithms with less hassle.
Graphics in DoEasy library (Part 83): Class of the abstract standard graphical object
Graphics in DoEasy library (Part 83): Class of the abstract standard graphical object

Graphics in DoEasy library (Part 83): Class of the abstract standard graphical object

In this article, I will create the class of the abstract graphical object. This object is to serve as a basis for creating the class of standard graphical objects. Graphical objects feature multiple properties. Therefore, I will need to do a lot of preparatory work before actually creating the abstract graphical object class. This work includes setting the properties in the library enumerations.
preview
Dealing with Time (Part 2): The Functions

Dealing with Time (Part 2): The Functions

Determing the broker offset and GMT automatically. Instead of asking the support of your broker, from whom you will probably receive an insufficient answer (who would be willing to explain a missing hour), we simply look ourselves how they time their prices in the weeks of the time changes — but not cumbersome by hand, we let a program do it — why do we have a PC after all.
Graphics in DoEasy library (Part 82): Library objects refactoring and collection of graphical objects
Graphics in DoEasy library (Part 82): Library objects refactoring and collection of graphical objects

Graphics in DoEasy library (Part 82): Library objects refactoring and collection of graphical objects

In this article, I will improve all library objects by assigning a unique type to each object and continue the development of the library graphical objects collection class.
Graphics in DoEasy library (Part 81): Integrating graphics into library objects
Graphics in DoEasy library (Part 81): Integrating graphics into library objects

Graphics in DoEasy library (Part 81): Integrating graphics into library objects

It is time to start the integration of the already created objects into the previously created library objects. This will ultimately endow each library object with its own graphical object allowing users to interact with the program.
Better programmer (Part 05): How to become a faster developer
Better programmer (Part 05): How to become a faster developer

Better programmer (Part 05): How to become a faster developer

Every developer wants to be able to write code faster, and being able to code faster and effective is not some kind of special ability that only a few people are born with. It's a skill that can be learned, that is what I'm trying to teach in this article.
Graphics in DoEasy library (Part 80): "Geometric animation frame" object class
Graphics in DoEasy library (Part 80): "Geometric animation frame" object class

Graphics in DoEasy library (Part 80): "Geometric animation frame" object class

In this article, I will optimize the code of classes from the previous articles and create the geometric animation frame object class allowing us to draw regular polygons with a given number of vertices.
preview
Exploring options for creating multicolored candlesticks

Exploring options for creating multicolored candlesticks

In this article I will address the possibilities of creating customized indicators with candlesticks, pointing out their advantages and disadvantages.
Graphics in DoEasy library (Part 79): "Animation frame" object class and its descendant objects
Graphics in DoEasy library (Part 79): "Animation frame" object class and its descendant objects

Graphics in DoEasy library (Part 79): "Animation frame" object class and its descendant objects

In this article, I will develop the class of a single animation frame and its descendants. The class is to allow drawing shapes while maintaining and then restoring the background under them.
Better Programmer (Part 04): How to become a faster developer
Better Programmer (Part 04): How to become a faster developer

Better Programmer (Part 04): How to become a faster developer

Every developer wants to be able to write code faster, and being able to code faster and effective is not some kind of special ability that only a few people are born with. It's a skill that can be learned by every coder, regardless of years of experience on the keyboard.
Better Programmer (Part 03): Give Up doing these 5 things to become a successful MQL5 Programmer
Better Programmer (Part 03): Give Up doing these 5 things to become a successful MQL5 Programmer

Better Programmer (Part 03): Give Up doing these 5 things to become a successful MQL5 Programmer

This is the must-read article for anyone wanting to improve their programming career. This article series is aimed at making you the best programmer you can possibly be, no matter how experienced you are. The discussed ideas work for MQL5 programming newbies as well as professionals.
Graphics in DoEasy library (Part 78): Animation principles in the library. Image slicing
Graphics in DoEasy library (Part 78): Animation principles in the library. Image slicing

Graphics in DoEasy library (Part 78): Animation principles in the library. Image slicing

In this article, I will define the animation principles to be used in some parts of the library. I will also develop a class for copying a part of the image and pasting it to a specified form object location while preserving and restoring the part of the form background the image is to be superimposed on.
Better Programmer (Part 01): You must stop doing these 5 things to become a successful MQL5 programmer
Better Programmer (Part 01): You must stop doing these 5 things to become a successful MQL5 programmer

Better Programmer (Part 01): You must stop doing these 5 things to become a successful MQL5 programmer

There are a lot of bad habits that newbies and even advanced programmers are doing that are keeping them from becoming the best they can be to their coding career. We are going to discuss and address them in this article. This article is a must read for everyone who wants to become successful developer in MQL5.