New article Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal API, Part 2 has been published:
This article is a continuation of the first part "Bi-Directional Trading and Hedging of Positions in MetaTrader 5 Using the HedgeTerminal Panel, Part 1".
In the second part, we will discuss integration of Expert Advisors and
other MQL5 programs with the HedgeTerminalAPI library. Read this article
to learn how to work with the library. It will help you create
bi-directional trading Expert Advisors while still working in a
comfortable and simple trading environment.
In addition to the library description, the article touches on the
fundamentals of asynchronous trading and multi-threaded programming.
These descriptions are given in the third and fourth sections of this
article. Therefore, this material will be useful for the traders who are
not interested in bi-directional trading, but who would like to find
out something new about asynchronous and multi-threaded programming.
The material presented below is intended for experienced algorithmic
traders who know the MQL5 programming language. If you don't know MQL5,
please read the first part of the article, which contains simple
diagrams and drawings explaining the general principle of the library
and the HedgeTerminal panel.
1.12. The SendTradeRequest() Function and the HedgeTradeRequest Structure through the Example of Chaos II EA
As an example, let's develop a trading robot based on the trading tactics proposed by Bill Williams in his book Trading Chaos. Second Edition.
We will not follow all his recommendations, but simplify the scheme by omitting the Alligator
indicator and some other conditions. The choice of this strategy stems
from several considerations. The main one is that this strategy includes
composite position maintenance tactics. Sometimes you need to close a
part of a position and move the stop loss to breakeven.
When moved to breakeven, the stop level should be trailed following
the price. The second consideration is that this tactic is known enough
and indicators developed for it are included in the standard MetaTrader 5
delivery pack. Let's slightly modify and simplify the rules, to prevent
the complex logic of the Expert Advisor from hindering its primary
objectives: to show an example of EA interaction with the
HedgeTerminalAPI library. The EA's logic uses most of trading functions
of HedgeTerminalAPI. This is a good test for the library.
The following chart illustrates this strategy:
Fig. 4. The representation of bi-directional positions of the Chaos 2 EA on the price chart
Author: Vasiliy Sokolov