Asynchronous and multi-threaded programming in MQL - page 26

 
Vladimir Simakov:
Synchronization is the task of the programmer, if you don't know how, you don't use multithreading. The task of creators to give a tool, and there everyone is an evil Pinocchio to himself. The same a la mutex is not a problem to implement by yourself.

Unfortunately this is not the case, the target audience of MQL - who? (imho, application programmers who know the basics of programming)

And this will still be MQL5 (the developers have repeatedly said that there will be no more updates in MQL4).

MQL5 itself initially works in asynchronous mode - a request for historical data (for example, it will either return the data or start paging in the background and return an error). This way everything works with regard to data exchange between the terminal and MQL program,

and these moments are already perplexing, because instead of returning values you need to constantly check the data readiness and so on.... when converting from MQL4 it's really not convenient


and here's another topic, let's take a simple structure of MQL-program and enter different events asynchronously.... who will be intended for it? - who will be the end user of these necessary features?

;)

 
Andrey Barinov:

The GUI should spin in the main EA and everything else in a separate EA. This separate slave EA is placed on invisible OBJ_CHART and interacts with the main EventSendCustom() path.

I don't know how it is now. It seems that before, only scripts were running on OBJ_CHART. There was some other peculiarity with input parameters.

Tried requesting bars from all symbols from Market Watch. The history for all is uploaded. Tens of seconds one cycle pass! Not happy with MT5 to put it mildly.
 
fxsaber:

I don't know how it is now. Previously, it seemed that only scripts ran on OBJ_CHART. There was some other peculiarity with input parameters.

Tried to request bars from all symbols from Market Watch. History on all uploaded. Tens of seconds one cycle pass! Not happy with MT5 to put it mildly.

Expert Advisors are run, but neither ticks nor timer works there. The only way to run everything is through OnChartEvent (the ticks and the timer can be passed there from the main EA).

I have not noticed any other limitations. Everything works.

But you can do the same on a regular chart on the same principle. (In MT4 I have it that way, as there is noOBJ_CHART there)
 
Andrey Barinov:

Advisors are started, but neither ticks nor timer works there. Only OnChartEvent can be used to start everything (and the ticks and timer can be sent there from the main EA).

I have not noticed any other limitations. Everything works.

That's cool. I didn't know about this possibility. Why don't you put gui in indicator and interact via resources? I have it like this. The EventChartCustom() sends up to 128 symbols, one double and long at a time and it gets to the queue OnChartEvent(). In resources, you can place any characters and values of any types via units. And it doesn't queue. You get it when you need it.
 
Реter Konow:
That's cool. I did not know about this possibility. Why don't you put gui in indicator and use resources for communication? I have it like this. The EventChartCustom() sends up to 128 symbols, one double and long at a time and it gets to the queue OnChartEvent(). In resources, you can place any characters and values of any types via units. And it doesn't queue. You get it when you need it.

Thanks, I didn't know about OnChartEvent. Do you do the synchronisation through custom events? Data exchange?

 
Реter Konow:
That's cool. I did not know about such feature. Why not put the gui in indicator and use resources? I have it like this. The EventChartCustom() sends up to 128 symbols, one double and long at a time and it gets to the queue OnChartEvent(). In resources, you can place any characters and values of any types via units. And it doesn't queue. You get it when you need it.

I don't pass data by OnChartEvent. Only events. Otherwise there are no events in the EA agent, and this way it receives ONTIMER_BEAT and ONTICK_BEAT.

The data can be exchanged either via a file or via resources, depending on the task. I use files more often, because they are also used to restore the GUI and everything else after restarting the terminal.

Is your GUI able to remember and restore its appearance after the terminal restart?

 
fxsaber:

Thanks, I didn't know about OnChartEvent. Do you do the synchronisation through custom events? Data exchange?

Each message of each side has a sequence number. When party A sends a message to party B, it first looks to see if the previous message has been read. If not, it does not send a new one. When party B sends a message to party A, it also looks to see if the previous message has been read.
 
Andrey Barinov:

I don't pass data by OnChartEvent. Only events. Otherwise there are no events in the EA agent, and this way it receives ONTIMER_BEAT and ONTICK_BEAT.

The data can be exchanged either via a file or via resources, depending on the task. I use files more often, because they are also used to restore the GUI and everything else after restarting the terminal.

Is your GUI able to remember and restore its image after terminal restart?

I'd suggest doing away with EventChartCustom() entirely, precisely because of the queue, which can sometimes cause stalls. Interact through resources making two-way requests at the timer frequency. For example, if side A is heavily loaded with OnChartEvent() and side B sends a Cancel button event, then side A may receive this event late due to some nonsense that is loading it up.

Yes, I save the kernel in the file and load from the file. In this case, all settings and appearance are reverted to the last view after restart. But, usually after restart I need startup settings, so I don't use this function.

 
Реter Konow:

I would suggest doing away with EventChartCustom() entirely, precisely because of the queue, which can sometimes cause slowdowns. Interact through resources making two-way requests at the timer frequency . For example, if side A is heavily loaded with OnChartEvent() and side B sends a Cancel button event, then side A may receive this event late due to some nonsense that loads it.

Timer does not work in EA which is on OBJ_CHART. There are NO EVENTS there (except OnChartEvent). Therefore, we have to send allevents (OnTick, OnTimer etc) there from main EA.

Besides, I don't send button presses there. There's no need for that.
 
Andrey Barinov:

The timer does not work in the EA which is on OBJ_CHART. There are NO EVENTS there (except OnChartEvent). Therefore, all events (OnTick, OnTimer etc.) must be sent there from main EA.

Besides, I don't send button presses back and forth. There's no need for that.

I propose to use the indicator as a carrier of GUI, and resources as a link to the EA. In addition, in MT4, you will be able to control the Expert Advisor tester from a standard chart using the panel. All controls will work, not just buttons. You will be able to send text and anything else to the EA under test. I have already tested it. Everything works.

ZS. And the EA being tested will send different data to the regular chart.

Reason: