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
Using WinInet in MQL5.  Part 2:  POST Requests and Files
Using WinInet in MQL5.  Part 2:  POST Requests and Files

Using WinInet in MQL5. Part 2: POST Requests and Files

In this article, we continue studying the principles of working with Internet using HTTP requests and exchange of information with server. It describes new functions of the CMqlNet class, methods of sending information from forms and sending of files using POST requests as well as authorization on websites under your login using Cookies.
Decreasing Memory Consumption by Auxiliary Indicators
Decreasing Memory Consumption by Auxiliary Indicators

Decreasing Memory Consumption by Auxiliary Indicators

If an indicator uses values of many other indicators for its calculations, it consumes a lot of memory. The article describes several methods of decreasing the memory consumption when using auxiliary indicators. Saved memory allows increasing the number of simultaneously used currency pairs, indicators and strategies in the client terminal. It increases the reliability of trade portfolio. Such a simple care about technical resources of your computer can turn into money resources at your deposit.
Advanced Adaptive Indicators Theory and Implementation in MQL5
Advanced Adaptive Indicators Theory and Implementation in MQL5

Advanced Adaptive Indicators Theory and Implementation in MQL5

This article will describe advanced adaptive indicators and their implementation in MQL5: Adaptive Cyber Cycle, Adaptive Center of Gravity and Adaptive RVI. All indicators were originally presented in "Cybernetic Analysis for Stocks and Futures" by John F. Ehlers.
preview
The Fundamentals of Testing in MetaTrader 5

The Fundamentals of Testing in MetaTrader 5

What are the differences between the three modes of testing in MetaTrader 5, and what should be particularly looked for? How does the testing of an EA, trading simultaneously on multiple instruments, take place? When and how are the indicator values calculated during testing, and how are the events handled? How to synchronize the bars from different instruments during testing in an "open prices only" mode? This article aims to provide answers to these and many other questions.
MQL5 Wizard for Dummies
MQL5 Wizard for Dummies

MQL5 Wizard for Dummies

In early 2011 we released the first version of the MQL5 Wizard. This new application provides a simple and convenient tool to automatically generate trading robots. Any MetaTrader 5 user can create a custom Expert Advisor without even knowing how to program in MQL5.
Statistical Estimations
Statistical Estimations

Statistical Estimations

Estimation of statistical parameters of a sequence is very important, since most of mathematical models and methods are based on different assumptions. For example, normality of distribution law or dispersion value, or other parameters. Thus, when analyzing and forecasting of time series we need a simple and convenient tool that allows quickly and clearly estimating the main statistical parameters. The article shortly describes the simplest statistical parameters of a random sequence and several methods of its visual analysis. It offers the implementation of these methods in MQL5 and the methods of visualization of the result of calculations using the Gnuplot application.
MQL5 Wizard: New Version
MQL5 Wizard: New Version

MQL5 Wizard: New Version

The article contains descriptions of the new features available in the updated MQL5 Wizard. The modified architecture of signals allow creating trading robots based on the combination of various market patterns. The example contained in the article explains the procedure of interactive creation of an Expert Advisor.
Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction
Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction

Using MetaTrader 5 Indicators with ENCOG Machine Learning Framework for Timeseries Prediction

This article presents connecting MetaTrader 5 to ENCOG - Advanced Neural Network and Machine Learning Framework. It contains description and implementation of a simple neural network indicator based on a standard technical indicators and an Expert Advisor based on a neural indicator. All source code, compiled binaries, DLLs and an exemplary trained network are attached to the article.
How to Order an Expert Advisor and Obtain the Desired Result
How to Order an Expert Advisor and Obtain the Desired Result

How to Order an Expert Advisor and Obtain the Desired Result

How to write correctly the Requirement Specifications? What should and should not be expected from a programmer when ordering an Expert Advisor or an indicator? How to keep a dialog, what moments to pay special attention to? This article gives the answers to these, as well as to many other questions, which often don't seem obvious to many people.
Tracing, Debugging and Structural Analysis of Source Code
Tracing, Debugging and Structural Analysis of Source Code

Tracing, Debugging and Structural Analysis of Source Code

The entire complex of problems of creating a structure of an executed code and its tracing can be solved without serious difficulties. This possibility has appeared in MetaTrader 5 due to the new feature of the MQL5 language - automatic creation of variables of complex type of data (structures and classes) and their elimination when going out of local scope. The article contains the description of the methodology and the ready-made tool.
The Indicators of the Micro, Middle and Main Trends
The Indicators of the Micro, Middle and Main Trends

The Indicators of the Micro, Middle and Main Trends

The aim of this article is to investigate the possibilities of trade automation and the analysis, on the basis of some ideas from a book by James Hyerczyk "Pattern, Price & Time: Using Gann Theory in Trading Systems" in the form of indicators and Expert Advisor. Without claiming to be exhaustive, here we investigate only the Model - the first part of the Gann theory.
The Implementation of Automatic Analysis of the Elliott Waves in MQL5
The Implementation of Automatic Analysis of the Elliott Waves in MQL5

The Implementation of Automatic Analysis of the Elliott Waves in MQL5

One of the most popular methods of market analysis is the Elliott Wave Principle. However, this process is quite complicated, which leads us to the use of additional tools. One of such instruments is the automatic marker. This article describes the creation of an automatic analyzer of Elliott Waves in MQL5 language.
Electronic Tables in MQL5
Electronic Tables in MQL5

Electronic Tables in MQL5

The article describes a class of dynamic two-dimensional array that contains data of different types in its first dimension. Storing data in the form of a table is convenient for solving a wide range of problems of arrangement, storing and operation with bound information of different types. The source code of the class that implements the functionality of working with tables is attached to the article.
Using Pseudo-Templates as Alternative to C++ Templates
Using Pseudo-Templates as Alternative to C++ Templates

Using Pseudo-Templates as Alternative to C++ Templates

The article describes a way of programming without using templates but keeping the style of programming iherenet to them. It tells about implementation of templates using custom methods and has a ready-made script attached for creating a code on the basis of specified templates.
Random Walk and the Trend Indicator
Random Walk and the Trend Indicator

Random Walk and the Trend Indicator

Random Walk looks very similar to the real market data, but it has some significant features. In this article we will consider the properties of Random Walk, simulated using the coin-tossing game. To study the properties of the data, the trendiness indicator is developed.
preview
Use of Resources in MQL5

Use of Resources in MQL5

MQL5 programs not only automate routine calculations, but also can create a full-featured graphical environment. The functions for creating truly interactive controls are now virtually the same rich, as those in classical programming languages. If you want to write a full-fledged stand-alone program in MQL5, use resources in them. Programs with resources are easier to maintain and distribute.
Econometric Approach to Analysis of Charts
Econometric Approach to Analysis of Charts

Econometric Approach to Analysis of Charts

This article describes the econometric methods of analysis, the autocorrelation analysis and the analysis of conditional variance in particular. What is the benefit of the approach described here? Use of the non-linear GARCH models allows representing the analyzed series formally from the mathematical point of view and creating a forecast for a specified number of steps.
Expert Advisor based on the "New Trading Dimensions" by Bill Williams
Expert Advisor based on the "New Trading Dimensions" by Bill Williams

Expert Advisor based on the "New Trading Dimensions" by Bill Williams

In this article I will discuss the development of Expert Advisor, based on the book "New Trading Dimensions: How to Profit from Chaos in Stocks, Bonds, and Commodities" by Bill Williams. The strategy itself is well known and its use is still controversial among traders. The article considers trading signals of the system, the specifics of its implementation, and the results of testing on historical data.
Filtering Signals Based on Statistical Data of Price Correlation
Filtering Signals Based on Statistical Data of Price Correlation

Filtering Signals Based on Statistical Data of Price Correlation

Is there any correlation between the past price behavior and its future trends? Why does the price repeat today the character of its previous day movement? Can the statistics be used to forecast the price dynamics? There is an answer, and it is positive. If you have any doubt, then this article is for you. I'll tell how to create a working filter for a trading system in MQL5, revealing an interesting pattern in price changes.
Implementation of Indicators as Classes by Examples of Zigzag and ATR
Implementation of Indicators as Classes by Examples of Zigzag and ATR

Implementation of Indicators as Classes by Examples of Zigzag and ATR

Debate about an optimal way of calculating indicators is endless. Where should we calculate the indicator values - in the indicator itself or embed the entire logic in a Expert Advisor that uses it? The article describes one of the variants of moving the source code of a custom indicator iCustom right in the code of an Expert Advisor or script with optimization of calculations and modeling the prev_calculated value.
Parallel Calculations in MetaTrader 5
Parallel Calculations in MetaTrader 5

Parallel Calculations in MetaTrader 5

Time has been a great value throughout the history of mankind, and we strive not to waste it unnecessarily. This article will tell you how to accelerate the work of your Expert Advisor if your computer has a multi-core processor. Moreover, the implementation of the proposed method does not require the knowledge of any other languages besides MQL5.
Building a Spectrum Analyzer
Building a Spectrum Analyzer

Building a Spectrum Analyzer

This article is intended to get its readers acquainted with a possible variant of using graphical objects of the MQL5 language. It analyses an indicator, which implements a panel of managing a simple spectrum analyzer using the graphical objects. The article is meant for readers acquianted with basics of MQL5.
Finding Errors and Logging
Finding Errors and Logging

Finding Errors and Logging

MetaEditor 5 has the debugging feature. But when you write your MQL5 programs, you often want to display not the individual values, but all messages that appear during testing and online work. When the log file contents have large size, it is obvious to automate quick and easy retrieval of required message. In this article we will consider ways of finding errors in MQL5 programs and methods of logging. Also we will simplify logging into files and will get to know a simple program LogMon for comfortable viewing of logs.
Averaging Price Series for Intermediate Calculations Without Using Additional Buffers
Averaging Price Series for Intermediate Calculations Without Using Additional Buffers

Averaging Price Series for Intermediate Calculations Without Using Additional Buffers

This article is about traditional and unusual algorithms of averaging packed in simplest and single-type classes. They are intended for universal usage in almost all developments of indicators. I hope that the suggested classes will be a good alternative to 'bulky' calls of custom and technical indicators.
The Implementation of a Multi-currency Mode in MetaTrader 5
The Implementation of a Multi-currency Mode in MetaTrader 5

The Implementation of a Multi-currency Mode in MetaTrader 5

For a long time multi-currency analysis and multi-currency trading has been of interest to people. The opportunity to implement a full fledged multi-currency regime became possible only with the public release of MetaTrader 5 and the MQL5 programming language. In this article we propose a way to analyze and process all incoming ticks for several symbols. As an illustration, let's consider a multi-currency RSI indicator of the USDx dollar index.
Drawing Channels - Inside and Outside View
Drawing Channels - Inside and Outside View

Drawing Channels - Inside and Outside View

I guess it won't be an exaggeration, if I say the channels are the most popular tool for the analysis of market and making trade decisions after the moving averages. Without diving deeply into the mass of trade strategies that use channels and their components, we are going to discuss the mathematical basis and the practical implementation of an indicator, which draws a channel determined by three extremums on the screen of the client terminal.
Charts and diagrams in HTML
Charts and diagrams in HTML

Charts and diagrams in HTML

Today it is difficult to find a computer that does not have an installed web-browser. For a long time browsers have been evolving and improving. This article discusses the simple and safe way to create of charts and diagrams, based on the the information, obtained from MetaTrader 5 client terminal for displaying them in the browser.
Connecting NeuroSolutions Neuronets
Connecting NeuroSolutions Neuronets

Connecting NeuroSolutions Neuronets

In addition to creation of neuronets, the NeuroSolutions software suite allows exporting them as DLLs. This article describes the process of creating a neuronet, generating a DLL and connecting it to an Expert Advisor for trading in MetaTrader 5.
preview
Trade Events in MetaTrader 5

Trade Events in MetaTrader 5

A monitoring of the current state of a trade account implies controlling open positions and orders. Before a trade signal becomes a deal, it should be sent from the client terminal as a request to the trade server, where it will be placed in the order queue awaiting to be processed. Accepting of a request by the trade server, deleting it as it expires or conducting a deal on its basis - all those actions are followed by trade events; and the trade server informs the terminal about them.
MQL5 Wizard: How to Create a Module of Trailing of Open Positions
MQL5 Wizard: How to Create a Module of Trailing of Open Positions

MQL5 Wizard: How to Create a Module of Trailing of Open Positions

The generator of trade strategies MQL5 Wizard greatly simplifies the testing of trading ideas. The article discusses how to write and connect to the generator of trade strategies MQL5 Wizard your own class of managing open positions by moving the Stop Loss level to a lossless zone when the price goes in the position direction, allowing to protect your profit decrease drawdowns when trading. It also tells about the structure and format of the description of the created class for the MQL5 Wizard.
MQL5 Wizard: How to Create a Risk and Money Management Module
MQL5 Wizard: How to Create a Risk and Money Management Module

MQL5 Wizard: How to Create a Risk and Money Management Module

The generator of trading strategies of the MQL5 Wizard greatly simplifies testing of trading ideas. The article describes how to develop a custom risk and money management module and enable it in the MQL5 Wizard. As an example we've considered a money management algorithm, in which the size of the trade volume is determined by the results of the previous deal. The structure and format of description of the created class for the MQL5 Wizard are also discussed in the article.
Exposing C# code to MQL5 using unmanaged exports
Exposing C# code to MQL5 using unmanaged exports

Exposing C# code to MQL5 using unmanaged exports

In this article I presented different methods of interaction between MQL5 code and managed C# code. I also provided several examples on how to marshal MQL5 structures against C# and how to invoke exported DLL functions in MQL5 scripts. I believe that the provided examples may serve as a basis for future research in writing DLLs in managed code. This article also open doors for MetaTrader to use many libraries that are already implemented in C#.
preview
Orders, Positions and Deals in MetaTrader 5

Orders, Positions and Deals in MetaTrader 5

Creating a robust trading robot cannot be done without an understanding of the mechanisms of the MetaTrader 5 trading system. The client terminal receives the information about the positions, orders, and deals from the trading server. To handle this data properly using the MQL5, it's necessary to have a good understanding of the interaction between the MQL5-program and the client terminal.
How to Copy Trading from MetaTrader 5 to MetaTrader 4
How to Copy Trading from MetaTrader 5 to MetaTrader 4

How to Copy Trading from MetaTrader 5 to MetaTrader 4

Is it possible to trade on a real MetaTrader 5 account today? How to organize such trading? The article contains the theory of these questions and the working codes used for copying trades from the MetaTrader 5 terminal to MetaTrader 4. The article will be useful both for the developers of Expert Advisors and for practicing traders.
Moving Mini-Max: a New Indicator for Technical Analysis and Its Implementation in MQL5
Moving Mini-Max: a New Indicator for Technical Analysis and Its Implementation in MQL5

Moving Mini-Max: a New Indicator for Technical Analysis and Its Implementation in MQL5

In the following article I am describing a process of implementing Moving Mini-Max indicator based on a paper by Z.G.Silagadze 'Moving Mini-max: a new indicator for technical analysis'. The idea of the indicator is based on simulation of quantum tunneling phenomena, proposed by G. Gamov in the theory of alpha decay.
Creating Multi-Expert Advisors on the basis of Trading Models
Creating Multi-Expert Advisors on the basis of Trading Models

Creating Multi-Expert Advisors on the basis of Trading Models

Using the object-oriented approach in MQL5 greatly simplifies the creation of multi-currency/multi-system /multi-time-frame Expert Advisors. Just imagine, your single EA trades on several dozens of trading strategies, on all of the available instruments, and on all of the possible time frames! In addition, the EA is easily tested in the tester, and for all of the strategies, included in its composition, it has one or several working systems of money management.
Create Your Own Expert Advisor in MQL5 Wizard
Create Your Own Expert Advisor in MQL5 Wizard

Create Your Own Expert Advisor in MQL5 Wizard

The knowledge of programming languages is no longer a prerequisite for creating trading robots. Earlier lack of programming skills was an impassable obstacle to the implementation of one's own trading strategies, but with the emergence of the MQL5 Wizard, the situation radically changed. Novice traders can stop worrying because of the lack of programming experience - with the new Wizard, which allows you to generate Expert Advisor code, it is not necessary.
MQL5 Wizard: How to Create a Module of Trading Signals
MQL5 Wizard: How to Create a Module of Trading Signals

MQL5 Wizard: How to Create a Module of Trading Signals

The article discusses how to write your own class of trading signals with the implementation of signals on the crossing of the price and the moving average, and how to include it to the generator of trading strategies of the MQL5 Wizard, as well as describes the structure and format of the description of the generated class for the MQL5 Wizard.
MQL5 Wizard: Creating Expert Advisors without Programming
MQL5 Wizard: Creating Expert Advisors without Programming

MQL5 Wizard: Creating Expert Advisors without Programming

Do you want to try out a trading strategy while wasting no time for programming? In MQL5 Wizard you can simply select the type of trading signals, add modules of trailing positions and money management - and your work is done! Create your own implementations of modules or order them via the Jobs service - and combine your new modules with existing ones.
Create your own Market Watch using the Standard Library Classes
Create your own Market Watch using the Standard Library Classes

Create your own Market Watch using the Standard Library Classes

The new MetaTrader 5 client terminal and the MQL5 Language provides new opportunities for presenting visual information to the trader. In this article, we propose a universal and extensible set of classes, which handles all the work of organizing displaying of the arbitrary text information on the chart. The example of Market Watch indicator is presented.