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
Event handling in MQL5: Changing MA period on-the-fly
Event handling in MQL5: Changing MA period on-the-fly

Event handling in MQL5: Changing MA period on-the-fly

Suppose that simple MA (Moving Average) indicator with period 13 is applied to a chart. And we want to change the period to 20, but we do not want to go to indicator properties dialog box and edit the number 13 to 20: simply tired of these tedious actions with mouse and keyboard. And especially we don't want to open indicator code and modify it. We want to do all this with a single press of a button - "up arrows" next to the numeric keypad. In this article I'll describe how to do it.
How to call indicators in MQL5
How to call indicators in MQL5

How to call indicators in MQL5

With new version of MQL programming language available not only the approach of dealing with indicators have changed, but there are also new ways of how to create indicators. Furthermore, you have additional flexibility working with indicator's buffers - now you can specify the desired direction of indexing and get exactly as many indicator's values as you want. This article explains the basic methods of calling indicators and retrieving data from the indicator's buffers.
Custom Indicators in MQL5 for Newbies
Custom Indicators in MQL5 for Newbies

Custom Indicators in MQL5 for Newbies

Any new subject seems complicated and hard-to-learn for a newbie. Subjects that we know seem very simple and clear to us. But we simply do not remember, that everyone has to study something from scratch, and even our native language. The same is with the MQL5 programming language that offers wide possibilities of developing one's own trading strategies - you can start learning it from basic notions and simplest examples. Interaction of a technical indicator with the MetaTrader 5 client terminal is consider in this article on the example of the simple custom indicator SMA.
The Order of Object Creation and Destruction in MQL5
The Order of Object Creation and Destruction in MQL5

The Order of Object Creation and Destruction in MQL5

Every object, whether it is a custom object, a dynamic array or an array of objects, is created and deleted in MQL5-program in its particular way. Often, some objects are part of other objects, and the order of object deleting at deinitialization becomes especially important. This article provides some examples that cover the mechanisms of working with objects.
MQL5.community - User Memo
MQL5.community - User Memo

MQL5.community - User Memo

You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
How to Export Quotes from МetaTrader 5 to .NET Applications Using WCF Services
How to Export Quotes from МetaTrader 5 to .NET Applications Using WCF Services

How to Export Quotes from МetaTrader 5 to .NET Applications Using WCF Services

Want to organize export of quotes from MetaTrader 5 to your own application? The MQL5-DLL junction allows to create such solutions! This article will show you one of the ways to export quotes from MetaTrader 5 to applications written in .NET. For me it was more interesting, rational and easy to implement export of quotes using this very platform. Unfortunately, version 5 still does not support .NET, so like in old days we will use win32 dll with .NET support as an interlayer.
Easy Stock Market Trading with MetaTrader
Easy Stock Market Trading with MetaTrader

Easy Stock Market Trading with MetaTrader

This article raises the issues of automated trading on the stock market. Examples of MetaTrader 4 and QUIK integration are provided for your information. In addition to that, you can familiarize yourself with MetaTrader advantages aimed at solving this issue, and see how a trading robot can perform operations on MICEX.
Checking the Myth: The Whole Day Trading Depends on How the Asian Session Is Traded
Checking the Myth: The Whole Day Trading Depends on How the Asian Session Is Traded

Checking the Myth: The Whole Day Trading Depends on How the Asian Session Is Traded

In this article we will check the well-known statement that "The whole day trading depends on how the Asian session is traded".
Applying One Indicator to Another
Applying One Indicator to Another

Applying One Indicator to Another

When writing an indicator that uses the short form of the OnCalculate() function call, you might miss the fact that an indicator can be calculated not only by price data, but also by data of some other indicator (no matter whether it is a built-in or custom one). Do you want to improve an indicator for its correct application to the other indicator's data? In this article we'll review all the steps required for such modification.
The Price Histogram (Market Profile) and its implementation in MQL5
The Price Histogram (Market Profile) and its implementation in MQL5

The Price Histogram (Market Profile) and its implementation in MQL5

