Discussion of article "Universal Expert Advisor: Custom Strategies and Auxiliary Trade Classes (Part 3)"

 

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[1], Open[0] 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[1] and High[0] 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.

Methods to Be Overridden by the Custom Expert Advisor

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 practicing.

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:

Virtual method Event/Action Purpose
OnSymbolChanged Called when the name of a trading symbol changes When you change the trading instrument, the EA's indicators should be re-initialized. The event allows performing re-initialization of indicators of the Expert Advisor.
OnTimeframeChanged Change of the working timframe When you change the working timeframe, the EA's indicators should be re-initialized. The event allows performing re-initialization of indicators of the Expert Advisor.
ParseXmlParams Parsing custom parameters of the strategy loaded via n XML file The strategy should recognize XML parameters passed to the method and configure its settings accordingly.
ExpertNameFull Returns the full name of the Expert Advisor The full name of the Expert Advisor consists of the strategy name and, as a rule, a unique set of the strategy parameters. A strategy instance must independently determine its full name. This name is also used in the visual panel, in the drop-down Agent list.
OnTradeTransaction Occurs in case of a trade event Some strategies need to analyze trade events for proper operation. This event allows passing a trade event to the Expert Advisor and analyze it.
InitBuy Initiates a Buy operation One of the basic methods that must be overridden. In this method you should execute a Buy operation if suitable trading conditions have formed.
InitSell Initiates a Sell operation One of the basic methods that must be overridden. In this method you should execute a Sell operation if suitable trading conditions have formed.
SupportBuy Manages a previously opened long position An open long position needs to be managed. For example, you should set Stop Loss or close the position at a position exit signal. All these steps must be performed in this method.
SupportSell Manages a previously opened short position An open short position needs to be managed. For example, you should set Stop Loss or close the position at a position exit signal. All these steps must be performed in this method.

 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

 
Thank you for this nice article.
 
Hello. The " Example of Expert Advisor Trading Two Moving Averages' cant be complied as it has 70 errors.


Reason: