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
Rope Indicator by Erik Nayman
Rope Indicator by Erik Nayman

Rope Indicator by Erik Nayman

The article reveals how the "Rope" indicator is created based on "The Small Encyclopedia of Trader" by Erik L. Nayman. This indicator shows the direction of the trend using the calculated values of bulls and bears over a specified period of time. The article also contains principles of creating and calculating indicators along with the examples of codes. Other subjects covered include building an Expert Advisor based on the indicator, and the optimization of external parameters.
Graphical Interfaces I: Form for Controls (Chapter 2)
Graphical Interfaces I: Form for Controls (Chapter 2)

Graphical Interfaces I: Form for Controls (Chapter 2)

In this article we will create the first and main element of the graphical interface - a form for controls. Multiple controls can be attached to this form anywhere and in any combination.
Graphical Interfaces I: Preparation of the Library Structure (Chapter 1)
Graphical Interfaces I: Preparation of the Library Structure (Chapter 1)

Graphical Interfaces I: Preparation of the Library Structure (Chapter 1)

This article is the beginning of another series concerning development of graphical interfaces. Currently, there is not a single code library that would allow quick and easy creation of high quality graphical interfaces within MQL applications. By that, I mean the graphical interfaces that we are used to in familiar operating systems.
Market Theory
Market Theory

Market Theory

A logically complete market theory that would cover all types and varieties of markets for goods and services, micro and macro markets like Forex, hasn't been available until now. This article covers the essence of a new market theory based on the profit analysis, reveals patterns of the current price change and the principle of the mechanism operation that allows the price to find its most optimal value by forming a chain of virtual prices that can develop the controlling influence on the actual price. Mechanisms of formation and change of market trends are also identified here.
MQL5 for beginners: Anti-vandal protection of graphic objects
MQL5 for beginners: Anti-vandal protection of graphic objects

MQL5 for beginners: Anti-vandal protection of graphic objects

What should your program do, if graphic control panels have been removed or modified by someone else? In this article we will show you how not to have "ownerless" objects on the chart, and how not to lose control over them in cases of renaming or deleting programmatically created objects after the application is deleted.
Using Assertions in MQL5 Programs
Using Assertions in MQL5 Programs

Using Assertions in MQL5 Programs

This article covers the use of assertions in MQL5 language. It provides two examples of the assertion mechanism and some general guidance for implementing assertions.
Error Handling and Logging in MQL5
Error Handling and Logging in MQL5

Error Handling and Logging in MQL5

This article focuses on general issues linked to handling software errors. Furthermore, the logging term is brought up and the examples of logging implementation with MQL5 tools are shown.
Evaluation and selection of variables for machine learning models
Evaluation and selection of variables for machine learning models

Evaluation and selection of variables for machine learning models

This article focuses on specifics of choice, preconditioning and evaluation of the input variables (predictors) for use in machine learning models. New approaches and opportunities of deep predictor analysis and their influence on possible overfitting of models will be considered. The overall result of using models largely depends on the result of this stage. We will analyze two packages offering new and original approaches to the selection of predictors.
Handling ZIP Archives in Pure MQL5
Handling ZIP Archives in Pure MQL5

Handling ZIP Archives in Pure MQL5

The MQL5 language keeps evolving, and its new features for working with data are constantly being added. Due to innovation it has recently become possible to operate with ZIP archives using regular MQL5 tools without getting third party DLL libraries involved. This article focuses on how this is done and provides the CZip class, which is a universal tool for reading, creating and modifying ZIP archives, as an example.
Indicator for Spindles Charting
Indicator for Spindles Charting

Indicator for Spindles Charting

The article regards spindle chart plotting and its usage in trading strategies and experts. First let's discuss the chart's appearance, plotting and connection with japanese candlestick chart. Next we analyze the indicator's implementation in the source code in the MQL5 language. Let's test the expert based on indicator and formulate the trading strategy.
MQL5 Cookbook: Implementing Your Own Depth of Market
MQL5 Cookbook: Implementing Your Own Depth of Market

MQL5 Cookbook: Implementing Your Own Depth of Market

This article demonstrates how to utilize Depth of Market (DOM) programmatically and describes the operation principle of CMarketBook class, that can expand the Standard Library of MQL5 classes and offer convenient methods of using DOM.
How to Secure Your Expert Advisor While Trading on the Moscow Exchange
How to Secure Your Expert Advisor While Trading on the Moscow Exchange

How to Secure Your Expert Advisor While Trading on the Moscow Exchange

The article delves into the trading methods ensuring the security of trading operations at the stock and low-liquidity markets through the example of Moscow Exchange's Derivatives Market. It brings practical approach to the trading theory described in the article "Principles of Exchange Pricing through the Example of Moscow Exchange's Derivatives Market".
Drawing Resistance and Support Levels Using MQL5
Drawing Resistance and Support Levels Using MQL5

Drawing Resistance and Support Levels Using MQL5

