Articles with MQL5 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
MQL5 Cookbook: The History of Deals And Function Library for Getting Position Properties
MQL5 Cookbook: The History of Deals And Function Library for Getting Position Properties

MQL5 Cookbook: The History of Deals And Function Library for Getting Position Properties

It is time to briefly summarize the information provided in the previous articles on position properties. In this article, we will create a few additional functions to get the properties that can only be obtained after accessing the history of deals. We will also get familiar with data structures that will allow us to access position and symbol properties in a more convenient way.
MQL5 Programming Basics: Time
MQL5 Programming Basics: Time

MQL5 Programming Basics: Time

The article focuses on standard MQL5 functions for working with time, as well as programming techniques and practically useful functions for working with time that are required when creating Expert Advisors and indicators. Particular attention is paid to the general theory of time measurement. This article should be of interest primarily to novice MQL5 programmers.
Debugging MQL5 Programs
Debugging MQL5 Programs

Debugging MQL5 Programs

This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.
MQL5 Cookbook: How to Avoid Errors When Setting/Modifying Trade Levels
MQL5 Cookbook: How to Avoid Errors When Setting/Modifying Trade Levels

MQL5 Cookbook: How to Avoid Errors When Setting/Modifying Trade Levels

In continuation of our work on the Expert Advisor from the previous article of the series called "MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester", we will enhance it with a whole lot of useful functions, as well as improve and optimize the existing ones. The Expert Advisor will this time have external parameters that can be optimized in the MetaTrader 5 Strategy Tester and will in some ways resemble a simple trading system.
MQL5 Programming Basics: Strings
MQL5 Programming Basics: Strings

MQL5 Programming Basics: Strings

The article covers everything you can do with strings in MQL5. It should be of interest primarily to novice MQL5 programmers, while experienced developers will have a good opportunity to summarize and systematize their knowledge.
MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester
MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester

MQL5 Cookbook: Analyzing Position Properties in the MetaTrader 5 Strategy Tester

We will present a modified version of the Expert Advisor from the previous article "MQL5 Cookbook: Position Properties on the Custom Info Panel". Some of the issues we will address include getting data from bars, checking for new bar events on the current symbol, including a trade class of the Standard Library to a file, creating a function to search for trading signals and a function for executing trading operations, as well as determining trade events in the OnTrade() function.
MQL5 Cookbook: Position Properties on the Custom Info Panel
MQL5 Cookbook: Position Properties on the Custom Info Panel

MQL5 Cookbook: Position Properties on the Custom Info Panel

This time we will create a simple Expert Advisor that will get position properties on the current symbol and display them on the custom info panel during manual trading. The info panel will be created using graphical objects and displayed information will be refreshed at every tick. This is going to be much more convenient than all the time having to manually run the script described in the previous article of the series called "MQL5 Cookbook: Getting Position Properties".
MQL5 Programming Basics: Arrays
MQL5 Programming Basics: Arrays

MQL5 Programming Basics: Arrays

Arrays are an integral part of almost any programming language along with variables and functions. The article should be of interest primarily to novice MQL5 programmers, while experienced programmers will have a good opportunity to summarize and systematize their knowledge.
MQL5 Cookbook: Getting Position Properties
MQL5 Cookbook: Getting Position Properties

MQL5 Cookbook: Getting Position Properties

In this article, we will create a script that gets all position properties and displays them to the user in a dialog box. Upon running the script, you will be able to select out of two modes available in the drop-down list in the external parameters: to either view position properties only on the current symbol or to view position properties on all symbols.
MQL5 Cookbook: Using Different Print Modes
MQL5 Cookbook: Using Different Print Modes

MQL5 Cookbook: Using Different Print Modes

This is the first article of the MQL5 Cookbook series. I will start with simple examples to allow those who are taking their first steps in programming to gradually become familiar with the new language. I remember my first efforts at designing and programming trading systems which I may say was quite difficult, given the fact that it was the first programming language in my life. However, it turned out to be easier than I thought and it only took me a few months before I could develop a fairly complex program.
Calculation of Integral Characteristics of Indicator Emissions
Calculation of Integral Characteristics of Indicator Emissions

Calculation of Integral Characteristics of Indicator Emissions

Indicator emissions are a little-studied area of market research. Primarily, this is due to the difficulty of analysis that is caused by the processing of very large arrays of time-varying data. Existing graphical analysis is too resource intensive and has therefore triggered the development of a parsimonious algorithm that uses time series of emissions. This article demonstrates how visual (intuitive image) analysis can be replaced with the study of integral characteristics of emissions. It can be of interest to both traders and developers of automated trading systems.
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.
Change Expert Advisor Parameters From the User Panel "On the Fly"
Change Expert Advisor Parameters From the User Panel "On the Fly"

Change Expert Advisor Parameters From the User Panel "On the Fly"

This article provides a small example demonstrating the implementation of an Expert Advisor whose parameters can be controlled from the user panel. When changing the parameters "on the fly", the Expert Advisor writes the values obtained from the info panel to a file to further read them from the file and display accordingly on the panel. This article may be relevant to those who trade manually or in semi-automatic mode.
Neural Networks: From Theory to Practice
Neural Networks: From Theory to Practice

Neural Networks: From Theory to Practice

Nowadays, every trader must have heard of neural networks and knows how cool it is to use them. The majority believes that those who can deal with neural networks are some kind of superhuman. In this article, I will try to explain to you the neural network architecture, describe its applications and show examples of practical use.
How to Prepare MetaTrader 5 Quotes for Other Applications
How to Prepare MetaTrader 5 Quotes for Other Applications

How to Prepare MetaTrader 5 Quotes for Other Applications

The article describes the examples of creating directories, copying data, filing, working with the symbols in Market Watch or the common list, as well as the examples of handling errors, etc. All these elements can eventually be gathered in a single script for filing the data in a user-defined format.
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.
How to Write a Good Description for a Market Product
How to Write a Good Description for a Market Product

How to Write a Good Description for a Market Product

MQL5 Market has many products for sale but some of their descriptions leave much to be desired. Many texts are obviously in need of improvement, as common traders are not able to comprehend them. This article will help you to put your product in a favorable light. Use our recommendations to write an eye-catching description that will easily show your customers what exactly you are selling.
Communicating With MetaTrader 5 Using Named Pipes Without Using DLLs
Communicating With MetaTrader 5 Using Named Pipes Without Using DLLs

Communicating With MetaTrader 5 Using Named Pipes Without Using DLLs

Many developers face the same problem - how to get to the trading terminal sandbox without using unsafe DLLs. One of the easiest and safest method is to use standard Named Pipes that work as normal file operations. They allow you to organize interprocessor client-server communication between programs. Take a look at practical examples in C++ and MQL5 that include server, client, data exchange between them and performance benchmark.
Quick Start: Short Guide for Beginners
Quick Start: Short Guide for Beginners

Quick Start: Short Guide for Beginners

Hello dear reader! In this article, I will try to explain and show you how you can easily and quickly get the hang of the principles of creating Expert Advisors, working with indicators, etc. It is beginner-oriented and will not feature any difficult or abstruse examples.
MetaQuotes ID in MetaTrader Mobile Terminal
MetaQuotes ID in MetaTrader Mobile Terminal

MetaQuotes ID in MetaTrader Mobile Terminal

Android and iOS powered devices offer us many features we do not even know about. One of these features is push notifications allowing us to receive personal messages, regardless of our phone number or mobile network operator. MetaTrader mobile terminal already can receive such messages right from your trading robot. You should only know MetaQuotes ID of your device. More than 9 000 000 mobile terminals have already received it.
Trade Operations in MQL5 - It's Easy
Trade Operations in MQL5 - It's Easy

Trade Operations in MQL5 - It's Easy

Almost all traders come to market to make money but some traders also enjoy the process itself. However, it is not only manual trading that can provide you with an exciting experience. Automated trading systems development can also be quite absorbing. Creating a trading robot can be as interesting as reading a good mystery novel.
preview
Fast Dive into MQL5

Fast Dive into MQL5

You have decided to study MQL5 trading strategies' programming language, but you know nothing about it? We have tried to examine MQL5 and MetaTrader 5 terminal from the newcomers' point of view and have written this short introductory article. In this article, you can find a brief idea of the possibilities of the language, as well as some tips on working with MetaEditor 5 and the terminal.
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.
preview
How to Make a Trading Robot in No Time

How to Make a Trading Robot in No Time

Trading on financial markets involves many risks including the most critical one - the risk of making a wrong trading decision. The dream of every trader is to find a trading robot, which is always in good shape and not subject to human weaknesses - fear, greed and impatience.
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.
preview
OpenCL: From Naive Towards More Insightful Programming

OpenCL: From Naive Towards More Insightful Programming

This article focuses on some optimization capabilities that open up when at least some consideration is given to the underlying hardware on which the OpenCL kernel is executed. The figures obtained are far from being ceiling values but even they suggest that having the existing resources available here and now (OpenCL API as implemented by the developers of the terminal does not allow to control some parameters important for optimization - particularly, the work group size), the performance gain over the host program execution is very substantial.
Visualize a Strategy in the MetaTrader 5 Tester
Visualize a Strategy in the MetaTrader 5 Tester

Visualize a Strategy in the MetaTrader 5 Tester

We all know the saying "Better to see once than hear a hundred times". You can read various books about Paris or Venice, but based on the mental images you wouldn't have the same feelings as on the evening walk in these fabulous cities. The advantage of visualization can easily be projected on any aspect of our lives, including work in the market, for example, the analysis of price on charts using indicators, and of course, the visualization of strategy testing. This article contains descriptions of all the visualization features of the MetaTrader 5 Strategy Tester.
preview
Get 200 usd for your algorithmic trading article!

