Discussion of article "Library for easy and quick development of MetaTrader programs (part XXIV): Base trading class - auto correction of invalid parameters"
Hi Artyom -- in working closer with this code, I noticed this peculiarity of the 'shift' value implemented in EventsHandling() and OnDoEasyEvent() for correctly handling trade events when running in the tester... I understand, as you point out in the article, when running live trade events are delivered one by one from OnChartEvent() as they are triggered by the engine, whereas in testing mode they are grouped together and delivered as a list...
My question is: wouldn't it be better to implement a dedicated function parameter in the event-handler rather than sacrificing 'lparam' which can contain useful information for the event-handler? I also think it makes the code simpler / more readable; do you agree?
PS: Anyway, I am finding this library to be really powerful but also complex and difficult to wrap one's head around, however once mastered it should enable developing all sorts of EA-powered strategies very quickly... Beside the huge learning curve, I am also noticing the back-testing performance to be rather slow, so I hope you can address this point once you complete the feature-set you envisioned for DoEasy.
void EventsHandling(void) { //--- If a trading event is present if(engine.IsTradeEvent()) { //--- Number of trading events occurred simultaneously int total = engine.GetTradeEventsTotal(); for (int i = 0; i < total; i++) { //--- Get the next event from the list of simultaneously occurred events by index CEventBaseObj *event = engine.GetTradeEventByIndex(i); if(event == NULL) continue; int shift = i; long lparam = event.LParam(); double dparam = event.DParam(); string sparam = event.SParam(); OnDoEasyEvent(CHARTEVENT_CUSTOM+event.ID(), lparam, dparam, sparam, shift); } } //... //... } void OnDoEasyEvent(const int id, const long &lparam, const double &dparam, const string &sparam, int shift=0) { //... //... //--- Handling trading events if(idx > TRADE_EVENT_NO_EVENT && idx < TRADE_EVENTS_NEXT_CODE) { //--- Get the list of trading events CArrayObj *list = engine.GetListAllOrdersEvents(); if(list == NULL) return; //--- get the event index shift relative to the end of the list //--- in the tester, the shift is passed by the lparam parameter to the event handler //--- outside the tester, events are sent one by one and handled in OnChartEvent() int shift=(testing ? (int)lparam : 0); CEvent *event=list.At(list.Total()-1-shift); if(event==NULL) return; //... //... }
Hi Artyom -- in working closer with this code, I noticed this peculiarity of the ' shift ' value implemented in EventsHandling() and OnDoEasyEvent() for correctly handling trade events when running in the tester... I understand, as you point out in the article, when running live trade events are delivered one by one from OnChartEvent() as they are triggered by the engine, whereas in testing mode they are grouped together and delivered as a list...
My question is: wouldn't it be better to implement a dedicated function parameter in the event-handler rather than sacrificing ' lparam ' which can contain useful information for the event-handler? I also think it makes the code simpler / more readable; do you agree?
PS: Anyway, I am finding this library to be really powerful but also complex and difficult to wrap one's head around, however once mastered it should enable developing all sorts of EA-powered strategies very quickly... Beside the huge learning curve, I am also noticing the back-testing performance to be rather slow, so I hope you can address this point once you complete the feature-set you envisioned for DoEasy.
No. Here I did not plan to redo anything, and most likely I will not. All the necessary data is already delivered to event objects, and the rest of the data is already taken from those objects whose event was registered.
No. Here I did not plan to redo anything, and most likely I will not. All the necessary data is already delivered to event objects, and the rest of the data is already taken from those objects whose event was registered.
OK, fair enough... I agree that all necessary data is in the event objects.
- 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 XXIV): Base trading class - auto correction of invalid parameters has been published:
In this article, we will have a look at the handler of invalid trading order parameters and improve the trading event class. Now all trading events (both single ones and the ones occurred simultaneously within one tick) will be defined in programs correctly.
Generally, the EA should be able to act according to the circumstances while following the user-defined logic of handling errors in trading orders. Thus, we may give the following instructions to the EA when a trading order error is detected:
Handling errors in trading order parameters may lead to one of several outcomes:
In this article, we are going to develop the trading order error handler that will check errors and their sources, as well as return the error handling method:
Author: Artyom Trishkin