Download MetaTrader 5

question to MetaQuotes - event handling queue

To add comments, please log in or register
Your conversation partner speaks foreign language? Automatic translation will help you!
Pawel Wojnarowski
Pawel Wojnarowski 2012.08.23 11:59 

Hello MetaQuotes,

I am currently preparing a flexible framework for multicurrency EA for the ATC2012 and therefore I would like to ask for clarification on event handling mechanism in MT5. The general info about the event handling is:

A client terminal sends new events to the corresponding open charts. Events can also be generated by charts (chart events) or mql5-programs (custom events). (...) Each MQL5 program and each chart has its own queue of events, where all new incoming events are added.

A program receives only events from the chart it runs on. All events are processed one after another in the order they are received. If a queue already has a NewTick event, or this event is currently being processed, then the new NewTick event is not placed in the queue of the MQL5 program. Similarly, if ChartEvent is already enqueued, or this event is being processed, no new event of this kind is enqueued. The timer events are handled the same way – if the Timer event is in the queue or being handled, the new timer event is not enqueued.

Event queues have a limited but sufficient size, so that the queue overflow for well written programs is unlikely. In case of queue overflow, new events are discarded without queuing. 

Having quoted this, let me describe the case in brief:

For multicurrency EA I obviously need multicurrency OnTick event handler. I have decided to adapt the approach proposed by Lizar (I have attached Spy Control panel MCM.mq5 under this post for a quick reference) which uses EventChartCustom() for generating an event of new tick or new bar (it attaches an indicator to a chart of each symbol that user wants to track and this indicator generates events on new tick/new bar). I have tested it in a simple way by just printing an info about new bar on a certain period and so far it works fine, but I am afraid that due to what I have marked bold above, when I will start processing such a new bar event e.g. for EURUSD M1 and it will last e.g. 5-10 seconds due to some calculations, all the other events (e.g. GPBUSD M1, EURJPY M1) will be discarded and my EA framework will never know that it should process the other currencies.

My first question is - is above thinking right? Or is there a queue for custom events, which keeps the new custom events until the current one is processed? 

The other question is with regard to:

Event queues have a limited but sufficient size, so that the queue overflow for well written programs is unlikely.

 What queues does this sentence describe? A common event queue for each of charts/MQL5 programs ("own queue of events" for each one, as stated in the first quotation) and e.g. the one for OnTradeTransaction() (according to documentation, it has its own event queue for 1024 events) additionally for EAs? How large is "limited but sufficient size"?

To add comments, please log in or register