The Market Profile was developed by trully brilliant thinker Peter Steidlmayer. He suggested to use the alternative representation of information about "horizontal" and "vertical" market movements that leads to completely different set of models. He assumed that there is an underlying pulse of the market or a fundamental pattern called the cycle of equilibrium and disequilibrium. In this article I will consider Price Histogram — a simplified model of Market Profile, and will describe its implementation in MQL5.
How to Exchange Data: A DLL for MQL5 in 10 Minutes
How to Exchange Data: A DLL for MQL5 in 10 Minutes

How to Exchange Data: A DLL for MQL5 in 10 Minutes

Now not so many developers remember how to write a simple DLL, and what are special features of different system binding. Using several examples, I will try to show the entire process of the simple DLL's creation in 10 minutes, as well as to discuss some technical details of our binding implementation. I will show the step-by-step process of DLL creation in Visual Studio with examples of exchanging different types of variables (numbers, arrays, strings, etc.). Besides I will explain how to protect your client terminal from crashes in custom DLLs.
Data Exchange between Indicators: It's Easy
Data Exchange between Indicators: It's Easy

Data Exchange between Indicators: It's Easy

We want to create such an environment, which would provide access to data of indicators attached to a chart, and would have the following properties: absence of data copying; minimal modification of the code of available methods, if we need to use them; MQL code is preferable (of course, we have to use DLL, but we will use just a dozen of strings of C++ code). The article describes an easy method to develop a program environment for the MetaTrader terminal, that would provide means for accessing indicator buffers from other MQL programs.
MQL5: Create Your Own Indicator
MQL5: Create Your Own Indicator

MQL5: Create Your Own Indicator

What is an indicator? It is a set of calculated values that we want to be displayed on the screen in a convenient way. Sets of values are represented in programs as arrays. Thus, creation of an indicator means writing an algorithm that handles some arrays (price arrays) and records results of handling to other arrays (indicator values). By describing creation of True Strength Index, the author shows how to write indicators in MQL5.
Here Comes the New MetaTrader 5 and MQL5
Here Comes the New MetaTrader 5 and MQL5

Here Comes the New MetaTrader 5 and MQL5

This is just a brief review of MetaTrader 5. I can't describe all the system's new features for such a short time period - the testing started on 2009.09.09. This is a symbolical date, and I am sure it will be a lucky number. A few days have passed since I got the beta version of the MetaTrader 5 terminal and MQL5. I haven't managed to try all its features, but I am already impressed.
Meta COT Project - New Horizons for CFTC Report Analysis in MetaTrader 4
Meta COT Project - New Horizons for CFTC Report Analysis in MetaTrader 4

Meta COT Project - New Horizons for CFTC Report Analysis in MetaTrader 4

The article is about the use of CFTC report data (Open Interest) in MetaTrader. The article describes the proposed META COT project in details, shows how to load and process the necessary information. The Expert Advisor included into the project will help us analyze the effectiveness of the concept presented in the article. Finally, we'll draw some conclusions and offer useful suggestions.
FANN2MQL Neural Network Tutorial
FANN2MQL Neural Network Tutorial

FANN2MQL Neural Network Tutorial

This article has been made to show you how to use neural networks, via FANN2MQL, using an easy example: teaching a simple pattern to the neuralnetwork, and testing it to see if it can recognize patterns it has never seen.
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5

Step on New Rails: Custom Indicators in MQL5

I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
Auto-Generated Documentation for MQL5 Code
Auto-Generated Documentation for MQL5 Code

Auto-Generated Documentation for MQL5 Code

Most Java coders will be familiar with the auto-generated documentation that can be created with JavaDocs. The idea is to add comments into the code in a semi-structured way that can then be extracted into an easy to navigate help file. The C++ world also has a number of documentation auto-generators, with Microsoft's SandCastle and Doxygen being two leaders. The article describes the use of Doxygen to create HTML help file from structured comments in MQL5 code. The experiment worked very well and I believe the help documentation that Doxygen produces from MQL5 code will add a great deal of value.
Trader's Kit: Decorating Indicators
Trader's Kit: Decorating Indicators

