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
Universal ZigZag
Universal ZigZag

Universal ZigZag

ZigZag is one of the most popular indicators among the MetaTrader 5 users. The article analyzes the possibilities for creating various versions of the ZigZag. The result is a universal indicator with ample opportunities to extend its functionality, which is useful in the development of trading experts and other indicators.
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.
80-20 trading strategy
80-20 trading strategy

80-20 trading strategy

The article describes the development of tools (indicator and Expert Advisor) for analyzing the '80-20' trading strategy. The trading strategy rules are taken from the work "Street Smarts. High Probability Short-Term Trading Strategies" by Linda Raschke and Laurence Connors. We are going to formalize the strategy rules using the MQL5 language and test the strategy-based indicator and EA on the recent market history.
LifeHack for Trader: A comparative report of several tests
LifeHack for Trader: A comparative report of several tests

LifeHack for Trader: A comparative report of several tests

The article deals with the simultaneous launch of Expert Advisor testing on four different trading instruments. The final comparison of four testing reports is provided in a table similar to how goods are represented in online stores. An additional bonus is that distribution charts will be automatically created for each symbol.
The 'Turtle Soup' trading system and its 'Turtle Soup Plus One' modification
The 'Turtle Soup' trading system and its 'Turtle Soup Plus One' modification

The 'Turtle Soup' trading system and its 'Turtle Soup Plus One' modification

The article features formalized rules of two trading strategies 'Turtle Soup' and 'Turtle Soup Plus One' from Street Smarts: High Probability Short-Term Trading Strategies by Linda Bradford Raschke and Laurence A. Connors. The strategies described in the book are quite popular. But it is important to understand that the authors have developed them based on the 15...20 year old market behavior.
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal
MQL5 Programming Basics: Global Variables of the  MetaTrader 5 Terminal

MQL5 Programming Basics: Global Variables of the MetaTrader 5 Terminal

Global variables of the terminal provide an indispensable tool for developing sophisticated and reliable Expert Advisors. If you master the global variables, you will no more be able to imagine developing EAs on MQL5 without them.
Graphical Interfaces X: The Standard Chart Control (build 4)
Graphical Interfaces X: The Standard Chart Control (build 4)

Graphical Interfaces X: The Standard Chart Control (build 4)

This time we will consider the Standard chart control. It will allow to create arrays of subcharts with the ability to synchronize horizontal scrolling. In addition, we will continue to optimize the library code to reduce the CPU load.
MQL5 Programming Basics: Files
MQL5 Programming Basics: Files

MQL5 Programming Basics: Files

This practice-oriented article focuses on working with files in MQL5. It offers a number of simple tasks allowing you to grasp the basics and hone your skills.
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)
Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

Graphical Interfaces X: Updates for Easy And Fast Library (Build 3)

The next version of the Easy And Fast library (version 3) is presented in this article. Fixed certain flaws and added new features. More details further in the article.
Neural network: Self-optimizing Expert Advisor
Neural network: Self-optimizing Expert Advisor

Neural network: Self-optimizing Expert Advisor

Is it possible to develop an Expert Advisor able to optimize position open and close conditions at regular intervals according to the code commands? What happens if we implement a neural network (multilayer perceptron) in the form of a module to analyze history and provide strategy? We can make the EA optimize a neural network monthly (weekly, daily or hourly) and continue its work afterwards. Thus, we can develop a self-optimizing EA.
preview
Statistical Distributions in MQL5 - taking the best of R and making it faster

Statistical Distributions in MQL5 - taking the best of R and making it faster

The functions for working with the basic statistical distributions implemented in the R language are considered. Those include the Cauchy, Weibull, normal, log-normal, logistic, exponential, uniform, gamma distributions, the central and noncentral beta, chi-squared, Fisher's F-distribution, Student's t-distribution, as well as the discrete binomial and negative binomial distributions, geometric, hypergeometric and Poisson distributions. There are functions for calculating theoretical moments of distributions, which allow to evaluate the degree of conformity of the real distribution to the modeled one.
Working with currency baskets in the Forex market
Working with currency baskets in the Forex market

