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
How to conduct a qualitative analysis of trading signals and select the best of them
How to conduct a qualitative analysis of trading signals and select the best of them

How to conduct a qualitative analysis of trading signals and select the best of them

The article deals with evaluating the performance of Signals Providers. We offer several additional parameters highlighting signal trading results from a slightly different angle than in traditional approaches. The concepts of the proper management and perfect deal are described. We also dwell on the optimal selection using the obtained results and compiling the portfolio of multiple signal sources.
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.
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.
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.
How to create an indicator of non-standard charts for MetaTrader Market
How to create an indicator of non-standard charts for MetaTrader Market

How to create an indicator of non-standard charts for MetaTrader Market

Through offline charts, programming in MQL4, and reasonable willingness, you can get a variety of chart types: "Point & Figure", "Renko", "Kagi", "Range bars", equivolume charts, etc. In this article, we will show how this can be achieved without using DLL, and therefore such "two-for-one" indicators can be published and purchased from the Market.
Applying fuzzy logic in trading by means of MQL4
Applying fuzzy logic in trading by means of MQL4

Applying fuzzy logic in trading by means of MQL4

The article deals with examples of applying fuzzy set theory in trading by means of MQL4. The use of FuzzyNet library for MQL4 in the development of an indicator and an Expert Advisor is described as well.
Enhancing the StrategyTester to Optimize Indicators Solely on the Example of Flat and Trend Markets
Enhancing the StrategyTester to Optimize Indicators Solely on the Example of Flat and Trend Markets

Enhancing the StrategyTester to Optimize Indicators Solely on the Example of Flat and Trend Markets

It is essential to detect whether a market is flat or not for many strategies. Using the well known ADX we demonstrate how we can use the Strategy Tester not only to optimize this indicator for our specific purpose, but as well we can decide whether this indicator will meet our needs and get to know the average range of the flat and trend markets which might be quite important to determine stops and targets of the markets.
Price Action. Automating the Engulfing Pattern Trading Strategy
Price Action. Automating the Engulfing Pattern Trading Strategy

Price Action. Automating the Engulfing Pattern Trading Strategy

This article describes a process of creating an Expert Advisor for MetaTrader 4 based on the Engulfing pattern, as well as the pattern recognition principle, rules of setting pending orders and stop orders. The results of testing and optimization are provided for your information.
Price Action. Automating the Inside Bar Trading Strategy
Price Action. Automating the Inside Bar Trading Strategy

Price Action. Automating the Inside Bar Trading Strategy

The article describes the development of a MetaTrader 4 Expert Advisor based on the Inside Bar strategy, including Inside Bar detection principles, as well as pending and stop order setting rules. Test and optimization results are provided as well.
Managing the MetaTrader Terminal via DLL
Managing the MetaTrader Terminal via DLL

Managing the MetaTrader Terminal via DLL

The article deals with managing MetaTrader user interface elements via an auxiliary DLL library using the example of changing push notification delivery settings. The library source code and the sample script are attached to the article.
Trading Ideas Based on Prices Direction and Movement Speed
Trading Ideas Based on Prices Direction and Movement Speed

Trading Ideas Based on Prices Direction and Movement Speed

The article provides a review of an idea based on the analysis of prices' movement direction and their speed. We have performed its formalization in the MQL4 language presented as an expert advisor to explore viability of the strategy being under consideration. We also determine the best parameters via check, examination and optimization of an example given in the article.
Why Is It Important to Update MetaTrader 4 to the Latest Build by August 1?
Why Is It Important to Update MetaTrader 4 to the Latest Build by August 1?

Why Is It Important to Update MetaTrader 4 to the Latest Build by August 1?

From August 1, 2014, MetaTrader 4 desktop terminals older than build 600 will no longer be supported. However, many traders still work with outdated versions and are unaware of the updated platform's features. We have put a lot of effort into development and would like to move on with traders and abandon the older builds. In this article, we will describe the advantages of the new MetaTrader 4.
Common Errors in MQL4 Programs and How to Avoid Them
Common Errors in MQL4 Programs and How to Avoid Them

Common Errors in MQL4 Programs and How to Avoid Them

To avoid critical completion of programs, the previous version compiler handled many errors in the runtime environment. For example, division by zero or array out of range are critical errors and usually lead to program crash. The new compiler can detect actual or potential sources of errors and improve code quality. In this article, we discuss possible errors that can be detected during compilation of old programs and see how to fix them.
Upgrade to MetaTrader 4 Build 600 and Higher
Upgrade to MetaTrader 4 Build 600 and Higher

Upgrade to MetaTrader 4 Build 600 and Higher

The new version of the MetaTrader 4 terminal features the updated structure of user data storage. In earlier versions all programs, templates, profiles etc. were stored directly in terminal installation folder. Now all necessary data required for a particular user are stored in a separate directory called data folder. Read the article to find answers to frequently asked questions.
Data Structure in MetaTrader 4 Build 600 and Higher
Data Structure in MetaTrader 4 Build 600 and Higher

Data Structure in MetaTrader 4 Build 600 and Higher

MetaTarder 4 build 600 features the new structure and location of the client terminal files. Now, MQL4 applications are placed in separate directories according to the program type (Expert Advisors, indicators or scripts). In most cases, the terminal data is now stored in a special data folder separated from the terminal installation location. In this article, we will describe in details how data is transferred, as well as the reasons for introducing the new storage system.
Offline Charts in the New MQL4
Offline Charts in the New MQL4

Offline Charts in the New MQL4

Updated MQL4 has the new format for storing historical data and provides the appropriate MqlRates structure for convenient storage of Time, Open, Low, High, Close and Volume values. For many years, traders have developed their MQL4 applications that collect and store their data in HST files for generating offline charts. We can assure you that all previously compiled EX4 files will work in the new MetaTrader 4 terminal the same way as before.
Visual Optimization of Indicator and Signal Profitability
Visual Optimization of Indicator and Signal Profitability

Visual Optimization of Indicator and Signal Profitability

This article is a continuation and development of my previous article "Visual Testing of Profitability of Indicators and Alerts". Having added some interactivity to the parameter changing process and having reworked the study objectives, I have managed to get a new tool that does not only show the prospective trade results based on the signals used but also allows you to immediately get a layout of deals, balance chart and the end result of trading by moving virtual sliders that act as controls for signal parameter values in the main chart.
EA Status SMS Notifications
EA Status SMS Notifications

EA Status SMS Notifications

Developing a system of SMS notifications that informs you of the status of your EA so that you are always aware of any critical situation, wherever you may be.
Expert Advisor for Trading in the Channel
Expert Advisor for Trading in the Channel

Expert Advisor for Trading in the Channel

The Expert Advisor plots the channel lines. The upper and lower channel lines act as support and resistance levels. The Expert Advisor marks datum points, provides sound notification every time the price reaches or crosses the channel lines and draws the relevant marks. Upon fractal formation, the corresponding arrows appear on the last bars. Line breakouts may suggest the possibility of a growing trend. The Expert Advisor is extensively commented throughout.
Alert and Comment for External Indicators (Part Two)
Alert and Comment for External Indicators (Part Two)

Alert and Comment for External Indicators (Part Two)

Since I published the article "Alert and Comment for External Indicators", I have been receiving requests and questions regarding the possibility of developing an external informer operating based on indicator lines. Having analyzed the questions, I have decided to continue with the subject. Getting data stored in indicator buffers turned out to be another area of interest to users.
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.
Graphical Control of External Parameters of Indicators
Graphical Control of External Parameters of Indicators

Graphical Control of External Parameters of Indicators

External variables of indicators are controlled using a special window where parameters can be changed and the indicator is then run again. The obvious inconvenience of these manipulations has given rise to the need for displaying the required parameters on the screen and controlling the indicator graphically.
Reading RSS News Feeds by Means of MQL4
Reading RSS News Feeds by Means of MQL4

Reading RSS News Feeds by Means of MQL4

This article deals with an example of reading RSS markup by means of MQL4 using the functions for HTML tags analysis. We will try to make a work piece which can then be turned into a news indicator or just an RSS reader on MQL4 language.
LibMatrix: Library of Matrix Algebra (Part One)
LibMatrix: Library of Matrix Algebra (Part One)

LibMatrix: Library of Matrix Algebra (Part One)

The author familiarizes the readers with a simple library of matrix algebra and provides descriptions and peculiarities of the main functions.
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.
The Random Sandbox
The Random Sandbox

The Random Sandbox

The article includes an interactive "sandbox" as an Excel file which simulates randomized Expert Advisor backtest data. Readers can use this to help explore and more deeply understand the EA performance metrics offered by default with MetaTrader. The text of the article is designed to guide the user through this experience.
MetaTrader 4 Expert Advisor exchanges information with the outside world
MetaTrader 4 Expert Advisor exchanges information with the outside world

MetaTrader 4 Expert Advisor exchanges information with the outside world

A simple, universal and reliable solution of information exchange between МetaТrader 4 Expert Advisor and the outside world. Suppliers and consumers of the information can be located on different computers, the connection is performed through the global IP addresses.
MetaTrader 4 on Linux
MetaTrader 4 on Linux

MetaTrader 4 on Linux

In this article, we demonstrate an easy way to install MetaTrader 4 on popular Linux versions — Ubuntu and Debian. These systems are widely used on server hardware as well as on traders’ personal computers.
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.
MetaTrader 4 on Mac OS
MetaTrader 4 on Mac OS

MetaTrader 4 on Mac OS

Apple products have become very popular. MetaQuotes Software Corp. attentively follows the progress of the IT industry and has already released the special mobile applications for iOS-based devices - MetaTrader 4 for iPhone and MetaTrader 5 for iPhone.There are many topics on the MQL4.community forum, where people are seeking a solution for running MetaTrader 4 under the Mac OS operating system. In this article, you will find out how to work in MetaTrader 4 via the Apple's popular operating system.
Trader's Kit: Drag Trade Library
Trader's Kit: Drag Trade Library

Trader's Kit: Drag Trade Library

The article describes Drag Trade Library that provides functionality for visual trading. The library can easily be integrated into virtually any Expert Advisor. Your Expert Advisor can be transformed from an automat into an automated trading and information system almost effortless on your side by just adding a few lines of code.
Fractal Analysis of Joint Currency Movements
Fractal Analysis of Joint Currency Movements

Fractal Analysis of Joint Currency Movements

How independent are currency quotes? Are their movements coordinated or does the movement of one currency suggest nothing of the movement of another? The article describes an effort to tackle this issue using nonlinear dynamics and fractal geometry methods.
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.
Enhancing the Quality of the Code with the Help of Unit Test
Enhancing the Quality of the Code with the Help of Unit Test

Enhancing the Quality of the Code with the Help of Unit Test

Even simple programs may often have errors that seem to be unbelievable. "How could I create that?" is our first thought when such an error is revealed. "How can I avoid that?" is the second question which comes to our mind less frequently. It is impossible to create absolutely faultless code, especially in big projects, but it is possible to use technologies for their timely detection. The article describes how the MQL4 code quality can be enhanced with the help of the popular Unit Testing method.
Protect Yourselves, Developers!
Protect Yourselves, Developers!

Protect Yourselves, Developers!

Protection of intellectual property is still a big problem. This article describes the basic principles of MQL4-programs protection. Using these principles you can ensure that results of your developments are not stolen by a thief, or at least to complicate his "work" so much that he will just refuse to do it.
Research of Statistical Recurrences of Candle Directions
Research of Statistical Recurrences of Candle Directions

Research of Statistical Recurrences of Candle Directions

Is it possible to predict the behavior of the market for a short upcoming interval of time, based on the recurring tendencies of candle directions, at specific times throughout the day? That is, If such an occurrence is found in the first place. This question has probably arisen in the mind of every trader. The purpose of this article is to attempt to predict the behavior of the market, based on the statistical recurrences of candle directions during specific intervals of time.
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.
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.
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.