Discussion of article "Library for easy and quick development of MetaTrader programs (part V): Classes and collection of trading events, sending events to the program"

 

New article Library for easy and quick development of MetaTrader programs (part V): Classes and collection of trading events, sending events to the program has been published:

In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the fourth part, we tested tracking trading events on the account. In this article, we will develop trading event classes and place them to the event collections. From there, they will be sent to the base object of the Engine library and the control program chart.

Now we can compile the EA and launch it in the tester. When clicking the buttons, short two-line messages about occurring account events are displayed in the tester journal.


Entries from the EA event handler are not displayed in the journal since they work outside of the tester. If click on the EA buttons on a demo account, three lines are displayed in the terminal journal: two lines from the method for displaying short messages of the CEvent class and another one — from the EA's OnChartEvent() handler.

Below is a sample of displaying a message in the journal when placing and removing a pending order:

- Pending order placed: 2019.04.05 23:19:55.248 -                                                              
EURUSD 0.10 Sell Limit #375419507 at price 1.14562                                                             
OnChartEvent: id=1001, event=TRADE_EVENT_PENDING_ORDER_PLASED, lparam=375419507, dparam=1.14562, sparam=EURUSD 
- Pending order removed: 2019.04.05 23:19:55.248 -                                                             
EURUSD 0.10 Sell Limit #375419507 at price 1.14562                                                             
OnChartEvent: id=1002, event=TRADE_EVENT_PENDING_ORDER_REMOVED, lparam=375419507, dparam=1.14562, sparam=EURUSD

Author: Artyom Trishkin

Library for easy and quick development of MetaTrader programs (part V): Classes and collection of trading events, sending events to the program
Library for easy and quick development of MetaTrader programs (part V): Classes and collection of trading events, sending events to the program
  • www.mql5.com
In the previous articles, we started creating a large cross-platform library simplifying the development of programs for MetaTrader 5 and MetaTrader 4 platforms. In the fourth part, we tested tracking trading events on the account. In this article, we will develop trading event classes and place them to the event collections. From there, they...
 
I wonder how the library handles a lot of trading nuances. So it's probably worth trying to get at least the initial test done

Forum on trading, automated trading systems and testing trading strategies.

Less code, more rolling... writing an EA

fxsaber, 2019.03.12 21:46

This task can well be considered an initial test on the ability to write trading under MT5. So everyone can try their hand at it.

 
fxsaber:
I wonder how the library handles a lot of trading nuances. So it's probably worth trying to pass at least the initial test

There are no trading classes in the library yet. At the moment the work with account history and active market state is coming to an end - tracking of netting account events will be published in the next article, then work with the account in MetaTrader 4, and then, after preparing classes for message output, work with trading classes will be described.

 
Artyom Trishkin:

There are no trading classes in the library yet. At the moment the work with account history and active market state is coming to an end - tracking of netting account events will be published in the next article, then work with the account in MetaTrader 4, and then, after preparing classes for message output, work with trading classes will be described.

Got it. MT5 is so complex in this respect that I think we need a whole article that would describe in detail the trading subtleties arising on MT5 and how to take them into account.

 
Artyom Trishkin: tracking netting account events will be published in the next article, then the
the library will automatically detect and work with both netting account and hedge account types?
 
fxsaber:

Roger. MT5 is so complex in this respect that it probably needs a whole article describing in detail the trading subtleties that arise on MT5 and how to take them into account.

I am busy dealing with such situations. I hope I will be able to handle them all correctly.

Something else is interesting - on the basis of the described library user-case functions will be created for easy access to the data collected and stored in the library, for using trading classes, and accordingly - for simple and easy creation of programmes based on it.
Though already as it is - there is a possibility to use it, but at a lower level of access - by pointers to lists of collections, and from them - by pointers to any of their data. But this does not correspond to the "claims" stated at the very beginning about the ease of creating one's own programmes on the basis of the library. But this is just the beginning :)

 
Igor Makanu:
library will automatically detect and work with both netting account and hedge type of accounts?

Yes. Already done. It will be published in the next article.

 
Artyom Trishkin:

Yes. Already. The next article will be published.

But for now only work with account history and market state. Then it will be possible to get the history of any position on any account type on the basis of collected data. I will include it in my plans.
 

Very powerful as a testing tool, thanks for sharing!

 

Hello Artyom, congratulations for the great job! Following the description in the text, it seems that function CHistoryCollection::OrderSearch(…) may have a break missing.

The for loop always complete all iterations from start-1 to 0, whether it finds the “lost order” or not.

Perhaps, it would be more efficient to include a break after finding the “lost order”:

 

ulong CHistoryCollection::OrderSearch(const int start,ENUM_ORDER_TYPE &order_type) 
  { 
   ulong order_ticket=0; 
   for(int i=start-1;i>=0;i--) 
     { 
      ulong ticket=::HistoryOrderGetTicket(i); 
      if(ticket==0) 
         continue; 
      ENUM_ORDER_TYPE type=(ENUM_ORDER_TYPE)::HistoryOrderGetInteger(ticket,ORDER_TYPE); 
      if(this.IsPresentOrderInList(ticket,type)) 
         continue; 
      order_ticket=ticket; 
      order_type=type; 
      break; 
     } 
   return order_ticket; 
  } 

 

What do you think?

 

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The identifier of...
 
Alvaro Arioni :

Hello Artyom, congratulations for the great job! Following the description in the text, it seems that function CHistoryCollection::OrderSearch(…) may have a break missing.

The for loop always complete all iterations from start-1 to 0 , whether it finds the “lost order” or not.

Perhaps, it would be more efficient to include a break after finding the “lost order”:

 

...

 

What do you think?

 

There may be more than one lost order