Events Queue size management

Erwann Pannerec  

Hi community,

For somes EA which are a bit complicated, multi timeframe & multi currency, sometimes the queue of events which are pending to process (Onchartevent, etc...) could increase and maybe overflow.

Is there any solutions to acess to this queue ?

That could help to improve stability of programm by making a kind of adaptation of calculations process depending the events queue size/type.

Indeed, my programs are already optimized for best performances...

Thanks !

Erwann.

Erwann Pannerec  

Hi !

I'm wonder if a solution about this problem exist... someone has an idea ?

Thanks :)

William Roeder  
Erwann Pannerec: sometimes the queue of events which are pending to process (Onchartevent, etc...) could increase and maybe overflow.

Is there any solutions to acess to this queue ?

There is no solution for your non-problem. The queue will not increase and maybe overflow.

The documentation plainly states that if an event is already in the queue, another is not added. That is why ticks will be ignored, if OnTick is still running.

Erwann Pannerec  

Okay,

Thank you for your reply very clear.

Regards,

Erwann.

Alain Verleyen  
Erwann Pannerec:

Hi !

I'm wonder if a solution about this problem exist... someone has an idea ?

Thanks :)

Your problem is not clear. You can't access the queue, but why would you need to do it ? What is the real problem ?
nicholish en  
Alain Verleyen:
Your problem is not clear. You can't access the queue, but why would you need to do it ? What is the real problem ?

What Erwann is talking about is the <behind the scenes> event queue, which is FIFO instead of priority-queue. The problem Erwann is having is that long running tasks will cause the event queue to fill up with events which the EA has to process, however, since the completion of his long running tasks the events in the queue are no longer relevant and he would like to know if there is a way to manage the queue itself. 

Erwann, it helps to post a MCVE. In the following example, if you click the mouse to fill up the event queue - it will block event handling and cause the ticks (which should be priority in my opinion) to get back logged in the queue. 

int OnInit() {
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
   Print("tick");
}
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam) {
   if (id == CHARTEVENT_CLICK) {
      Print("Clicked mouse -> Simulating long running task");
      Sleep(1000);
   }
}
//+------------------------------------------------------------------+
Alain Verleyen  
William Roeder:

There is no solution for your non-problem. The queue will not increase and maybe overflow.

The documentation plainly states that if an event is already in the queue, another is not added. That is why ticks will be ignored, if OnTick is still running.

The documentation is wrong.

Similarly, if the ChartEvent is already in an mql5 program queue or such an event is being handled, then a new event of this type is not placed into a queue.

I can assure you that events are queued even if an other one of the same type is already running or queued, at least for ChartEvent. Try it.

Documentation on MQL5: MQL5 programs / Client Terminal Events
Documentation on MQL5: MQL5 programs / Client Terminal Events
  • www.mql5.com
Immediately after the client terminal loads a program (an Expert Advisor or custom indicator) and starts the process of initialization of global variables, the Init event will be sent, which will be processed by OnInit() event handler, if there is such. This event is also generated after a financial instrument and/or chart timeframe is changed...
Christian Berrigan  

I'm having a similar problem with events related to implementation of a CAppDialog.


When the EA implementation of the dialog first starts on a chart, it is susceptible to freezing up.  After it has been on the chart awhile it seems to be stable.

I have created a 500ms timer to log events.  When the panel is working, the log prints like clockwork.  However, if I abuse the panel with mouseclicks I can force the problem to happen (but it does happen 1 of xx times when starting the EA without abusing it).  When it happens, the timer prints once every 5-10 seconds or longer, indicating processing is totally hosed, some code that traps for "unhandled chart events" fires and prints to the log, and it continues to run like a snail.

Changing timeframes often fixes it.  Dropping a script that executes ChartSetSymbolPeriod(0,NULL,0); as a fake tick often fixes it.  However, when the panel freezes up, the actual currency chart stops getting ticks and basically this situation is intolerable.  And its not getting normal ticks, so I can't expect an incoming tick to fix it.

There are no stuck loops.  This is a chart-event driven process.   If one waits long enough (a very long time) it eventually fixes itself.

Once it is stable, the EA can sit on a chart for hours without seizing up.

I've even been able to detect the problem by comparing TimeCurrent() in the timer to the prior CurrentTime() of the last timer event, and if it is more than 2 seconds, I can detect the problem.  But interestingly, putting a ChartSetSymbolPeriod(0,NULL,0); when detected does not solve the problem even though dropping a script with that command on the chart does seem to resolve it.

If I could conceive of a fix in the timer itself, it would only take a few seconds to re-orient itself back into reality.  However that is pretty weird, and it would be better to understand the underlying problem and deal with it direclty.

Any thoughts on this would be GREATLY appreciated!!

Reason: