Logical, interesting...but I gave up unnecessary features in Expert Advisors (schedules, news and other external stuff) a long time ago.
There is a more beautiful solution - it is more convenient to set the mode of the Expert Advisor through terminal variables. Several names of variables are given in the parameters of the Expert Advisor, and it uses their values to orientate itself.
Logical, interesting...but I gave up unnecessary features in Expert Advisors (schedules, news and other external stuff) a long time ago.
There is a more beautiful solution - it is more convenient to set the mode of the Expert Advisor through terminal variables. Several names of variables are given in the parameters of the Expert Advisor, and it uses their values to orientate itself.
The idea is to hide these tricks inside auxiliary modules. The user makes a formal description of the TS, and the trading engine does everything else for him.
By the way, "trading modes" are only a consequence of the proposed organisation of the EA logic. If you describe the trading logic of an EA with four actions, the trading modes will appear by themselves. If you learn how to write a TS using these four actions, the speed of writing an Expert Advisor increases several times and the number of errors tends to zero - it has been tested many times.
The idea is to hide these tricks inside auxiliary modules. The user makes a formal description of the TS, and the trading engine does the rest for him.
By the way, "trading modes" are only a consequence of the proposed organisation of the EA logic. If you describe the trading logic of an EA using four actions, trading modes will appear by themselves. If you learn how to write a TS with the help of these four actions, the speed of EA writing increases several times and the number of errors tends to zero - it has been tested many times.
It is undeniable that trade modes appear. But it is better to set these modes from the outside, by external means. In this way, the EA "leaves" unnecessary code, no matter how you look at it, and it eats resources (computational, development, support, etc.). But instead of an EA you get a kind of "shopping mall", where you can control several owls from one remote control.
Well, in general, they are set from the outside. You can, for example, create a visual form of trading modes. It can be done even on Win32. It is also possible to place trade modes as parameters. The engine itself does not possess any trading modes. And thanks to this, what you write about is achieved: independence of the strategy from add-ons and extensions - you can use them or not, they are simply written and described, and can be used if necessary.
It is undeniable that trade modes appear. But it is better to set these modes from the outside, by external means. In this way, the EA "leaves" unnecessary code, no matter how you look at it, and it eats resources (computational, development, support, etc.). But instead of an EA you get a kind of "trading complex", where you can control several owls from one remote control.
What makes you think it is better? Your approach is disgusting! Tell me more about how realistic you are and that you don't use a tester.
You get a lot of functions that determine the result of the EA's work, but cannot be checked in the tester.
Everything that changes the EA's work should be regulated through the EA properties window.
Great article, where's the follow up? Hurry up and translate it!
Just started to understand it. I would like a description of XML strategy - what is there where. And at least some XML file. IMHO, it is missing in the archive.
Thank you.
Just started to understand it. I would like a description of XML strategy - what is there where. And at least some XML file. IMHO, it is missing in the archive.
Thank you.
Example of XML-serialisation of strategies:
<Global> <Strategies> <Strategy Name="MovingAverage" Magic="100" Timeframe="PERIOD_M1" Symbol="Si"> <TradeStateStart> Stop</TradeStateStart> <Params> <FastMA> 1</FastMA> <SlowMA> 3</SlowMA> <Shift> 0</Shift> <Method> MODE_SMA</Method> <AppliedPrice> PRICE_CLOSE</AppliedPrice> </Params> </Strategy> <Strategy Name="MovingAverage" Magic="101" Timeframe="PERIOD_M5" Symbol="SBRF"> <TradeStateStart> BuyOnly</TradeStateStart> <Params> <FastMA> 15</FastMA> <SlowMA> 21</SlowMA> <Shift> 0</Shift> <Method> MODE_SMA</Method> <AppliedPrice> PRICE_CLOSE</AppliedPrice> </Params> </Strategy> <Strategy Name="BollingerBands" Magic="102" Timeframe="PERIOD_M15" Symbol="GAZR"> <TradeStateStart> BuyAndSell</TradeStateStart> <Params> <Period> 30</Period> <StdDev> 1.5</StdDev> </Params> </Strategy> <Strategy Name="BollingerBands" Magic="103" Timeframe="PERIOD_M30" Symbol="ED"> <TradeStateStart> BuyAndSell</TradeStateStart> <Params> <Period> 20</Period> <StdDev> 2.0</StdDev> </Params> </Strategy> </Strategies> </Global>
The issue of strategy serialisation is dealt with in the following parts. This example is present there.
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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