Discussion of article "Order Strategies. Multi-Purpose Expert Advisor"

 

New article Order Strategies. Multi-Purpose Expert Advisor is published:

This article centers around strategies that actively use pending orders, a metalanguage that can be created to formally describe such strategies and the use of a multi-purpose Expert Advisor whose operation is based on those descriptions

Order Strategies. Multi-Purpose Expert Advisor

In addition, strategies may require another type of analysis. We will call it analysis of the current trading situation. It comprises analysis of the trading position status and analysis of any available/missing pending orders (if any are used in a strategy). The results of such analysis bring us to decisions of whether certain actions with positions or orders need to be performed, e.g. closing, moving Stop Loss, placing or deleting pending orders, etc. In other words, such analysis includes the study of our market activity, actions according to the situation we (or an Expert Advisor) created and the rules of the strategy in use.

A commonly known Trailing Stop can to a certain extent be considered the second type of elements in a trading strategy. Consider the following analysis: if there is an open position with the profit higher than the set value, while the Stop Loss is not set or is further than the distance from the current price as specified in the settings, the Stop Loss will be moved.

Trailing Stop is a fairly simple function to be of particular interest. Besides, it can be classified as a totally different category of trading strategy elements, being a position management function. Thus, a trading strategy can be comprised of three categories of elements:

  1. Market analysis and actions based thereon.

  2. Analysis of the trading situation and actions based thereon.

  3. Position management.

This article centers around strategies that actively use pending orders (we will call them order strategies for short), a metalanguage that can be created to describe such strategies and the development and use of a multi-purpose tool (Expert Advisor) whose operation is based on those descriptions.

Author: Дмитрий

 

Dmitry, what is this? Why is the article in the form of a reference book and tables of macros?
and where are the code samples, where is the essence of the programmer's idea?
The chapters explaining the principle and identification - unfortunately did not shed any light on what is going on.
such an impression that they wrote it for themselves not to forget the list of possible macros.

can you explain for everyone the purpose of what is happening in the code? (I am not interested in the application, but only in the organisation of MQL algorithms).

 
I support, I need an example of how to programme a simple TS, at least trading on the crossovers of slow and fast MAs.
 
The article is apparently not for average minds. ;-) The goal is commendable - to save the user from the need to understand what is going on in the MQL code and to get away from programming routine. There seem to be enough examples of TCs (in the meta-language), but the meta-language itself may take time to master. Maybe in time it will be possible to simplify it or to increase it with a visual strategy designer, then there will be less dissatisfied people or they will start complaining that the buttons are placed in the wrong place. ;-)
 

Ahem...
It looks like an article "from a programmer for programmers". Only it is not clear who (except the author) will use it. "Learn mql5" vs "Learn eIntepretar".

But the work done is just colossal, it is admirable.

 
sergeev:

Dmitry, what is this? Why is the article in the form of a reference book and tables of macros?
and where are the code samples, where is the essence of the programmer's idea?
The chapters explaining the principle and identification - unfortunately did not shed any light on what is going on.
such an impression that they wrote it for themselves not to forget the list of possible macros.

can you explain for everyone the purpose of what is happening in the code? (I'm not interested in the application, but only in the organisation of MQL algorithms).

There are 3 or 4 reference tables. The rest are macros with comments. The article is very informationally rich, you should read it without skipping a single word, do not go to the next, if there is even one unclear thought (of course, if necessary and if you want). A single reading probably won't help. If you try to single out the central idea, it is not so big and complicated: any strategy on orders should be decomposed into all possible phases of states, but this is a personal creative process, not formalised. Although, if you wish, you can formalise it, but it will be a lot of writing.

Programmer's idea... it is as old as the computer itself: a programme in human language, by which an iron machine works.

Code examples. StringFind() and StringSubstr() functions. In general, it can be useful to study string functions in PHP - it can really expand your creativity...

If you try to put the whole amount of information presented in the article in some other way, it could be 5-10 times more voluminous...

What happens in the code... Read the file line by line, separate comments by the "#" sign, split into phase and action fields by the "|" sign, split commands by the ";" sign. Then we look for substrings <, >, <=, <=, etc. in comparison expressions. If we find one, we note its index, and the expression is divided into left and right parts by it. The arithmetic expression remains. If it starts with + or -, we indent one character and look for + or - before which there is no * sign. We split + or - into substrings, and split these two substrings by the * sign. After that we have four arguments (and one more on the left side of the expression). These arguments can be commands. We check if it is a number, or a number with p at the end, or a user variable or a user variable with p at the end, if so, we replace it with a number. If not, it is a command. We separate the command itself and its arguments by the sign (.

The most interesting thing is the calculation of expressions. There are structures, five structures with values in each structure, the value structure specifies whether the value is directly numeric or a command. For each structure with a value, a function is called to calculate the value. If the value is numeric, the function does nothing, if it is a command, the appropriate function is called (selected via switch). After the values are filled in, the arithmetic expression is calculated, there in the structure the signs for the values and the arithmetic action are specified.... Only everything is specified by numbers (indices), and the necessary action is selected through switch.

The very process of working interpretation is two levels of switch: a command and nested for the identifier of the data received about the command. If you are interested, dig into the code from the OnTick() function, there is not a lot of code from it. The largest amount of code comes from OnInit() function, but it's not so interesting there, it can be done as it is more convenient for someone - only StringFind() and StrSubstr() functions.


Документация по MQL5: Строковые функции / StringFind
Документация по MQL5: Строковые функции / StringFind
  • www.mql5.com
Строковые функции / StringFind - Документация по MQL5
 
IgorM:
I support, I need an example of how to programme a simple TS, at least trading on crossings of slow and fast MAs


Khe... First you should read the article in full.

 
marketeer:
...to be a visual designer of strategies.....

That's a good idea, that would take away one problem... but a minor one, you'd still have to think about the strategy, analyse it, break it down into phases.

 
komposter:

Ahem...
It looks like an article "from a programmer for programmers". Only it is not clear who (except the author) will use it. "Learn mql5" vs "Learn eIntepretar".

And the work done is simply colossal, it is admirable.

Well, there is a little bit, ala "Crazy scientist"..... As a consolation prize, there is a description of several order strategies, though not very detailed, but with pictures.... Someone, maybe, at least this will be useful...

 

Если постараться изложить весь объем информации представленный в статье как-то иначе, она бы могла поучиться раз в 5-10 объемней...

You could put the reference tables in a dock and just attach them to the article.


I have re-read the article again. I even decided to make a thesis statement for myself in order to understand what the article is about. I am probably close to understanding.

Dimitri, correct me if I'm wrong.


So, the expert's job will be to check the states. All of them. Point by point.
And if any of the states is relevant at the moment - then we do what the macro prescribes for this state.
The task is not to create contradictions - to make several macros handle the same state, or to avoid conflicts between two macros (for example, one closes and the second immediately opens, and there will be a "fight")

That is, the task of the expert is to constantly run in a loop and check ALL the specified macros (what we wrote in the file or something else) and do what they prescribe when they fulfil their condition.


For example, let's say we have a simple strategy (even an indicator strategy).
We need to open an order when MA crosses. Then spend it. And close it forcibly at some prefix.

What a programmer does in this case.

He writes THREE functions (like macros in your case)
- the function of checking the indicator and opening an order, if the indicator has given the OK and there is no pose.
- the function of trawl, if there is a pose
- the function of closing, if there is an order and there is a profit

The order of calling these functions can be any. It is enough to place them on the check in OnTick for example

OnTick()
{
OpenOrder()
TralPos()
CloseProfit()
}

That is, the functions are independent by themselves.
It means that TralPos is independent by itself and the presence of other two functions does not affect its work in any way. All necessary checks are performed in it (searching for a pose, modifying a stop, etc.)
Similarly, CloseProfit is independent.


So you have written several dozens of such functions, which are independent and perform atomic operation of the algorithm.
And you made a way to set them through a test file with parameters, so that you could change parameters of functions (and thus of the Expert Advisor) without recompiling it.



like this?

 
sergeev:

It would be possible to put the reference tables in a doc and just attach them to the article

It's a matter of taste, but if they're inside the article, they won't get lost.


I have reread the article again. I even decided to make a thesis statement for myself to understand what the article is about, and I'm probably close to understanding it.

Dimitri, correct me if I'm wrong.


So, the expert's job will be to check the states. All of them. Point by point.

Yes. On each tick, all phases are checked for relevance.


And if any of the states is relevant at the moment - then we do what the macro prescribes for this state.

Yes. But there are some nuances. If a market action is performed, it must be one and it must come first. If a pending order is set, the Expert Advisor checks its existence before setting it.

The task is not to create contradictions - several macros should process the same state, or two macros should not conflict (for example, one closes and the second immediately opens, and there will be a "fight").

There should be no conflict. But there can be several macros for the same phase, if it is more convenient. For example, a phase is the presence of a market position, in one side there can be a Limit order and in the other a Stop order, or you can write both a Stop and a Limit order in one line.

That is, the task of the Expert Advisor is to constantly run through the loop and check
ALL the specified macros (that we have written in the file or something else) and do what they prescribe when their condition is fulfilled.

Yes.


For example, let's say we have a simple strategy (even an indicator strategy).
We need to open an order when MA crosses. Then spend it. And then close it forcibly at some prefix.

Yes.

What a programmer does in this case.

He writes THREE functions (like macros in your case)
- the function of checking the indicator and opening an order if the indicator has given a signal and there are no positions.

This is one phase: there is an indicator signal, but no position. In this case, its action is to open a position.

- function of trawl, if there is a pose.

This can be recorded as a separate phase. Phase identification - presence of a market position. The corresponding action is the call of the trawl function.


- closing function, if there is an order and the order has a profit.

This is the third phase. There is a position and its profit is greater than the specified value. The action is to close the position.


The order of calling these functions can be any. It is enough to place them on the check in OnTick, for example.

And in the file with the metaprogram you can place the lines in different order.



OnTick()
{
OpenOrder()
TralPos()
CloseProfit()
}

That is, the functions themselves are independent.

It turns out that the lines in the file with the metaprogram are independent as well.


It means that TralPos is independent by itself and the presence of other two functions does not affect its work. All necessary checks are performed in it (pose search, stop modification, etc.).

One line of the metaprogram is also self-sufficient.


Similarly, CloseProfit is self-sufficient.


So you have written several dozens of such functions that are independent and perform atomic operation of the algorithm.
And you have made a way to set them through a test file with parameters, so that you could change the parameters of functions (and thus the Expert Advisor) without recompiling it.

These functions can be combined. Phase can be determined not only by the presence of a market position... but many variants, commands in the table of access commands.

like this?

One thing that may cause misunderstanding. I have somehow blurred the difference between action and state in the article. If a market action should be taken when identifying a phase, it should be called an action. And when it is necessary to set pending orders, it is more likely to be called a state description. A phase is mainly identified by a comment in a market position, and this phase corresponds to either an action (opening/closing a market position) or a state (presence of some pending orders). If it is a market action, it is assumed that after its execution there will be a transition to another phase. It is important to mark orders correctly. But in one phase there can be both a market action and setting of orders. If the market action is unsuccessful, everything after it will not be executed. And if it is successful, it will be executed, in case you try to do as much as possible on one tick. It should be borne in mind that orders may not be set, but the market action is completed, i.e. there is a transition to another phase.