MQL4 Programming Articles

icon

Here you can find articles on MQL4 - programming language of trading strategies. Most of them are written by traders and active members of MQL5.community. For more convenience, all articles are grouped into several categories - Experts, Indicators, Trading Systems, etc.

Watch out for new articles and discuss them on the Forum!

Add a new article
latest | best
Error 146 ("Trade context busy") and How to Deal with It
Error 146 ("Trade context busy") and How to Deal with It

Error 146 ("Trade context busy") and How to Deal with It

The article deals with conflict-free trading of several experts on one МТ 4 Client Terminal. It will be useful for those who have basic command of working with the terminal and programming in MQL 4.
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.
Testing (Optimization) Technique and Some Criteria for Selection of the Expert Advisor Parameters
Testing (Optimization) Technique and Some Criteria for Selection of the Expert Advisor Parameters

Testing (Optimization) Technique and Some Criteria for Selection of the Expert Advisor Parameters

There is no trouble finding the Holy Grail of testing, it is however much more difficult to get rid of it. This article addresses the selection of the Expert Advisor operating parameters with automated group processing of optimisation and testing results upon maximum utilisation of the Terminal performance capabilities and minimum end user load.
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.
Secrets of the MetaTrader 4 Client Terminal: Indicators
Secrets of the MetaTrader 4 Client Terminal: Indicators

Secrets of the MetaTrader 4 Client Terminal: Indicators

Are you going to write your own indicator? Perhaps you will find that what you need among indicators already embedded in the client terminal. So why to reinvent the wheel? A summary table of integrated indicators' characteristics; special features and methods of attaching indicators to a chart; building of levels; displaying of indicators on different timeframes.
Comfortable Scalping
Comfortable Scalping

Comfortable Scalping

The article describes the method of creating a tool for comfortable scalping. However, such an approach to trade opening can be applied in any trading.
On Methods of Technical Analysis and Market Forecasting
On Methods of Technical Analysis and Market Forecasting

On Methods of Technical Analysis and Market Forecasting

The article demonstrates the capabilities and potential of a well-known mathematical method coupled with visual thinking and an "out of the box" market outlook. On the one hand, it serves to attract the attention of a wide audience as it can get the creative minds to reconsider the trading paradigm as such. And on the other, it can give rise to alternative developments and program code implementations regarding a wide range of tools for analysis and forecasting.
Evaluating the effectiveness of trading systems by analyzing their components
Evaluating the effectiveness of trading systems by analyzing their components

Evaluating the effectiveness of trading systems by analyzing their components

This article explores the effectiveness of complex trading systems by analyzing the efficiency of its individual components. Any analysis, whether it is graphic, based on indicators, or any other, is one of the key components of successful trading in financial markets. This article is to some extent a research of few simple and independent trading systems for analyzing their effectiveness and usefulness of the joint application.
Universal Expert Advisor Template
Universal Expert Advisor Template

Universal Expert Advisor Template

The article will help newbies in trading to create flexibly adjustable Expert Advisors.
What is Martingale and Is It Reasonable to Use It?
What is Martingale and Is It Reasonable to Use It?

What is Martingale and Is It Reasonable to Use It?

This article contains a detailed description of the Martingale system, as well as precise mathematical calculations, necessary for answering the question: "Is it reasonable to use Martingale?".
An Insight Into Accumulation/Distribution And Where It Can Get You
An Insight Into Accumulation/Distribution And Where It Can Get You

An Insight Into Accumulation/Distribution And Where It Can Get You

The Accumulation/Distribution (A/D) Indicator has one interesting feature - a breakout of the trend line plotted in this indicator chart suggests, with a certain degree of probability, a forthcoming breakout of the trend line in the price chart. This article will be useful and interesting for those who are new to programming in MQL4. Having this in view, I have tried to present the information in an easy to grasp manner and use the simplest code structures.
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.
A Method of Drawing the Support/Resistance Levels
A Method of Drawing the Support/Resistance Levels

A Method of Drawing the Support/Resistance Levels

This article describes the process of creating a simple script for detecting the support/resistance levels. It is written for beginners, so you can find the detailed explanation of every stage of the process. However, though the script is very simple, the article will be also useful for advanced traders and the users of the MetaTrader 4 platform. It contains the examples of the data export into the tabular format, the import of the table to Microsoft Excel and plotting the charts for the further detailed analysis.
Trading Strategy Based on Pivot Points Analysis
Trading Strategy Based on Pivot Points Analysis

Trading Strategy Based on Pivot Points Analysis

