Discussion of article "MQL5 Cookbook - Multi-Currency Expert Advisor and Working with Pending Orders in MQL5"

 

New article MQL5 Cookbook - Multi-Currency Expert Advisor and Working with Pending Orders in MQL5 has been published:

This time we are going to create a multi-currency Expert Advisor with a trading algorithm based on work with the pending orders Buy Stop and Sell Stop. The pattern we are going to create will be designed for the intra-day trade/tests. The article considers the following matters:

  • Trading in a specified time range. Let's create a feature that will allow us to set up the time of the beginning and the end of trading. For instance, it can be the time of the European or American trading sessions. For sure there will be an opportunity to find the most suitable time range when optimizing parameters of the Expert Advisor.
  • Placing/modifying/deleting pending orders.
  • Processing of trade events: checking if the last position was closed at Take Profit or Stop Loss and control over the history of the deals for each symbol.

MQL5 Cookbook - Multi-Currency Expert Advisor and Working with Pending Orders in MQL5

Author: Anatoli Kazharski

 

Time.

Hours are not always enough, minutes are also necessary. For example, if the market opens and closes at fractional times.

And this function raises questions - you need to trade through midnight much more often than you need minutes

bool IsInTradeTimeRange(int symbol_number)
  {
//--- If time range trading is enabled
   if(TradeInTimeRange[symbol_number])
     {
      //--- Date and time structure
      MqlDateTime last_date;
      //--- Get the latest date and time data
      TimeTradeServer(last_date);
      //--- Outside the authorised time range
      if(last_date.hour<StartTrade[symbol_number] ||
         last_date.hour>=EndTrade[symbol_number])
         return(false);
     }
//--- In the permitted time range
   return(true);
  }
 
TheXpert:

Time.

Hours are not always enough, minutes are also necessary. For example, if the market opens and closes at fractional times.

And this function raises questions - you need to trade through midnight much more often than minutes.

Yes, I agree. I'll try to visualise it later, in some new scheme.

Then perhaps instead of enumerations we should make a line where the user specifies the time himself. For example:"9: 35". Otherwise the list of parameters is extended by three more parameters (in the article scheme) for specifying minutes.

It would be great if there was a convenient standard possibility to specify the time. Now we have datetime, we need to make time. )

 

In fact, it's all program code, IMHO it's not suitable as an article, rather it's for the Code Base section.

 
revers45:

In fact, it's all program code, IMHO it doesn't work as an article, rather it's for the Code Base section.

Oh, well. Good work then. Write and post everything in Code Base. ;)
 
revers45:

In fact, it's all program code, IMHO it doesn't work as an article, rather it's for the Code Base section.

Such articles are convenient for learning the language.

It is easier to read both text and code, and to look at illustrations at once, than to scroll through the article separately, and separate codes from different files.

But I agree that some descriptive part is missing. Concept and main points of implementation in the form of plain text.

 
komposter:

Such articles are convenient for learning a language.

It is easier to read both text and code, and to look at illustrations at once, than to scroll through the article separately, and separate codes from different files.


But I agree that some descriptive part is missing. Concept and main points of implementation in the form of plain text.

This series of articles is more for sequential language learning. The scheme was described in one of the previous articles and probably there is no sense to describe everything again. At the beginning of the article there is a link to the article where this scheme was considered in detail. Additional functions were written here and some small changes were made. Everything is simple and nothing superfluous, and every line in the code is commented. I think it's nice to have a lot of different ready-made schemes that you can just pick up and use.

I can't imagine what else could have been added to the article. But that's okay. ))

 
Why so much code for several symbols? Wouldn't it be easier to put one Expert Advisor for each symbol, I think it will make the programme execute faster. In this connection, dear author, could you tell me how to convert these functions for working with pending orders, so that they were only for one symbol, except for the way to put in the variable #define NUMBER_OF_SYMBOLS one?
 
kuva:
Why is there so much code for several symbols?

To be able to test the system in the tester on several symbols at once.

kuva:
Wouldn't it be simpler to put one Expert Advisor on different symbols, in my opinion it will be faster to execute programmes. In this connection, dear author, could you tell me how to convert this code so that it works only on one character, except for the way to put in the variable #define NUMBER_OF_SYMBOLS one?

If you want it to work on one character only, just remove all loops related to character search. From some functions you will then need to remove the first parameter of the character sequence number.

Also, arrays that were initialised with values of external parameters will no longer be needed. In the functions where they were used they will have to be replaced by variables of external parameters.

 
Do forward test on real ticks - the optimisation result will be opposite.
 
It is awfully inconvenient to search for symbols via symbol_number. I used to use this scheme, but now I've switched to OOP. Each symbol = an instance of the class. At runtime, on each OnChartEvent event, you search through the instances of the class in order. It works even a little faster.