New article Universal Expert Advisor: Custom Strategies and Auxiliary Trade Classes (Part 3) has been published:
In this article, we will continue analyzing the algorithms of the CStrategy trading engine. The third part of the series contains the detailed analysis of examples of how to develop specific trading strategies using this approach. Special attention is paid to auxiliary algorithms — Expert Advisor logging system and data access using a conventional indexer (Close, Open etc.)
In this part, we continue to discuss the
CStrategy trading engine. Here are the brief contents of the previous
two parts. In the first article Universal Expert Advisor: Trading Modes of Strategies,
we have discussed in detail trading modes that allow configuring Expert
Advisor logic in accordance with time and day of the week. In the
seconds article Universal Expert Advisors: the Event Model and Trading Strategy Prototype,
we have analyzed the event model based on centralized event handling,
as well as the main algorithms of the basic CStrategy class underlying
custom Expert Advisors.
In the third part of the series, we will
describe in detail the examples of Expert Advisors based on the
CStrategy trading engine and some auxiliary algorithms that may be
needed for the EA development. Particular attention is paid to the
logging procedure. Despite its purely supporting role, logging is a very
important element of any complex system. A good logger allows you to
quickly understand the cause of the problem and find the place where it
occurred. This logger is written using a special programming technique
called Singleton pattern.
Information about it will be interesting not only for those who
organize the trading process, but also for those who create algorithms
for performing non-standard tasks.
Also, the article describes the
algorithms that allow you to access market data through convenient and
intuitive indexes. Indeed, data access through indexes like Close and
High is a popular feature of MetaTrader 4. So why avoid it, if it
can also be used in MetaTrader 5? This article explains how to do this,
and describes in detail the algorithms that implement the above idea.
In the first article Universal Expert Advisor: Trading Modes of Strategies (Part 1),
we have considered in detail trading modes of a strategy and its main
methods that need to be overridden. Now, it is time to do some
Each Expert Advisor created using the
CStrategy engine must override virtual methods that are responsible for
some properties and behavior of the Expert Advisor. We will list all the
methods to be overridden as a table of three columns. The first one
contains the name of the virtual method, the second one shows the event
or action to be tracked or performed. The third column contains the
description of the purpose of using the method. So here is the table:
Table 1. Virtual methods and their purposes
The most important methods that you must override are InitBuy, InitSell, SupportBuy, and SupportSell.
They are shown in bold in the table. If you forget to override, for
example, InitBuy, the custom strategy will not buy. If you do not
override one of the Support methods, an open position can be left open
forever. Therefore, when creating an Expert Advisor, be careful
overriding these methods.
Author: Vasiliy Sokolov