Pivot Points (PP) analysis is one of the simplest and most effective strategies for high intraday volatility markets. It was used as early as in the precomputer times, when traders working at stocks could not use any ADP equipment, except for counting frames and arithmometers.
Layman's Notes: ZigZag…
Layman's Notes: ZigZag…

Layman's Notes: ZigZag…

Surely, a fey thought to trade closely to extremums visited every apprentice trader when he/she saw "enigmatic" polyline for the first time. It's so simple, indeed. Here is the maximum. And there is the minimum. A beautiful picture on the history. And what is in practice? A ray is drawn. It should seem, that is it, the peak! It is time to sell. And now we go down. But hell no! The price is treacherously moving upwards. Haw! It's a trifle, not an indicator. And you throw it out!
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?
How Not to Fall into Optimization Traps?
How Not to Fall into Optimization Traps?

How Not to Fall into Optimization Traps?

The article describes the methods of how to understand the tester optimization results better. It also gives some tips that help to avoid "harmful optimization".
Transferring an Indicator Code into an Expert Advisor Code. General Structural Schemes of an Expert Advisor and Indicator Functions
Transferring an Indicator Code into an Expert Advisor Code. General Structural Schemes of an Expert Advisor and Indicator Functions

Transferring an Indicator Code into an Expert Advisor Code. General Structural Schemes of an Expert Advisor and Indicator Functions

This article dwells on the ways of transferring an indicator code into an Expert Advisor Code and on writing Expert Advisors with no calling to custom indicators, and with the whole program code for the calculation of necessary indicator values inside the Expert Advisor. This article gives a general scheme of Expert Advisor changing and the idea of building an indicator function based on a custom indicator. The article is intended for readers, already having experience of programming in MQL4 language.
Testing of Expert Advisors in the MetaTrader 4 Client Terminal: An Outward Glance
Testing of Expert Advisors in the MetaTrader 4 Client Terminal: An Outward Glance

Testing of Expert Advisors in the MetaTrader 4 Client Terminal: An Outward Glance

What happens after you have clicked on the "Start" button? The article answers this and many other questions.
Synchronization of Expert Advisors, Scripts and Indicators
Synchronization of Expert Advisors, Scripts and Indicators

Synchronization of Expert Advisors, Scripts and Indicators

The article considers the necessity and general principles of developing a bundled program that would contain both an Expert Advisor, a script and an indicator.
Alert and Comment for External Indicators. Multi-Currency Analysis Through External Scanning
Alert and Comment for External Indicators. Multi-Currency Analysis Through External Scanning

Alert and Comment for External Indicators. Multi-Currency Analysis Through External Scanning

Alert for multi-currency and multiple time frame analysis of external indicators. The article deals with a method of getting event information in respect of events in external indicators, without having to attach indicators to a chart or open charts themselves. We will call it external scanning.
Money Management Revisited
Money Management Revisited

Money Management Revisited

The article deals with some issues arising when traders apply various money management systems to Forex trading. Experimental data obtained from performing trading deals using different money management (MM) methods is also described.
Strings: Table of ASCII Symbols and Its Use
Strings: Table of ASCII Symbols and Its Use

Strings: Table of ASCII Symbols and Its Use

In this article we will analyze the table of ASCII symbols and the ways it can be used. We will also deal with some new functions, the principle of operation of which is based on the peculiarities of the ASCII table, and then we will create a new library, which will include these functions. They are quite popular in other programming languages, but they are not included into the list of built-in functions. Besides, we will examine in details the basics of working with strings. So, I think you will certainly learn something new about this useful type of data.
Testing Expert Advisors on Non-Standard Time Frames
Testing Expert Advisors on Non-Standard Time Frames

Testing Expert Advisors on Non-Standard Time Frames

It's not just simple; it's super simple. Testing Expert Advisors on non-standard time frames is possible! All we need to do is to replace standard time frame data with non-standard time frame data. Furthermore, we can even test Expert Advisors that use data from several non-standard time frames.
Forex Trading ABC
Forex Trading ABC

Forex Trading ABC

Working on financial markets represents, first of all, trade operations. We all, starting from the very childhood, have an intuitive idea of what is to buy and to sell. But Forex trading is still something special. This article deals with the ideas necessary to explain some terms. We will also consider the MQL 4 functions that correspond with those terms.
Synthetic Bars - A New Dimension to Displaying Graphical Information on Prices
Synthetic Bars - A New Dimension to Displaying Graphical Information on Prices

Synthetic Bars - A New Dimension to Displaying Graphical Information on Prices

