Discussion of article "Universal Expert Advisor: Trading Modes of Strategies (Part 1)"

 

New article Universal Expert Advisor: Trading Modes of Strategies (Part 1) has been published:

Any Expert Advisor developer, regardless of programming skills, is daily confronted with the same trading tasks and algorithmic problems, which should be solved to organize a reliable trading process. The article describes the possibilities of the CStrategy trading engine that can undertake the solution of these tasks and provide a user with convenient mechanism for describing a custom trading idea.

Various tasks may arise while implementing automated trading algorithms, including analysis of the market environment to interpret market entry signals, and closing of an existing position. Another possible task is control over Expert Advisor operations and proper handling of trading errors. Finally, it is a task of easy and convenient access to market data and trading positions of the Expert Advisor. All these tasks are implemented directly in the Expert Advisor source code.

On the other hand, we should separate the technical part of the trading process and the idea implemented in the custom Expert Advisors. With the object-oriented approach, we can separate these two essentially different trading tasks and entrust implementation of the trading process to a special class common to all the strategies, which is sometimes also referred to as the trading engine.

This is the first article in the series of articles describing the operation of such engine, which can be called a Universal Expert Advisor. This name unifies a set of classes that enable easy development of trading algorithms by a usual enumeration of position entry and exit conditions. You will not need to add required data and trading logics to the Expert Advisor, e.g. position search — all the required procedures are done by the trading engine.

Trading Modes of a Strategy

Very often, trading actions of an Expert Advisor need to be limited. The simplest example is to prevent the EA from performing short or long deals. MetaTrader 4 provides a standard switch of these modes. It is located directly on a tab of the EA properties window that appears at EA launch:

Fig. 2. Trading modes in MetaTrader 4

However, even more modes are possible. Furthermore, we may need more flexible tools for configuring these modes. For example, some EAs need a pause in trading in certain moments of time. Suppose that during the Pacific session of the Forex market, the EA should ignore new position entry signals. This approach is a classic way to restrict EA trading during low volatility periods. What is the best way to implement this mode, additionally making it optional? This can be done through the four-block arrangement of trading logic.

Author: Vasiliy Sokolov

 

Hello,

The source code of the article does not compile.
The error returned is:

cannot cast 'DoubleValue' to 'ULongValue' Dictionary.mqh 210 14

     lValue=(ULongValue)dValue;


Thanks for your help,
Pierre8r

 
Pierre Rougier:

Hello,

The source code of the article does not compile.
The error returned is:

cannot cast 'DoubleValue' to 'ULongValue' Dictionary.mqh 210 14


Thanks for your help,
Pierre8r

I found how to compile the program.
Change the Dictionary.mqh file of this article by the Dictionary.mqh file of this article 
https://www.mql5.com/en/articles/2653

Universal Expert Advisor: CUnIndicator and Use of Pending Orders (Part 9)
Universal Expert Advisor: CUnIndicator and Use of Pending Orders (Part 9)
  • 2017.10.20
  • Vasiliy Sokolov
  • www.mql5.com
Table of Contents Introduction The development of the Universal Expert Advisor's base of source code continues. Most of the approaches integrated into the CStrategy trade engine have proven their efficiency, convenience and simplicity in practice. However, over the course of actual usage, certain aspects in the expert operation had to be...
 
Surely it would make more sense to only update the effected elements in m_state so that the order of calling SetTradeState did not matter? Also, if this were implemented as part of strategy instead of or as well as engine, then different states could be assigned for different assets (eg particular forex pairs during relevent news releases)