MT5 and speed in action - page 5

 
fxsaber:

In Combat Advisors, I've wrapped functions everywhere in suspicious places to _B(FuncName(...), AlertTime).

Forgot that it's very expensive.

        Alert: Time[SyncEA.mqh 309: ::TerminalInfoInteger(TERMINAL_MEMORY_USED)] = 21 ms.
 
fxsaber:

At best I spend tens of milliseconds on each tick just because of HistorySelect.

Profiling the combat advisor.


 
It's either that or something else. When an order is placed successfully, its ticket is returned? Does the return of the HistoryOrderSelect(ticket) function tell you anything? Why bother using expensive HS at all, except when starting the robot?
 
Vladimir Simakov:
Why use expensive HS at all, except when starting the robot?

Wrote at the beginning of the thread.

 
fxsaber:

You make an OrderSend. If, immediately after the end of the OrderSend, a certain position has not closed at the same time, you make another OrderSend. This is all the logic you need to program. Async is not used.

Now the situation that happened for our robot. You have sent an OrderSend and while it is being executed the Limiter has triggered and then the TP of our position has been executed, as I mentioned earlier.

I really don't understand anything about this - if you can, please describe the steps in more detail. The only thing I got was that only theOnTradeTransaction event handler is used, which means that we don't need event handling priority management and the suggested

bool HandleNextEvent(ENUM_EVENT_TYPE);

degenerates into

bool HandleNextEvent();
What was the request? Give usHandleNextEvent()
OnTradeTransaction(...)
{
        /*вычисления1*/
        HandleNextEvent();
        /*вычисления2*/
}
Now the secondary event handler in the scheme is proposed to be implemented like this:
On2TradeTransaction(...)
{
        if флаг установлен goto label
        /*вычисления1*/
                запомнить результаты вычислений
                установить флаг
                return;
label:          извлечь результаты вычислений
        /*вычисления2*/
}
 
A100:

This is where I really don't get it - if you can, please describe it in more detail step by step.

void OnMain()
{
  OrderSend(OP_BULIMIT); // Во время выполнения сработал и другой отложенник и тейк позиции (после отложенника).
  
  // Следующий OrderSend должен быть незамедлительно вызван.
  if (наблюдаемая позиция закрылась по тейку) // Проблема определить это без доступа к очереди.
    OrderSend(OP_BUYLIMIT)  
  else
    OrderSend(OP_SELLLIMIT)    
}
 
fxsaber:

Why can't youreturn after callingOrderSend?

void OnMain()
{
        if (first)
        {
                OrderSend(OP_BULIMIT); // Во время выполнения сработал и другой отложенник и тейк позиции (после отложенника).
                return;
        }
//...
}

Next time you return to OnMain when a new event has already been added to the queue (or by timer)

 

A100:

Why can't theOrderSend call be followed bya return ?

There is no limitation.

Next time you return to OnMain when a new event is added to the queue (or by timer)

The next event is the execution of a pending order and not of a take position.

 
fxsaber:

The next event is the execution of the pending order, not the takeover of the position.

It is suggested to return repeatedly, until you either read the whole current queue or for a given number of events. When trade events are over - there will be a timer return and you will have access to all events at once

 
void OnMain()
{
        if (first)
        {
                OrderSend(OP_BULIMIT); // Во время выполнения сработал и другой отложенник и тейк позиции (после отложенника).
                return; 
        }
        if ( OnTrade событие последнее )
                return; //может еще есть
        if ( OnTimer событие последнее )
        { // все торговые события в лукошке
                if (наблюдаемая позиция закрылась по тейку) // Проблема определить это без доступа к очереди.
                        OrderSend(OP_BUYLIMIT)  
                else
                        OrderSend(OP_SELLLIMIT)
        }
}
there is a more elegant solution, without OnTimer... think about it
Reason: