New article Universal Expert Advisor: Trading Modes of Strategies (Part 1) has been published at mql5.com:
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.
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
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