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
Graphical Interfaces XI: Rendered controls (build 14.2)
Graphical Interfaces XI: Rendered controls (build 14.2)

Graphical Interfaces XI: Rendered controls (build 14.2)

In the new version of the library, all controls will be drawn on separate graphical objects of the OBJ_BITMAP_LABEL type. We will also continue to describe the optimization of code: changes in the core classes of the library will be discussed.
Angles in Trading. Further Study Required
Angles in Trading. Further Study Required

Angles in Trading. Further Study Required

In this article, we discuss the method of trading analysis by measuring angles in the MetaTrader 4 terminal. The article provides a general plan of using angles for trend movement analysis, as well as non-standard ways to the practical application of angle analysis in trading. The article also provides conclusions that can be useful for trading.
Graphical Interfaces XI: Refactoring the Library code (build 14.1)
Graphical Interfaces XI: Refactoring the Library code (build 14.1)

Graphical Interfaces XI: Refactoring the Library code (build 14.1)

As the library grows, its code must be optimized again in order to reduce its size. The version of the library described in this article has become even more object-oriented. This made the code easier to learn. A detailed description of the latest changes will allow the readers to develop the library independently based on their own needs.
Custom indicators and infographics in CCanvas
Custom indicators and infographics in CCanvas

Custom indicators and infographics in CCanvas

The article considers new types of indicators with more complex structural implementation. It also describes the development of pseudo-3D indicator types and dynamic infographics.
Cross-Platform Expert Advisor: Time Filters
Cross-Platform Expert Advisor: Time Filters

Cross-Platform Expert Advisor: Time Filters

This article discusses the implementation of various methods of time filtering a cross-platform expert advisor. The time filter classes are responsible for checking whether or not a given time falls under a certain time configuration setting.
Cross-Platform Expert Advisor: Money Management
Cross-Platform Expert Advisor: Money Management

Cross-Platform Expert Advisor: Money Management

This article discusses the implementation of money management method for a cross-platform expert advisor. The money management classes are responsible for the calculation of the lot size to be used for the next trade to be entered by the expert advisor.
An example of an indicator drawing Support and Resistance lines
An example of an indicator drawing Support and Resistance lines

An example of an indicator drawing Support and Resistance lines

The article provides an example of how to implement an indicator for drawing support and resistance lines based on formalized conditions. In addition to having a ready-to-use indicator, you will see how simple the indicator creation process is. You will also learn how to formulate conditions for drawing any desired line by changing the indicator code.
Graphical Interfaces X: Text selection in the Multiline Text box (build 13)
Graphical Interfaces X: Text selection in the Multiline Text box (build 13)

Graphical Interfaces X: Text selection in the Multiline Text box (build 13)

This article will implement the ability to select text using various key combinations and deletion of the selected text, similar to the way it is done in any other text editor. In addition, we will continue to optimize the code and prepare the classes to move on to the final process of the second stage of the library's evolution, where all controls will be rendered as separate images (canvases).
Wolfe Waves
Wolfe Waves

Wolfe Waves

The graphical method proposed by Bill Wolfe allows to detect a pattern, based on which a moment and direction for entry can be found, and also it helps forecast the target which the price should reach, as well as the time of target reaching. The article describes how to create an indicator based on a ZigZag, that would search for Wolfe Waves, and a simple Expert Advisor trading based on this indicator.
Thomas DeMark's Sequential (TD SEQUENTIAL) using artificial intelligence
Thomas DeMark's Sequential (TD SEQUENTIAL) using artificial intelligence

Thomas DeMark's Sequential (TD SEQUENTIAL) using artificial intelligence

In this article, I will tell you how to successfully trade by merging a very well-known strategy and a neural network. It will be about the Thomas DeMark's Sequential strategy with the use of an artificial intelligence system. Only the first part of the strategy will be applied, using the Setup and Intersection signals.
Cross-Platform Expert Advisor: Signals
Cross-Platform Expert Advisor: Signals

Cross-Platform Expert Advisor: Signals

This article discusses the CSignal and CSignals classes which will be used in cross-platform expert advisors. It examines the differences between MQL4 and MQL5 on how particular data needed for evaluation of trade signals are accessed to ensure that the code written will be compatible with both compilers.
MQL5 Cookbook - Creating a ring buffer for fast calculation of indicators in a sliding window
MQL5 Cookbook - Creating a ring buffer for fast calculation of indicators in a sliding window

MQL5 Cookbook - Creating a ring buffer for fast calculation of indicators in a sliding window

The ring buffer is the simplest and the most efficient way to arrange data when performing calculations in a sliding window. The article describes the algorithm and shows how it simplifies calculations in a sliding window and makes them more efficient.
MQL5 Cookbook - Pivot trading signals
MQL5 Cookbook - Pivot trading signals

MQL5 Cookbook - Pivot trading signals

The article describes the development and implementation of a class for sending signals based on pivots — reversal levels. This class is used to form a strategy applying the Standard Library. Improving the pivot strategy by adding filters is considered.
Graphical Interfaces X: Word wrapping algorithm in the Multiline Text box (build 12)
Graphical Interfaces X: Word wrapping algorithm in the Multiline Text box (build 12)

Graphical Interfaces X: Word wrapping algorithm in the Multiline Text box (build 12)

We continue to develop the Multiline Text box control. This time our task is to implement an automatic word wrapping in case a text box width overflow occurs, or a reverse word wrapping of the text to the previous line if the opportunity arises.
Universal Trend with the Graphical Interface
Universal Trend with the Graphical Interface

Universal Trend with the Graphical Interface

In this article a universal trend indicator is created based on a number of standard indicators. An additionally created graphical interface allows selecting the type of indicator and adjusting its parameter. The indicator is displayed in a separate window with rows of colored icons.
Graphical Interfaces X: Sorting, rebuilding the table and controls in the cells (build 11)
Graphical Interfaces X: Sorting, rebuilding the table and controls in the cells (build 11)

Graphical Interfaces X: Sorting, rebuilding the table and controls in the cells (build 11)

We continue to add new features to the rendered table: data sorting, managing the number of columns and rows, setting the table cell types to place controls into them.
A Universal Channel with the Graphical Interface
A Universal Channel with the Graphical Interface

A Universal Channel with the Graphical Interface

All channel indicators are displayed as three lines, including central, top and bottom lines. The drawing principle of the central line is similar to a moving average, while the moving average indicator is mostly used for drawing channels. The top and bottom lines are located at equal distances from the central line. This distance can be determined in points, as percent of price (the Envelopes indicator), using a standard deviation value (Bollinger Bands), or an ATR value (Keltner channel).
Graphical Interfaces X: Updates for the Rendered table and code optimization (build 10)
Graphical Interfaces X: Updates for the Rendered table and code optimization (build 10)

Graphical Interfaces X: Updates for the Rendered table and code optimization (build 10)

We continue to complement the Rendered table (CCanvasTable) with new features. The table will now have: highlighting of the rows when hovered; ability to add an array of icons for each cell and a method for switching them; ability to set or modify the cell text during the runtime, and more.
preview
Visualize this! MQL5 graphics library similar to 'plot' of R language

Visualize this! MQL5 graphics library similar to 'plot' of R language

When studying trading logic, visual representation in the form of graphs is of great importance. A number of programming languages popular among the scientific community (such as R and Python) feature the special 'plot' function used for visualization. It allows drawing lines, point distributions and histograms to visualize patterns. In MQL5, you can do the same using the CGraphics class.
Graphical interfaces X: New features for the Rendered table (build 9)
Graphical interfaces X: New features for the Rendered table (build 9)

Graphical interfaces X: New features for the Rendered table (build 9)

