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"
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?
- www.mql5.com
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
Please edit your post and
use the code button (Alt+S) when pasting code
There may be more than one lost order
OK, but the function is still returning just one of the lost orders, that which is closest to zero.
In this case, wouldn’t be the same iterating from 0 to start-1 with a break?
ulong CHistoryCollection::OrderSearch(const int start,ENUM_ORDER_TYPE &order_type) { ulong order_ticket=0; for(int i=0; i < start ;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; }
I know that it is just a detail, but I thought this could be a little improvement, especially in case of a too big history of orders.
- www.mql5.com
OK, but the function is still returning just one of the lost orders, that which is closest to zero.
In this case, wouldn’t be the same iterating from 0 to start-1 with a break?
I know that it is just a detail, but I thought this could be a little improvement, especially in case of a too big history of orders.
Ok, thanks, I'll check and test everything.
It may well be that "break" will come in handy.
- 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 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:
Author: Artyom Trishkin