Timer - page 2

 
TheXpert:

One more thing... You guys aren't brothers, are you?

Which doesn't mean there isn't one. We all have different tasks.

Here we go... Can we read? Show me how it is done for the induks.


  1. I don't think so, I don't even know who it is :D
  2. Well I honestly haven't encountered such a task, for my tasks - the faster it counts, the better.
  3. I'm sorry, I looked through it)). Not really got into what threads - what's going on. I don't know, I've never seen such a thing. It really depends on the task, unless I execute some weird script that taps the indication.
Or, as another alternative - to shove all calculations and everything in a separate thread into a dll - but that sounds like a perversion.
 

Interesting:

... timer processing cannot be called until the previous timer processing is completed. Or simply put, OnTimer() will not get the right to execute until the thread which should process the timer is busy.

To illustrate the impossibility of starting timer processing by the second thread you can use this example (dumb but clear):

int OnInit()
{
//----------------------------------------------------------------------------//
//Work variables
//----------------------------------------------------------------------------//
EventSetTimer(1);
//----------------------------------------------------------------------------//
return(0);
//----------------------------------------------------------------------------//
}

void OnTimer()
{
//----------------------------------------------------------------------------//
//Work variables
//----------------------------------------------------------------------------//
Print(TimeLocal());
Sleep(2000);
//----------------------------------------------------------------------------//
}
So, it turns out thatTimer events can be ignored as well asNewTick events? And under certain conditions, they cannot be placed in the Expert Advisor's event queue?
 
Yedelkin:
So it turns out thatTimer events can be ignored in the same way asNewTick events? And, under certain conditions, it can be excluded from the Expert Advisor's event queue?
The NewTick event is an exception in this case. There are no checks for other types of events. If event handlers run slower than the event queue fills, the queue will overflow and some events will be skipped. As for the above example, it only confirms that the EA has a single execution thread and that event handling is performed sequentially, in the order that the events are queued.
Документация по MQL5: Программы MQL5 / События клиентского терминала
Документация по MQL5: Программы MQL5 / События клиентского терминала
  • www.mql5.com
Программы MQL5 / События клиентского терминала - Документация по MQL5
 
antt:
The NewTick event is an exception in this case. There are no checks for other event types. If the event handlers are slower than the event queue fills, the queue will overflow and some events will be skipped. As for the above example, it only confirms that the EA has a single execution thread and that event handling is performed sequentially, in the order that the events are queued.

Great, thanks for the explanations! Logical and understandable, no need to speculate

Interesting, your question about multithreading of events is sort of answered. And I even guessed about OnTimer :)

 
Yedelkin:
So it turns out thatTimer events can be ignored the same way asNewTick events? And under certain circumstances, they cannot be queued in Expert Advisor's events?

As far as I understand it, it goes something like this:

1. all events are placed in the same queue. If there is a NewTick event in the queue or such an event is handled, then NewTick is ignored and is not queued.

2. The programmer chooses which events to handle. Handlers for OnTrade, OnTimer and OnTick are basic and frequently used in Expert Advisors.

3. During processing of one event others cannot be processed.

4. If event stack overflows, old events are removed from queue without processing.

5. Of the above three types of events, Trade will be generated less often, and NewTick will be generated more often (but ticks as described above may not be included in the queue).

6. The most interesting handler from this point of view is OnChartEvent, which handles all events from the chart + custom events.

And just a large number of these events can easily overflow the event queue (in case there will be a lot of such events).

In my opinion, the only saving grace in this situation is that OnChartEvent events are generated haphazardly and asynchronously.

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы графиков / Типы событий графика
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы графиков / Типы событий графика
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы графиков / Типы событий графика - Документация по MQL5
 

Yedelkin:

Interesting, your question about multi-threaded event handling seems to be answered. And I even guessed about OnTimer :)

In principle, I had no doubts about a single thread, the more so because the code in the Expert Advisor itself is executed in a single thread.

And what I described is a kind of dream about the future (say, about MT6), when there will be multi-threading in MT (at least until the event stream will not be separated for some reason).

I would have originally at least separated all ChartEvent events into a separate thread, but the developers know better...

 

Is there any way to get the EA to generate Timer events at a specific time? For example, at the start of the last minute of the hour or the day.

 
Yedelkin:

Is there any way to get the EA to generate Timer events at a specific time? For example, at the start of the last minute of the hour or the day.

Sure.
 
TheXpert:
Sure.
What does it (method) look like, if it's not a secret?
 
Yedelkin:
What does it (method) look like, if not a secret?

Using timer manager. I wanted to write an article, but then I somehow got sidetracked. Although it may not look like an article.

A specific time will not work because of the single-threaded nature of the code and the event queue, but with an average error of less than a second (the maximum is limited by the maximum execution time of the event by the code).

Moreover, there is only one timer.

Shall I?