Trader's Kit: Decorating Indicators

In this article you will find main tasks when decorating indicators, their solution and automation.
Working with Doubles in MQL4
Working with Doubles in MQL4

Working with Doubles in MQL4

In this note we will consider a typical programming errors, that occurs while working with double numbers in MQL4 programs.
Interaction between MеtaTrader 4 and MATLAB Engine (Virtual MATLAB Machine)
Interaction between MеtaTrader 4 and MATLAB Engine (Virtual MATLAB Machine)

Interaction between MеtaTrader 4 and MATLAB Engine (Virtual MATLAB Machine)

The article contains considerations regarding creation of a DLL library - wrapper that will enable the interaction of MetaTrader 4 and the MATLAB mathematical desktop package. It describes "pitfalls" and ways to overcome them. The article is intended for prepared C/C++ programmers that use the Borland C++ Builder 6 compiler.
Superposition and Interference of Financial Securities
Superposition and Interference of Financial Securities

Superposition and Interference of Financial Securities

The more factors influence the behavior of a currency pair, the more difficult it is to evaluate its behavior and make up future forecasts. Therefore, if we managed to extract components of a currency pair, values of a national currency that change with the time, we could considerably delimit the freedom of national currency movement as compared to the currency pair with this currency, as well as the number of factors influencing its behavior. As a result we would increase the accuracy of its behavior estimation and future forecasting. How can we do that?
On the Long Way to Be a Successful Trader - The Two Very First Steps
On the Long Way to Be a Successful Trader - The Two Very First Steps

On the Long Way to Be a Successful Trader - The Two Very First Steps

The main point of this article is to show a practical way to implement an effective MM. This can be achieved only by using a certain kind of strategies that we need to identify and describe first. In the following we’ll cover the basic concepts of how to build such a strategy and we’ll point out the common mistakes which always end up in draining a trader’s account.
Using Neural Networks In MetaTrader
Using Neural Networks In MetaTrader

Using Neural Networks In MetaTrader

This article shows you how to easily use Neural Networks in your MQL4 code taking advantage of best freely available artificial neural network library (FANN) employing multiple neural networks in your code.
Alert and Comment for External Indicators
Alert and Comment for External Indicators

Alert and Comment for External Indicators

In practical work a trader can face the following situation: it is necessary to get "alert" or a text message on a display (in a chart window) indicating about an appeared signal of an indicator. The article contains an example of displaying information about graphical objects created by an external indicator.
Channels. Advanced Models. Wolfe Waves
Channels. Advanced Models. Wolfe Waves

Channels. Advanced Models. Wolfe Waves

The article describes rules of marking patterns of Wolfe Waves. You will find here details of constructing and rules of accurate marking, which help to find correct formations of waves quickly and correctly.
Effective Averaging Algorithms with Minimal Lag: Use in Indicators and Expert Advisors
Effective Averaging Algorithms with Minimal Lag: Use in Indicators and Expert Advisors

Effective Averaging Algorithms with Minimal Lag: Use in Indicators and Expert Advisors

The article describes custom averaging functions of higher quality developed by the author: JJMASeries(), JurXSeries(), JLiteSeries(), ParMASeries(), LRMASeries(), T3Series() and MASeries(). The author considers the hot substitution of these functions in indicators using the call of the SmoothXSeries() function.
Recipes for Neuronets
Recipes for Neuronets

Recipes for Neuronets

The article is intended for beginners in baking "multi-layered" cakes.
Fallacies, Part 2. Statistics Is a Pseudo-Science, or a Chronicle of Nosediving Bread And Butter
Fallacies, Part 2. Statistics Is a Pseudo-Science, or a Chronicle of Nosediving Bread And Butter

Fallacies, Part 2. Statistics Is a Pseudo-Science, or a Chronicle of Nosediving Bread And Butter

Numerous attempts to apply statistical methods to the objective reality, i.e. to financial series, crash when met with the nonstationarity of processes, "fat tails" of accompanying probability distributions, and insufficient volume of financial data.In this publication I will try to refer not to the financial series as such, but to their subjective presentation - in this case, to the way a trader tries to halter the series, i.e. to the trading system. The eduction of statistical regularities of the trading results process is a rather enthralling task. In some cases quite true conclusions about the model of this process can be made, and these can be applied to the trading system.
Program Folder of MetaTrader 4 Client Terminal
Program Folder of MetaTrader 4 Client Terminal

Program Folder of MetaTrader 4 Client Terminal

The article describes the contents of the program folder of MetaTrader 4 Client Terminal. The article will be useful for those who have already started to grasp into the details of the client terminal operation.
Visual Testing of the Profitability of Indicators and Alerts
Visual Testing of the Profitability of Indicators and Alerts

Visual Testing of the Profitability of Indicators and Alerts

What indicator of trading alerts or just the methods of their calculating to use is usually decided when testing EAs using these alerts. However, it is not always possible/necessary/reasonable to write an EA for each indicator. You can promptly calculate the profitability of trading on the alerts from other indicators, using a special indicator that collects their alerts itself and draws a picture of ideal trading with them. It can help you both make a visual estimate of the results obtained and quickly choose most optimal parameters.
To Sleep, or Not to Sleep?
To Sleep, or Not to Sleep?

To Sleep, or Not to Sleep?

An alternative use of the Sleep() function in the realization of pauses between EA's actions is proposed. The approach under consideration allows a smart use of machine time.
View of Technical Analysis in the Context of Automatic Control Systems (ACS), or "Reverse View"
View of Technical Analysis in the Context of Automatic Control Systems (ACS), or "Reverse View"

View of Technical Analysis in the Context of Automatic Control Systems (ACS), or "Reverse View"

The article demonstrates an alternative view of technical analysis, which is based on the principles of both the modern automatic control theory and technical analysis itself. It is an introductory article representing the theory with some practical applications of it.
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.
HTML Walkthrough Using MQL4
HTML Walkthrough Using MQL4

HTML Walkthrough Using MQL4

HTML is nowadays one of the wide-spread types of documents. MetaTrader 4 Client Terminal allows you to save statements, test and optimization reports as .htm files. It is sometimes necessary to get information from such files in an MQL4 program. The article describes one of variations of how to get the tag structure and contents from HTML.
Expert Advisors Based on Popular Trading Strategies and Alchemy of Trading Robot Optimization (Part VI)
Expert Advisors Based on Popular Trading Strategies and Alchemy of Trading Robot Optimization (Part VI)

Expert Advisors Based on Popular Trading Strategies and Alchemy of Trading Robot Optimization (Part VI)

In this article, the author proposes the way of improving trading systems presented in his previous articles. The article is of interest for traders already having experiences in writing Expert Advisors.
How to Write Fast Non-Redrawing ZigZags
How to Write Fast Non-Redrawing ZigZags

How to Write Fast Non-Redrawing ZigZags

A rather universal approach to writing indicators of the ZigZag type is proposed. The method includes a significant part of ZigZags already described and allows you to create new ones relatively easily.
Idleness is the Stimulus to Progress, or How to Work with Graphics Interacively
Idleness is the Stimulus to Progress, or How to Work with Graphics Interacively

Idleness is the Stimulus to Progress, or How to Work with Graphics Interacively

An indicator for interactive working with trend lines, Fibo levels, icons manually imposed on a chart. It allows you to draw the colored zones of Fibo levels, shows the moments of the price crossing the trend line, manages the "Price label" object.
Changing the External Parameters of MQL4 Programs without Restarting
Changing the External Parameters of MQL4 Programs without Restarting

Changing the External Parameters of MQL4 Programs without Restarting

The article describes a method of changing the external parameters of MQL4 programs on-the-fly, without restarting.
Drawing Horizontal Break-Through Levels Using Fractals
Drawing Horizontal Break-Through Levels Using Fractals

Drawing Horizontal Break-Through Levels Using Fractals

The article describes creation of an indicator that would display the support/resistance levels using up/down fractals.