The main drawback of traditional methods for displaying price information using bars and Japanese candlesticks is that they are bound to the time period. It was perhaps optimal at the time when these methods were created but today when the market movements are sometimes too rapid, prices displayed in a chart in this way do not contribute to a prompt response to the new movement. The proposed price chart display method does not have this drawback and provides a quite familiar layout.
Graphic Expert Advisor: AutoGraf
Graphic Expert Advisor: AutoGraf

Graphic Expert Advisor: AutoGraf

The article shows the workability of graphics in creation of a convenient interface to manage trading.
Price Forecasting Using Neural Networks
Price Forecasting Using Neural Networks

Price Forecasting Using Neural Networks

Many traders speak about neural networks, but what they are and what they really can is known to few people. This article sheds some light on the world of artificial intelligence. It describes, how to prepare correctly the data for the network. Here you will also find an example of forecasting using means of the program Matlab.
Indicator Alternative Ichimoku – Setup, Examples of Usage
Indicator Alternative Ichimoku – Setup, Examples of Usage

Indicator Alternative Ichimoku – Setup, Examples of Usage

How to set up Alternative Ichimoku correctly? Read the description of parameters setting up. The article will help you understand the methods of setting up parameters not only of the indicator Ichimoku. Certainly you will also better understand how to set up the standard Ichimoku Kinko Hyo.
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.
Interaction between MetaTrader 4 and Matlab via CSV Files
Interaction between MetaTrader 4 and Matlab via CSV Files

Interaction between MetaTrader 4 and Matlab via CSV Files

Step-by-step instructions of how to organize data arrays exchange between MetaTrader 4 and Matlab via CSV files.
The Magic of Filtration
The Magic of Filtration

The Magic of Filtration

Most of the automated trading systems developers use some form of trading signals filtration. In this article, we explore the creation and implementation of bandpass and discrete filters for Expert Advisors, to improve the characteristics of the automated trading system.
A Pause between Trades
A Pause between Trades

A Pause between Trades

The article deals with the problem of how to arrange pauses between trade operations when a number of experts work on one МТ 4 Client Terminal. It is intended for users who have basic skills in both working with the terminal and programming in MQL 4.
Information Storage and View
Information Storage and View

Information Storage and View

The article deals with convenient and efficient methods of information storage and viewing. Alternatives to the terminal standard log file and the Comment() function are considered here.
Tester in the Terminal MetaTrader 4: It Should Be Known
Tester in the Terminal MetaTrader 4: It Should Be Known

Tester in the Terminal MetaTrader 4: It Should Be Known

The elaborate interface of the terminal MetaTrader 4 is a forefront, but beside this the terminal includes a deep-laid tester of strategies. And while the worth of MetaTrader 4 as a trading terminal is obvious, the quality of the tester's strategy testing can be assessed only in practice. This article shows the advantages and conveniences of testing in MetaTrader 4.
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.
Three Aspects of Manual Trading Automation. Part 1: Trading
Three Aspects of Manual Trading Automation. Part 1: Trading

Three Aspects of Manual Trading Automation. Part 1: Trading

This article is the first in a series of articles on manual trading automation in the МetaТrader 4 trading platform. Each of the articles will be devoted to one of the following aspects: automation of manual trading, current state of trade display automation and automation of reports on trade results. In this article, I will present an interesting approach to creating EA's controlled manually by a trader.
Can the Forex Market Be Forecasted? How to Create One's Own Trading Strategy?
Can the Forex Market Be Forecasted? How to Create One's Own Trading Strategy?

Can the Forex Market Be Forecasted? How to Create One's Own Trading Strategy?

Everyone starting to work in Forex tries to answer these questions. But not everyone finds the answer, even after many years of hard work and search. I personally have answered this question, as well as many other questions of this article. As a result of these answers a way of creating an efficient trading strategy was determined.
Indicator Taichi - a Simple Idea of Formalizing the Values of Ichimoku Kinko Hyo
Indicator Taichi - a Simple Idea of Formalizing the Values of Ichimoku Kinko Hyo

Indicator Taichi - a Simple Idea of Formalizing the Values of Ichimoku Kinko Hyo

Hard to interpret Ichimoku signals? This article introduces some principles of formalizing values and signals of Ichimoku Kinko Hyo. For visualization of its usage the author chose the currency pair EURUSD based on his own preferences. However, the indicator can be used on any currency pair.
Breakpoints in Tester: It's Possible!
Breakpoints in Tester: It's Possible!

Breakpoints in Tester: It's Possible!

The article deals with breakpoint emulation when passed through Tester, debug information being displayed.