Get 200 usd for your algorithmic trading article!

Write an article and contribute to the development of algorithmic trading. Share your experience in trading and programming, and we will pay you $200. Additionally, publishing an article on the popular MQL5.com website offers an excellent opportunity to promote your personal brand in a professional community. Thousands of traders will read your work. You can discuss your ideas with like-minded people, gain new experience, and monetize your knowledge.
OpenCL: The Bridge to Parallel Worlds
OpenCL: The Bridge to Parallel Worlds

OpenCL: The Bridge to Parallel Worlds

In late January 2012, the software development company that stands behind the development of MetaTrader 5 announced native support for OpenCL in MQL5. Using an illustrative example, the article sets forth the programming basics in OpenCL in the MQL5 environment and provides a few examples of the naive optimization of the program for the increase of operating speed.
MetaTrader 5 - More Than You Can Imagine!
MetaTrader 5 - More Than You Can Imagine!

MetaTrader 5 - More Than You Can Imagine!

The MetaTrader 5 client terminal has been developed from scratch and far surpasses its predecessor, of course. The new trading platform provides unlimited opportunities for trading in any financial market. Moreover, its functionality keeps expanding to offer even more useful features and convenience. So, it is now quite difficult to list all the numerous advantages of MetaTrader 5. We have tried to briefly describe them in one article, and we got surprised with the result' the article is far from brief!
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.
AutoElliottWaveMaker - MetaTrader 5 Tool for Semi-Automatic Analysis of Elliott Waves
AutoElliottWaveMaker - MetaTrader 5 Tool for Semi-Automatic Analysis of Elliott Waves

AutoElliottWaveMaker - MetaTrader 5 Tool for Semi-Automatic Analysis of Elliott Waves

The article provides a review of AutoElliottWaveMaker - the first development for Elliott Wave analysis in MetaTrader 5 that represents a combination of manual and automatic wave labeling. The wave analysis tool is written exclusively in MQL5 and does not include external dll libraries. This is another proof that sophisticated and interesting programs can (and should) be developed in MQL5.
Getting Rid of Self-Made DLLs
Getting Rid of Self-Made DLLs

Getting Rid of Self-Made DLLs

If MQL5 language functional is not enough for fulfilling tasks, an MQL5 programmer has to use additional tools. He\she has to pass to another programming language and create an intermediate DLL. MQL5 has the possibility to present various data types and transfer them to API but, unfortunately, MQL5 cannot solve the issue concerning data extraction from the accepted pointer. In this article we will dot all the "i"s and show simple mechanisms of exchanging and working with complex data types.
How to publish a product on the Market
How to publish a product on the Market

How to publish a product on the Market

Start offering your trading applications to millions of MetaTrader users from around the world though the Market. The service provides a ready-made infrastructure: access to a large audience, licensing solutions, trial versions, publication of updates and acceptance of payments. You only need to complete a quick seller registration procedure and publish your product. Start generating additional profits from your programs using the ready-made technical base provided by the service.
The Last Crusade
The Last Crusade

The Last Crusade

Take a look at your trading terminal. What means of price presentation can you see? Bars, candlesticks, lines. We are chasing time and prices whereas we only profit from prices. Shall we only give attention to prices when analyzing the market? This article proposes an algorithm and a script for point and figure charting ("naughts and crosses") Consideration is given to various price patterns whose practical use is outlined in recommendations provided.
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.
Create Your Own Trading Robot in 6 Steps!
Create Your Own Trading Robot in 6 Steps!

Create Your Own Trading Robot in 6 Steps!

If you don't know how trade classes are constructed, and are scared of the words "Object Oriented Programming", then this article is for you. In fact, you do not need to know the details to write your own module of trading signals. Just follow some simple rules. All the rest will be done by the MQL5 Wizard, and you will get a ready-to-use trading robot!
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.
Promote Your Development Projects Using EX5 Libraries
Promote Your Development Projects Using EX5 Libraries

Promote Your Development Projects Using EX5 Libraries

Hiding of the implementation details of classes/functions in an .ex5 file will enable you to share your know-how algorithms with other developers, set up common projects and promote them in the Web. And while the MetaQuotes team spares no effort to bring about the possibility of direct inheritance of ex5 library classes, we are going to implement it right now.
Securing MQL5 code: Password Protection, Key Generators, Time-limits, Remote Licenses and Advanced EA License Key Encryption Techniques
Securing MQL5 code: Password Protection, Key Generators, Time-limits, Remote Licenses and Advanced EA License Key Encryption Techniques

Securing MQL5 code: Password Protection, Key Generators, Time-limits, Remote Licenses and Advanced EA License Key Encryption Techniques

Most developers need to have their code secured. This article will present a few different ways to protect MQL5 software - it presents methods to provide licensing capabilities to MQL5 Scripts, Expert Advisors and Indicators. It covers password protection, key generators, account license, time-limit evaluation and remote protection using MQL5-RPC calls.