This article describes a method of finding four extremum points for drawing support and resistance levels based on them. In order to find extremums on a chart of a currency pair, RSI indicator is used. To give an example, we have provided an indicator code that displays support and resistance levels.
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.
How to Develop a Profitable Trading Strategy
How to Develop a Profitable Trading Strategy

How to Develop a Profitable Trading Strategy

This article provides an answer to the question: "Is it possible to formulate an automated trading strategy based on history data with neural networks?".
An Introduction to Fuzzy Logic
An Introduction to Fuzzy Logic

An Introduction to Fuzzy Logic

Fuzzy logic expands our boundaries of mathematical logic and set theory. This article reveals the basic principles of fuzzy logic as well as describes two fuzzy inference systems using Mamdani-type and Sugeno-type models. The examples provided will describe implementation of fuzzy models based on these two systems using the FuzzyNet library for MQL5.
Using Layouts and Containers for GUI Controls: The CGrid Class
Using Layouts and Containers for GUI Controls: The CGrid Class

Using Layouts and Containers for GUI Controls: The CGrid Class

This article presents an alternative method of GUI creation based on layouts and containers, using one layout manager — the CGrid class. The CGrid class is an auxiliary control that acts as a container for other containers and controls using a grid layout.
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.
Drawing Dial Gauges Using the CCanvas Class
Drawing Dial Gauges Using the CCanvas Class

Drawing Dial Gauges Using the CCanvas Class

We can find dial gauges in cars and airplanes, in industrial production and everyday life. They are used in all spheres which require quick response to behavior of a controlled value. This article describes the library of dial gauges for MetaTrader 5.
Statistical Verification of the Labouchere Money Management System
Statistical Verification of the Labouchere Money Management System

Statistical Verification of the Labouchere Money Management System

In this article, we test the statistical properties of the Labouchere money management system. It is considered to be a less aggressive kind of Martingale, since bets are not doubled, but are raised by a certain amount instead.
Using Layouts and Containers for GUI Controls: The CBox Class
Using Layouts and Containers for GUI Controls: The CBox Class

Using Layouts and Containers for GUI Controls: The CBox Class

This article presents an alternative method of GUI creation based on layouts and containers, using one layout manager — the CBox class. The CBox class is an auxiliary control that acts as a container for essential controls in a GUI panel. It can make designing graphical panels easier, and in some cases, reduce coding time.
Identifying Trade Setups by Support, Resistance and Price Action
Identifying Trade Setups by Support, Resistance and Price Action

Identifying Trade Setups by Support, Resistance and Price Action

This article shows how price action and the monitoring of support and resistance levels can be used for well-timed market entry. It discusses a trading system that effectively combines the two for the determination of trade setups. Corresponding MQL4 code is explained that can be utilized in the EAs based on these trading concepts.
Tips for Selecting a Trading Signal to Subscribe. Step-By-Step Guide
Tips for Selecting a Trading Signal to Subscribe. Step-By-Step Guide

Tips for Selecting a Trading Signal to Subscribe. Step-By-Step Guide

This step-by-step guide is dedicated to the Signals service, examination of trading signals, a system approach to the search of a required signal which would satisfy criteria of profitability, risk, trading ambitions, working on various types of accounts and financial instruments.
MQL5 Cookbook: Implementing an Associative Array or a Dictionary for Quick Data Access
MQL5 Cookbook: Implementing an Associative Array or a Dictionary for Quick Data Access

MQL5 Cookbook: Implementing an Associative Array or a Dictionary for Quick Data Access

This article describes a special algorithm allowing to gain access to elements by their unique keys. Any base data type can be used as a key. For example it may be represented as a string or an integer variable. Such data container is commonly referred to as a dictionary or an associative array. It provides easier and more efficient way of problem solving.
Tips for Purchasing a Product on the Market. Step-By-Step Guide
Tips for Purchasing a Product on the Market. Step-By-Step Guide

Tips for Purchasing a Product on the Market. Step-By-Step Guide

This step-by-step guide provides tips and tricks for better understanding and searching for a required product. The article makes an attempt to puzzle out different methods of searching for an appropriate product, sorting out unwanted products, determining product efficiency and essentiality for you.
Plotting trend lines based on fractals using MQL4 and MQL5
Plotting trend lines based on fractals using MQL4 and MQL5

Plotting trend lines based on fractals using MQL4 and MQL5

The article describes the automation of trend lines plotting based on the Fractals indicator using MQL4 and MQL5. The article structure provides a comparative view of the solution for two languages. Trend lines are plotted using two last known fractals.
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.
Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal API, Part 2
Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal API, Part 2

Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal API, Part 2

This article describes a new approach to hedging of positions and draws the line in the debates between users of MetaTrader 4 and MetaTrader 5 about this matter. It is a continuation of the first part: "Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal Panel, Part 1". In the second part, we discuss integration of custom Expert Advisors with HedgeTerminalAPI, which is a special visualization library designed for bi-directional trading in a comfortable software environment providing tools for convenient position management.
Studying the CCanvas Class. How to Draw Transparent Objects
Studying the CCanvas Class. How to Draw Transparent Objects

Studying the CCanvas Class. How to Draw Transparent Objects

Do you need more than awkward graphics of moving averages? Do you want to draw something more beautiful than a simple filled rectangle in your terminal? Attractive graphics can be drawn in the terminal. This can be implemented through the CСanvas class, which is used for creating custom graphics. With this class you can implement transparency, blend colors and produce the illusion of transparency by means of overlapping and blending colors.
Optimization. A Few Simple Ideas
Optimization. A Few Simple Ideas

Optimization. A Few Simple Ideas

The optimization process can require significant resources of your computer or even of the MQL5 Cloud Network test agents. This article comprises some simple ideas that I use for work facilitation and improvement of the MetaTrader 5 Strategy Tester. I got these ideas from the documentation, forum and articles.
Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal Panel, Part 1
Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal Panel, Part 1

Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal Panel, Part 1

This article describes a new approach to hedging of positions and draws the line in the debates between users of MetaTrader 4 and MetaTrader 5 about this matter. The algorithms making such hedging reliable are described in layman's terms and illustrated with simple charts and diagrams. This article is dedicated to the new panel HedgeTerminal, which is essentially a fully featured trading terminal within MetaTrader 5. Using HedgeTerminal and the virtualization of the trade it offers, positions can be managed in the way similar to MetaTrader 4.
Principles of Exchange Pricing through the Example of Moscow Exchange's Derivatives Market
Principles of Exchange Pricing through the Example of Moscow Exchange's Derivatives Market

Principles of Exchange Pricing through the Example of Moscow Exchange's Derivatives Market

This article describes the theory of exchange pricing and clearing specifics of Moscow Exchange's Derivatives Market. This is a comprehensive article for beginners who want to get their first exchange experience on derivatives trading, as well as for experienced forex traders who are considering trading on a centralized exchange platform.
MQL5 Cookbook: ОСО Orders
MQL5 Cookbook: ОСО Orders

MQL5 Cookbook: ОСО Orders

Any trader's trading activity involves various mechanisms and interrelationships including relations among orders. This article suggests a solution of OCO orders processing. Standard library classes are extensively involved, as well as new data types are created herein.
Building an Interactive Application to Display RSS Feeds in MetaTrader 5
Building an Interactive Application to Display RSS Feeds in MetaTrader 5

Building an Interactive Application to Display RSS Feeds in MetaTrader 5

In this article we look at the possibility of creating an application for the display of RSS feeds. The article will show how aspects of the Standard Library can be used to create interactive programs for MetaTrader 5.
Trader's Statistical Cookbook: Hypotheses
Trader's Statistical Cookbook: Hypotheses

Trader's Statistical Cookbook: Hypotheses

This article considers hypothesis - one of the basic ideas of mathematical statistics. Various hypotheses are examined and verified through examples using methods of mathematical statistics. The actual data is generalized using nonparametric methods. The Statistica package and the ported ALGLIB MQL5 numerical analysis library are used for processing data.
Third Generation Neural Networks: Deep Networks
Third Generation Neural Networks: Deep Networks

Third Generation Neural Networks: Deep Networks

This article is dedicated to a new and perspective direction in machine learning - deep learning or, to be precise, deep neural networks. This is a brief review of second generation neural networks, the architecture of their connections and main types, methods and rules of learning and their main disadvantages followed by the history of the third generation neural network development, their main types, peculiarities and training methods. Conducted are practical experiments on building and training a deep neural network initiated by the weights of a stacked autoencoder with real data. All the stages from selecting input data to metric derivation are discussed in detail. The last part of the article contains a software implementation of a deep neural network in an Expert Advisor with a built-in indicator based on MQL4/R.
Neural Networks Cheap and Cheerful - Link NeuroPro with MetaTrader 5
Neural Networks Cheap and Cheerful - Link NeuroPro with MetaTrader 5

Neural Networks Cheap and Cheerful - Link NeuroPro with MetaTrader 5

If specific neural network programs for trading seem expensive and complex or, on the contrary, too simple, try NeuroPro. It is free and contains the optimal set of functionalities for amateurs. This article will tell you how to use it in conjunction with MetaTrader 5.
Programming EA's Modes Using Object-Oriented Approach
Programming EA's Modes Using Object-Oriented Approach

Programming EA's Modes Using Object-Oriented Approach

This article explains the idea of multi-mode trading robot programming in MQL5. Every mode is implemented with the object-oriented approach. Instances of both mode classes hierarchy and classes for testing are provided. Multi-mode programming of trading robots is supposed to take into account all peculiarities of every operational mode of an EA written in MQL5. Functions and enumeration are created for identifying the mode.
Random Forests Predict Trends
Random Forests Predict Trends

Random Forests Predict Trends

This article considers using the Rattle package for automatic search of patterns for predicting long and short positions of currency pairs on Forex. This article can be useful both for novice and experienced traders.