Working with currency baskets in the Forex market

The article describes how currency pairs can be divided into groups (baskets), as well as how to obtain data about their status (for example, overbought and oversold) using certain indicators and how to apply this data in trading.
The Easy Way to Evaluate a Signal: Trading Activity, Drawdown/Load and MFE/MAE Distribution Charts
The Easy Way to Evaluate a Signal: Trading Activity, Drawdown/Load and MFE/MAE Distribution Charts

The Easy Way to Evaluate a Signal: Trading Activity, Drawdown/Load and MFE/MAE Distribution Charts

Subscribers often search for an appropriate signal by analyzing the total growth on the signal provider's account, which is not a bad idea. However, it is also important to analyze potential risks of a particular trading strategy. In this article we will show a simple and efficient way to evaluate a Trading Signal based on its performance values.
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.
LifeHack for trader: "Quiet" optimization or Plotting trade distributions
LifeHack for trader: "Quiet" optimization or Plotting trade distributions

LifeHack for trader: "Quiet" optimization or Plotting trade distributions

Analysis of the trade history and plotting distribution charts of trading results in HTML depending on position entry time. The charts are displayed in three sections - by hours, by days of the week and by months.
MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?
MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?

MQL5 vs QLUA - Why trading operations in MQL5 are up to 28 times faster?

Have you ever wondered how quickly your order is delivered to the exchange, how fast it is executed, and how much time your terminal needs in order to receive the operation result? We have prepared a comparison of trading operation execution speed, because no one has ever measured these values using applications in MQL5 and QLUA.
Cross-Platform Expert Advisor: Orders
Cross-Platform Expert Advisor: Orders

Cross-Platform Expert Advisor: Orders

MetaTrader 4 and MetaTrader 5 uses different conventions in processing trade requests. This article discusses the possibility of using a class object that can be used to represent the trades processed by the server, in order for a cross-platform expert advisor to further work on them, regardless of the version of the trading platform and mode being used.
MQL5 Cookbook - Trading signals of moving channels
MQL5 Cookbook - Trading signals of moving channels

MQL5 Cookbook - Trading signals of moving channels

The article describes the process of developing and implementing a class for sending signals based on the moving channels. Each of the signal version is followed by a trading strategy with testing results. Classes of the Standard Library are used for creating derived classes.
How to quickly develop and debug a trading strategy in MetaTrader 5
How to quickly develop and debug a trading strategy in MetaTrader 5

How to quickly develop and debug a trading strategy in MetaTrader 5

Scalping automatic systems are rightfully regarded the pinnacle of algorithmic trading, but at the same time their code is the most difficult to write. In this article we will show how to build strategies based on analysis of incoming ticks using the built-in debugging tools and visual testing. Developing rules for entry and exit often require years of manual trading. But with the help of MetaTrader 5, you can quickly test any such strategy on real history.
How to copy signals using an EA by your rules?
How to copy signals using an EA by your rules?

How to copy signals using an EA by your rules?

When you subscribe to signals, such situation may occur: your trade account has a leverage of 1:100, the provider has a leverage of 1:500 and trades using the minimal lot, and your trade balances are virtually equal — but the copy ratio will comprise only 10% to 15%. This article describes how to increase the copy rate in such cases.
Graphical Interfaces X: Updates for Easy And Fast Library (Build 2)
Graphical Interfaces X: Updates for Easy And Fast Library (Build 2)

Graphical Interfaces X: Updates for Easy And Fast Library (Build 2)

Since the publication of the previous article in the series, Easy And Fast library has received some new features. The library structure and code have been partially optimized slightly reducing CPU load. Some recurring methods in many control classes have been moved to the CElement base class.
False trigger protection for Trading Robot
False trigger protection for Trading Robot

False trigger protection for Trading Robot

Profitability of trading systems is defined not only by logic and precision of analyzing the financial instrument dynamics, but also by the quality of the performance algorithm of this logic. False trigger is typical for low quality performance of the main logic of a trading robot. Ways of solving the specified problem are considered in this article.
Graphical Interfaces IX: The Progress Bar and Line Chart Controls (Chapter 2)
Graphical Interfaces IX: The Progress Bar and Line Chart Controls (Chapter 2)

Graphical Interfaces IX: The Progress Bar and Line Chart Controls (Chapter 2)

The second chapter of the part nine is dedicated to the progress bar and line chart controls. As always, there will be detailed examples provided to reveal how these controls can be used in custom MQL applications.
Graphical Interfaces IX: The Color Picker Control (Chapter 1)
Graphical Interfaces IX: The Color Picker Control (Chapter 1)

Graphical Interfaces IX: The Color Picker Control (Chapter 1)

With this article we begin chapter nine of series of articles dedicated to creating graphical interfaces in MetaTrader trading terminals. It consists of two chapters where new elements of controls and interface, such as color picker, color button, progress bar and line chart are presented.
Cross-Platform Expert Advisor: Reuse of Components from the MQL5 Standard Library
Cross-Platform Expert Advisor: Reuse of Components from the MQL5 Standard Library

Cross-Platform Expert Advisor: Reuse of Components from the MQL5 Standard Library

There exists some components in the MQL5 Standard Library that may prove to be useful in the MQL4 version of cross-platform expert advisors. This article deals with a method of making certain components of the MQL5 Standard Library compatible with the MQL4 compiler.
LifeHack for trader: four backtests are better than one
LifeHack for trader: four backtests are better than one

LifeHack for trader: four backtests are better than one

Before the first single test, every trader faces the same question — "Which of the four modes to use?" Each of the provided modes has its advantages and features, so we will do it the easy way - run all four modes at once with a single button! The article shows how to use the Win API and a little magic to see all four testing chart at the same time.
Graphical Interfaces VIII: the File Navigator Control (Chapter 3)
Graphical Interfaces VIII: the File Navigator Control (Chapter 3)

Graphical Interfaces VIII: the File Navigator Control (Chapter 3)

In the previous chapters of the eighth part of the series, our library has been reinforced by several classes for developing mouse pointers, calendars and tree views. The current article deals with the file navigator control that can also be used as part of an MQL application graphical interface.
Cross-Platform Expert Advisor: Introduction
Cross-Platform Expert Advisor: Introduction

Cross-Platform Expert Advisor: Introduction

This article details a method by which cross-platform expert advisors can be developed faster and easier. The proposed method consolidates the features shared by both versions into a single class, and splits the implementation on derived classes for incompatible features.
Graphical Interfaces VIII: The Tree View Control (Chapter 2)
Graphical Interfaces VIII: The Tree View Control (Chapter 2)

Graphical Interfaces VIII: The Tree View Control (Chapter 2)

The previous chapter of part VIII on graphical interfaces has focused on the elements of static and drop-down calendar. The second chapter will be dedicated to an equally complex element — a tree view, that is included in every complete library used for creating graphical interfaces. A tree view implemented in this article contains multiple flexible settings and modes, thus allowing to adjust this element of control to your needs.
Graphical Interfaces VIII: The Calendar Control (Chapter 1)
Graphical Interfaces VIII: The Calendar Control (Chapter 1)

Graphical Interfaces VIII: The Calendar Control (Chapter 1)

In the part VIII of the series of articles dedicated to creating graphical interfaces in MetaTrader, we will consider complex composite controls like calendars, tree view, and file navigator. Due to the large amount of information, there are separate articles written for every subject. The first chapter of this part describes the calendar control and its expanded version — a drop down calendar.
Graphical Interfaces VII: The Tabs Control (Chapter 2)
Graphical Interfaces VII: The Tabs Control (Chapter 2)

Graphical Interfaces VII: The Tabs Control (Chapter 2)

The first chapter of seventh part introduced three classes of controls for creating tables: text label table (CLabelsTable), edit box table (CTable) and rendered table (CCanvasTable). In this article (chapter two) we are going to consider the Tabs control.
Testing trading strategies on real ticks
Testing trading strategies on real ticks

Testing trading strategies on real ticks

The article provides the results of testing a simple trading strategy in three modes: "1 minute OHLC", "Every tick" and "Every tick based on real ticks" using actual historical data.
Graphical Interfaces VII: the Tables Controls (Chapter 1)
Graphical Interfaces VII: the Tables Controls (Chapter 1)

Graphical Interfaces VII: the Tables Controls (Chapter 1)

The seventh part of the series on MetaTrader graphical interfaces deals with three table types: text label, edit box and rendered one. Another important and frequently used controls are tabs allowing you to show/hide groups of other controls and develop space effective interfaces in your MQL applications.
The checks a trading robot must pass before publication in the Market
The checks a trading robot must pass before publication in the Market

The checks a trading robot must pass before publication in the Market

Before any product is published in the Market, it must undergo compulsory preliminary checks in order to ensure a uniform quality standard. This article considers the most frequent errors made by developers in their technical indicators and trading robots. An also shows how to self-test a product before sending it to the Market.
LifeHack for Traders: Indicators of Balance, Drawdown, Load and Ticks during Testing
LifeHack for Traders: Indicators of Balance, Drawdown, Load and Ticks during Testing

LifeHack for Traders: Indicators of Balance, Drawdown, Load and Ticks during Testing

How to make the testing process more visual? The answer is simple: you need to use one or more indicators in the Strategy Tester, including a tick indicator, an indicator of balance and equity, an indicator of drawdown and deposit load. This solution will help you visually track the nature of ticks, balance and equity changes, as well as drawdown and deposit load.
Universal Expert Advisor: Integration with Standard MetaTrader Modules of Signals (Part 7)
Universal Expert Advisor: Integration with Standard MetaTrader Modules of Signals (Part 7)

Universal Expert Advisor: Integration with Standard MetaTrader Modules of Signals (Part 7)

This part of the article describes the possibilities of the CStrategy engine integration with the signal modules included into the standard library in MetaTrader. The article describes how to work with signals, as well as how to create custom strategies on their basis.
Working with sockets in MQL, or How to become a signal provider
Working with sockets in MQL, or How to become a signal provider

Working with sockets in MQL, or How to become a signal provider

Sockets… What in our IT world could possibly exist without them? Dating back to 1982, and hardly changed up to the present time, they smoothly work for us every second. This is the foundation of network, the nerve endings of the Matrix we all live in.
Using text files for storing input parameters of Expert Advisors, indicators and scripts
Using text files for storing input parameters of Expert Advisors, indicators and scripts

Using text files for storing input parameters of Expert Advisors, indicators and scripts

The article describes the application of text files for storing dynamic objects, arrays and other variables used as properties of Expert Advisors, indicators and scripts. The files serve as a convenient addition to the functionality of standard tools offered by MQL languages.
Regular expressions for traders
Regular expressions for traders

Regular expressions for traders

A regular expression is a special language for handling texts by applying a specified rule, also called a regex or regexp for short. In this article, we are going to show how to handle a trade report with the RegularExpressions library for MQL5, and will also demonstrate the optimization results after using it.
Creating a trading robot for Moscow Exchange. Where to start?
Creating a trading robot for Moscow Exchange. Where to start?

Creating a trading robot for Moscow Exchange. Where to start?

Many traders on Moscow Exchange would like to automate their trading algorithms, but they do not know where to start. The MQL5 language offers a huge range of trading functions, and it additionally provides ready classes that help users to make their first steps in algo trading.