Until today, the CTable was the most advanced type of tables among all presented in the library. This table is assembled from edit boxes of the OBJ_EDIT type, and its further development becomes problematic. Therefore, in terms of maximum capabilities, it is better to develop rendered tables of the CCanvasTable type even at the current development stage of the library. Its current version is completely lifeless, but starting from this article, we will try to fix the situation.
Graphical Interfaces X: The Multiline Text box control (build 8)
Graphical Interfaces X: The Multiline Text box control (build 8)

Graphical Interfaces X: The Multiline Text box control (build 8)

The Multiline Text box control is discussed. Unlike the graphical objects of the OBJ_EDIT type, the presented version will not have restrictions on the number of input characters. It also adds the mode for turning the text box into a simple text editor, where the cursor can be moved using the mouse or keys.
3D Modeling in MQL5
3D Modeling in MQL5

3D Modeling in MQL5

A time series is a dynamic system, in which values of a random variable are received continuously or at successive equally spaced points in time. Transition from 2D to 3D market analysis provides a new look at complex processes and research objects. The article describes visualization methods providing 3D representation of two-dimensional data.
Graphical interfaces X: Advanced management of lists and tables. Code optimization (build 7)
Graphical interfaces X: Advanced management of lists and tables. Code optimization (build 7)

Graphical interfaces X: Advanced management of lists and tables. Code optimization (build 7)

The library code needs to be optimized: it should be more regularized, which is — more readable and comprehensible for studying. In addition, we will continue to develop the controls created previously: lists, tables and scrollbars.
An Example of Developing a Spread Strategy for Moscow Exchange Futures
An Example of Developing a Spread Strategy for Moscow Exchange Futures

An Example of Developing a Spread Strategy for Moscow Exchange Futures

The MetaTrader 5 platform allows developing and testing trading robots that simultaneously trade multiple financial instruments. The built-in Strategy Tester automatically downloads required tick history from the broker's server taking into account contract specifications, so the developer does not need to do anything manually. This makes it possible to easily and reliably reproduce trading environment conditions, including even millisecond intervals between the arrival of ticks on different symbols. In this article we will demonstrate the development and testing of a spread strategy on two Moscow Exchange futures.
Graphical Interfaces X: Time control, List of checkboxes control and table sorting (build 6)
Graphical Interfaces X: Time control, List of checkboxes control and table sorting (build 6)

Graphical Interfaces X: Time control, List of checkboxes control and table sorting (build 6)

Development of the library for creating graphical interfaces continues. The Time and List of checkboxes controls will be covered this time. In addition, the CTable class now provides the ability to sort data in ascending or descending order.
Statistical distributions in the form of histograms without indicator buffers and arrays
Statistical distributions in the form of histograms without indicator buffers and arrays

Statistical distributions in the form of histograms without indicator buffers and arrays

The article discusses the possibility of plotting statistical distribution histograms of market conditions with the help of the graphical memory meaning no indicator buffers and arrays are applied. Sample histograms are described in details and the "hidden" functionality of MQL5 graphical objects is shown.
Graphical Interfaces X: Text Edit box, Picture Slider and simple controls (build 5)
Graphical Interfaces X: Text Edit box, Picture Slider and simple controls (build 5)

Graphical Interfaces X: Text Edit box, Picture Slider and simple controls (build 5)

This article will consider new controls: Text Edit box, Picture Slider, as well as additional simple controls: Text label and Picture. The library continues to grow, and in addition to introduction of new controls, the previously created ones are also being improved.
Universal Oscillator with a GUI
Universal Oscillator with a GUI

Universal Oscillator with a GUI

The article describes the process of creation of a universal indicator based on all oscillators available in the terminal, with its own graphical interface. The GUI allows users to quickly and easily change settings of each oscillator straight from the chart window (without having to open its properties), as well as to compare their values and to select an optimal option for a specific task.
Universal ZigZag
Universal ZigZag

Universal ZigZag

ZigZag is one of the most popular indicators among the MetaTrader 5 users. The article analyzes the possibilities for creating various versions of the ZigZag. The result is a universal indicator with ample opportunities to extend its functionality, which is useful in the development of trading experts and other indicators.
How to build and test a Binary Options strategy with the MetaTrader 4 Strategy Tester
How to build and test a Binary Options strategy with the MetaTrader 4 Strategy Tester

How to build and test a Binary Options strategy with the MetaTrader 4 Strategy Tester

Tutorial to build a Binary Options strategy an test it in Strategy-Tester of MetaTrader 4 with Binary-Options-Strategy-Tester utility from marketplace.
LifeHack for Trader: A comparative report of several tests
LifeHack for Trader: A comparative report of several tests

LifeHack for Trader: A comparative report of several tests

The article deals with the simultaneous launch of Expert Advisor testing on four different trading instruments. The final comparison of four testing reports is provided in a table similar to how goods are represented in online stores. An additional bonus is that distribution charts will be automatically created for each symbol.
The 'Turtle Soup' trading system and its 'Turtle Soup Plus One' modification
The 'Turtle Soup' trading system and its 'Turtle Soup Plus One' modification

The 'Turtle Soup' trading system and its 'Turtle Soup Plus One' modification

The article features formalized rules of two trading strategies 'Turtle Soup' and 'Turtle Soup Plus One' from Street Smarts: High Probability Short-Term Trading Strategies by Linda Bradford Raschke and Laurence A. Connors. The strategies described in the book are quite popular. But it is important to understand that the authors have developed them based on the 15...20 year old market behavior.
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal

MQL5 Programming Basics: Global Variables of the MetaTrader 5 Terminal

Global variables of the terminal provide an indispensable tool for developing sophisticated and reliable Expert Advisors. If you master the global variables, you will no more be able to imagine developing EAs on MQL5 without them.
Graphical Interfaces X: The Standard Chart Control (build 4)
Graphical Interfaces X: The Standard Chart Control (build 4)

Graphical Interfaces X: The Standard Chart Control (build 4)

This time we will consider the Standard chart control. It will allow to create arrays of subcharts with the ability to synchronize horizontal scrolling. In addition, we will continue to optimize the library code to reduce the CPU load.
MQL5 Programming Basics: Files
MQL5 Programming Basics: Files

MQL5 Programming Basics: Files

This practice-oriented article focuses on working with files in MQL5. It offers a number of simple tasks allowing you to grasp the basics and hone your skills.
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

The next version of the Easy And Fast library (version 3) is presented in this article. Fixed certain flaws and added new features. More details further in the article.
Portfolio trading in MetaTrader 4
Portfolio trading in MetaTrader 4

Portfolio trading in MetaTrader 4

The article reveals the portfolio trading principles and their application to Forex market. A few simple mathematical portfolio arrangement models are considered. The article contains examples of practical implementation of the portfolio trading in MetaTrader 4: portfolio indicator and Expert Advisor for semi-automated trading. The elements of trading strategies, as well as their advantages and pitfalls are described.
LifeHack for trader: "Quiet" optimization or Plotting trade distributions
LifeHack for trader: "Quiet" optimization or Plotting trade distributions

LifeHack for trader: "Quiet" optimization or Plotting trade distributions

Analysis of the trade history and plotting distribution charts of trading results in HTML depending on position entry time. The charts are displayed in three sections - by hours, by days of the week and by months.
MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?
MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?

MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?

Have you ever wondered how quickly your order is delivered to the exchange, how fast it is executed, and how much time your terminal needs in order to receive the operation result? We have prepared a comparison of trading operation execution speed, because no one has ever measured these values using applications in MQL5 and QLUA.
MQL5 Cookbook - Trading signals of moving channels
MQL5 Cookbook - Trading signals of moving channels

MQL5 Cookbook - Trading signals of moving channels

The article describes the process of developing and implementing a class for sending signals based on the moving channels. Each of the signal version is followed by a trading strategy with testing results. Classes of the Standard Library are used for creating derived classes.