Learning and writing together in MQL5 - page 17

 
Yedelkin:

Question about the Sleep() function. Do I correctly understand that using this function in an Expert Advisor halts execution of that EA only, and transfers CPU resources (kernel) to the next tasks in the list of tasks of that kernel? In other words, is it correct that Sleep() function does not slow down the thread itself where the Expert Advisor is being processed, but works as a switch between the current Expert Advisor and other programs picked up by a particular kernel?

As far as I understand, if I set Sleep(0), it will switch over. If I set Sleep(milliseconds), the EA will be stopped for a specified number of milliseconds.

At the same time, as far as I understand, each Expert Advisor is a separate thread and each of those threads claims processor time (the check of thread's state is performed every 100 milliseconds according to the help).

Thus if a thread is inactive, whatever the reason, CPU time is passed to another thread and the status of the thread that "decided to sleep" is checked after 100 milliseconds.

PS

Regarding distribution of cores between threads it is up to developers.

 
Yedelkin:

Question about the Sleep() function. Do I correctly understand that using this function in an Expert Advisor halts execution of that EA only, and transfers CPU resources (kernel) to the next tasks in the list of tasks of that kernel? In other words, is it correct that the Sleep() function does not slow down the thread itself where the Expert Advisor is being processed, but acts as a switch between the current Expert Advisor and other programs picked up by a particular kernel?

Each expert is executed in its own thread. Sleep() slows down this thread. There is no binding to cores (affinity mask).
 
Yedelkin:

Question about MqlTradeResult structure. I haven't found time field in it - time of successful basic request check (or something like that). Does anybody remember if there was a question about introducing an additional time field into MqlTradeResult structure? Needed for pulling out a pending order if it suddenly goes into history.

The request is not clear. If the order has been opened, it will store the opening time. Why do you need the server response time ?
 
sergeev:
The request is not clear. If the order was opened, then it will store the opening time. Why do you need the server's response time ?

The fate of the order is tracked by the ticket, right? However, the return of the ticket by the OrderSend() function does not guarantee the successful execution of the trade operation. According to the logic of the program, it is sufficient to check if my ticket has appeared among historical orders and what deals have been made after it was placed. For this I would like to upload the minimum amount of history to the history cache - i.e. from the time of server's response to the initial request, and no more. We do not need to work with the properties of an open order - that would be redundant pieces of code. The order may not even open. Thus, the server's response time is needed to download the optimal size (amount) of a fresh history, using the HistorySelect() function. So, is it clear about "taking an order out of the history"?

As far as I understand, the question of introducing an additional time field into the MqlTradeResult structure has not been raised yet.

 

About Sleep() I understood that the Expert Advisor's thread delay does not affect the execution of other programs. Thanks.

 

Another question about Sleep(). The comment says: "You can't call Sleep() function from custom indicators, asindicators are executed in the interface thread and it shouldn't slow it down". I've read the forum, but still don't understand the following: the phrase "you can't call it from indicators" - is it a preset prohibition or a recommendation to the programmer?

 
Yedelkin:

The fate of the order is tracked by the ticket, right? However, the return of the OrderSend() ticket does not guarantee the successful execution of the trade.

ahem.... you should have a look in a textbook about sending an order.
 
Yedelkin:

Another question about Sleep(). The comment says: "You can't call Sleep() function from custom indicators, asindicators are executed in the interface thread and it shouldn't slow it down". I've read the forum, but still don't understand the following: the phrase "you can't call it from indicators" - is it a preset prohibition or a recommendation to the programmer?

ban
 
sergeev:
xxm.... you should have a look in a textbook about sending an order.

Well, you get the point. I'm telling you meticulously, you can check: OrderSend() function returns a boolean value. In this case, if the request is successfully checked, the order ticket is written into variable of MqlResult structure. I call it "return of the order ticket function" for myself. Here is the link to the source:"When sending a request to buy using the OrderSend() function, you can immediately see the ticket of the order that was created if the request is successfully checked.

For the response about "banning" - thanks, got it.

 
Yedelkin:

Well, you get the point.

Unfortunately, I still don't get it.

you need to have a "time" field in the return structure for some reason. use the time in the order that appears. This is enough to control a little history.

Reason: