Articles with MQL4 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
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?
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.
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.
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.
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.
A Trader's Assistant Based on Extended MACD Analysis
A Trader's Assistant Based on Extended MACD Analysis

A Trader's Assistant Based on Extended MACD Analysis

Script 'Trader's Assistant' helps you to make a decision on opening positions, based on the extended analysis of the MACD status for the last three bars in the real-time trading on any timeframe. It can also be used for back testing.
Grouped File Operations
Grouped File Operations

Grouped File Operations

It is sometimes necessary to perform identical operations with a group of files. If you have a list of files included into a group, then it is no problem. However, if you need to make this list yourself, then a question arises: "How can I do this?" The article proposes doing this using functions FindFirstFile() and FindNextFile() included in kernel32.dll.
Method of Determining Errors in Code by Commenting
Method of Determining Errors in Code by Commenting

Method of Determining Errors in Code by Commenting

The article describes a method of searching the errors in the MQL4 code that is based on commenting. This method is found to be a useful one in case of problems occuring during the compilation caused by the errors in a reasonably large code.
All about Automated Trading Championship: Additional Materials of Championships 2006-2007
All about Automated Trading Championship: Additional Materials of Championships 2006-2007

All about Automated Trading Championship: Additional Materials of Championships 2006-2007

We present to you a selection of these materials that are divided into several parts. The present one contains additional materials about automated trading, Expert Advisors development, etc.
File Operations via WinAPI
File Operations via WinAPI

File Operations via WinAPI

Environment MQL4 is based on the conception of safe "sandbox": reading and saving files using the language are allowed in some predefined folders only. This protects the user of MetaTrader 4 from the potential danger of damaging important data on the HDD. However, it is sometimes necessary to leave that safe area. This article is devoted to the problem of how to do it easily and correctly.
All about Automated Trading Championship: Reporting the Championship 2007
All about Automated Trading Championship: Reporting the Championship 2007

All about Automated Trading Championship: Reporting the Championship 2007

The present article contains Weekly Reports of the ATC 2007. These materials are like snapshots, they are interesting-to-read not only during the Championship, but years later as well.
All about Automated Trading Championship: Interviews with the Participants'07
All about Automated Trading Championship: Interviews with the Participants'07

All about Automated Trading Championship: Interviews with the Participants'07

The published interviews of Championship 2007 bear the stamp of the results obtained during the preceding contest. The first Championship evoked a wide response on the internet and in printings. The leading developer of the MetaQuotes Software Corp. tells about changes made to the forthcoming Automated Trading Championship 2007. We put our questions to the developer of a well-known indicating complex ZUP, Eugeni Neumoin (nen) and spoke to an equity trader, Alexander Pozdnishev (AlexSilver).
All about Automated Trading Championship: Reporting the Championship 2006
All about Automated Trading Championship: Reporting the Championship 2006

All about Automated Trading Championship: Reporting the Championship 2006

This article contains Weekly Reports of the ATC 2006. These materials are like snapshots, they are interesting-to-read not only during the Championship, but years later as well.
Trend Lines Indicator Considering T. Demark's Approach
Trend Lines Indicator Considering T. Demark's Approach

Trend Lines Indicator Considering T. Demark's Approach

The indicator shows trend lines displaying the recent events on the market. The indicator is developed considering the recommendations and the approach of Thomas Demark concerning technical analysis. The indicator displays both the last direction of the trend and the next-to-last opposite direction of the trend.
All about Automated Trading Championship: Interviews with the Participants'06
All about Automated Trading Championship: Interviews with the Participants'06

All about Automated Trading Championship: Interviews with the Participants'06

Interviews with the Participants of Automated Trading Championship 2006 demonstrated a great variety of views of automated trading and trading as a whole. You can see yourselves which ideas turned out to work better during the Championship and which of them could not pass the critical verification through a three-month long "test-drive" on a contest account.
Interaction between MetaTrader 4 and Matlab via DDE
Interaction between MetaTrader 4 and Matlab via DDE

Interaction between MetaTrader 4 and Matlab via DDE

Step-by-step instructions of how to organize data transfer from Matlab to MetaTrader 4 using DDE.
All about Automated Trading Championship: Statistical Reports
All about Automated Trading Championship: Statistical Reports

All about Automated Trading Championship: Statistical Reports

Creating a profitable and stable trading system is always related to statistical data processing. In this article, we pout together statistical reports of the Automated Trading Championships 2006-2007. It may well be that the information they provide will help you find new trading ideas or correct the existing ones. Analyze the data and save your time.
All about Automated Trading Championship: Registration
All about Automated Trading Championship: Registration

All about Automated Trading Championship: Registration

This article comprises useful materials that will help you learn more about the procedure of registration for participation in the Automated Trading Championship.
The Statistic Analysis of Market Movements and Their Prognoses
The Statistic Analysis of Market Movements and Their Prognoses

The Statistic Analysis of Market Movements and Their Prognoses

The present article contemplates the wide opportunities of the statistic approach to marketing. Unfortunately, beginner traders deliberately fail to apply the really mighty science of statistics. Meanwhile, it is the only thing they use subconsciously while analyzing the market. Besides, statistics can give answers to many questions.
Two-Stage Modification of Opened Positions
Two-Stage Modification of Opened Positions

Two-Stage Modification of Opened Positions

The two-stage approach allows you to avoid the unnecessary closing and re-opening of positions in situations close to the trend and in cases of possible occurrence of divirgence.
Integrating MetaTrader 4  Client Terminal with MS SQL Server
Integrating MetaTrader 4  Client Terminal with MS SQL Server

Integrating MetaTrader 4 Client Terminal with MS SQL Server

The article gives an example of integrating MetaTrader 4 Client Terminal with MS SQL Server using a dll. Attached are both source codes in С++ and in MQL4, and a ready-made and compiled Visual C++ 6.0 SP5 project.
A Non-Trading EA Testing Indicators
A Non-Trading EA Testing Indicators

A Non-Trading EA Testing Indicators

All indicators can be divided into two groups: static indicators, the displaying of which, once shown, always remains the same in history and does not change with new incoming quotes, and dynamic indicators that display their status for the current moment only and are fully redrawn when a new price comes. The efficiency of a static indicator is directly visible on the chart. But how can we check whether a dynamic indicator works ok? This is the question the article is devoted to.
MetaEditor:Templates as a Spot to Stand On
MetaEditor:Templates as a Spot to Stand On

MetaEditor:Templates as a Spot to Stand On

It may be news to many our readers that all preparations for writing an EA can be performed once and then used continuously.
Fallacies, Part 1: Money Management is Secondary and Not Very Important
Fallacies, Part 1: Money Management is Secondary and Not Very Important

Fallacies, Part 1: Money Management is Secondary and Not Very Important

The first demonstration of testing results of a strategy based on 0.1 lot is becoming a standard de facto in the Forum. Having received "not so bad" from professionals, a beginner sees that "0.1" testing brings rather modest results and decides to introduce an aggressive money management thinking that positive mathematic expectation automatically provides positive results. Let's see what results can be achieved. Together with that we will try to construct several artificial balance graphs that are very instructive.
Easy Way to Publish a Video at MQL4.Community
Easy Way to Publish a Video at MQL4.Community

Easy Way to Publish a Video at MQL4.Community

It is usually easier to show, than to explain. We offer a simple and free way to create a video clip using CamStudio for publishing it in MQL.community forums.
An Expert Advisor Made to Order. Manual for a Trader
An Expert Advisor Made to Order. Manual for a Trader

An Expert Advisor Made to Order. Manual for a Trader

Not all traders are programmers. And not all of the programmers are really good ones. So, what should be done, if you need to automate your system by do not have time and desire to study MQL4?
Equivolume Charting Revisited
Equivolume Charting Revisited

Equivolume Charting Revisited

The article dwells on the method of constructing charts, at which each bar consists of the equal number of ticks.
MQL4 Language for Newbies. Custom Indicators (Part 2)
MQL4 Language for Newbies. Custom Indicators (Part 2)

MQL4 Language for Newbies. Custom Indicators (Part 2)

This is the fifth article from the series "MQL4 Languages for Newbies". Today we will learn to use graphical objects - a very powerful development tool that allows to widen substantially possibilities of using indicators. Besides, they can be used in scripts and Expert Advisors. We will learn to create objects, change their parameters, check errors. Of course, I cannot describe in details all objects - there are a lot of them. But you will get all necessary knowledge to be able to study them yourself. This article also contains a step-by-step guide-example of creating a complex signal indicator. At that, many parameters will be adjustable which will make it possible to change easily the appearance of the indicator.