Discussion of article "Library for easy and quick development of MetaTrader programs (part XXIV): Base trading class - auto correction of invalid parameters" - page 3

 
hsyhsy863 :
Hello, did you find the problem I mentioned?
I do not consider ex-files.
 

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;
   //...
   //...
  }


 
Dima Diall :

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.

 
Artyom Trishkin:

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.

 
Could you please give me a code example to pull the order/position ticket and other properties after getting the last trade event?
 
leonerd:
Could you please provide some sample code so that when you get the last trade event, you can pull the order/position ticket and other properties?
Not until a week from now - not on site.