The great and terrible MT4 forever (or how to strategise a transition) - page 12

 
Andrey Khatimlianskii:

It would be great to get around this point at MT4Orders level.

Order backups are happening now, unfortunately. Most likely because of this.

https://www.mql5.com/ru/forum/93352/page40#comment_13943845 it?

 
traveller00:

https://www.mql5.com/ru/forum/93352/page40#comment_13943845 it?

Unfortunately, backtracking happens with this crutch as well.

I don't know which way to debug anymore.

 
Andrey Khatimlianskii:

Unfortunately, backtracking happens with this crutch too.

I don't know which way to debug anymore.

Here's the reason (not that there aren't others).

        // Открытие руками единственной позиции.

        1
        PositionsTotal() = 0 OrdersTotal() = 1 HistoryDealsTotal() = 57 HistoryOrdersTotal() = 57 
        #2249767032 2021.05.04 02:10:01.089 buy 0.01 USDCAD 1.22776 0.00000 0.00000 1.22776 0.00 0.00 0.00 0
        ----------------
        2
        PositionsTotal() = 0 OrdersTotal() = 1 HistoryDealsTotal() = 57 HistoryOrdersTotal() = 57 
        #2249767032 2021.05.04 02:10:01.089 buy 0.01 USDCAD 1.22776 0.00000 0.00000 1.22776 0.00 0.00 0.00 0
        ----------------
        3
        PositionsTotal() = 0 OrdersTotal() = 1 HistoryDealsTotal() = 57 HistoryOrdersTotal() = 57 
        #2249767032 2021.05.04 02:10:01.089 buy 0.01 USDCAD 1.22776 0.00000 0.00000 1.22776 0.00 0.00 0.00 0
        ----------------
        4
        PositionsTotal() = 0 OrdersTotal() = 1 HistoryDealsTotal() = 57 HistoryOrdersTotal() = 57 
        #2249767032 2021.05.04 02:10:01.089 buy 0.01 USDCAD 1.22776 0.00000 0.00000 1.22776 0.00 0.00 0.00 0
        ----------------
        5
        PositionsTotal() = 0 OrdersTotal() = 1 HistoryDealsTotal() = 57 HistoryOrdersTotal() = 57 
        #2249767032 2021.05.04 02:10:01.089 buy 0.01 USDCAD 1.22776 0.00000 0.00000 1.22776 0.00 0.00 0.00 0
        ----------------
        6 // Полностью исчез открывающий позицию ордер - его нет ни в одной таблице. Позиции так и нет.
        PositionsTotal() = 0 OrdersTotal() = 0 HistoryDealsTotal() = 57 HistoryOrdersTotal() = 57 
        ----------------
        7 // Ордер появился в исторической таблице. Позиции так и нет.
        PositionsTotal() = 0 OrdersTotal() = 0 HistoryDealsTotal() = 57 HistoryOrdersTotal() = 58 
        ----------------
        8 // Появилась позиция и сделка.
        PositionsTotal() = 1 OrdersTotal() = 0 HistoryDealsTotal() = 58 HistoryOrdersTotal() = 58 
        #2249767032 2021.05.04 02:10:01.124 buy 0.01 USDCAD 1.22776 0.00000 0.00000 1.22769 -0.02 0.00 -0.05 0
        ----------------

P.6 is the most unpleasant. How to bypass this MT5 bug - haven't figured it out.

 
fxsaber:

Here's the reason (not that there aren't others).

P.6. is the most unpleasant. How to work around this MT5 bug - haven't figured it out.

The check for "missing" orders would work here. But it would not work.

I must have messed up something.

 
Andrey Khatimlianskii:

A missing order check would work here. It doesn't work.

I must have done something wrong myself.

In point 7. "The missing order shows up, but there's still no position.

 
fxsaber:

In point 7. The "missing" is found, but the position is still missing.

Does it mean that the loop on MT4Orders::OrdersTotal() will not see either the order or the position?

I thought this point was solved: either the order/position is in the list, or the order is "missing". How can a third thing happen?

 
Andrey Khatimlianskii:

Does this mean that the MT4Orders::OrdersTotal() loop will not see either order or position?

In all points, except point 6 and point 7, it shows that one position is visible.

I thought this point was just solved: either the order/position is in the list, or the order is "missing". How can there be a third?

Imagine that your EA reaches position 6 without knowing anything about the fact that there was an order. In that case there is no way for him to know that the situation corresponds to the missing order.

Великий и ужасный МТ4 навсегда (или как грамотно выработать стратегию перехода)
Великий и ужасный МТ4 навсегда (или как грамотно выработать стратегию перехода)
  • 2021.05.03
  • www.mql5.com
Хочу затронуть самую что ни на есть щекотливую тему терминалов МТ4 и МТ5. Их влияние и популярность среди пользователей и брокеров / ДЦ...
 
fxsaber:

Imagine that your EA gets to point 6 without knowing anything about there being an order. In that case there is no way for him to know that the situation corresponds to the missing order.

I cannot imagine such a situation if limits are used at some distance from the price (not in the spread).

He will always have time to see the set order in the list. And subsequently the order will either become "missing", or it will turn into a position.


I admit that such a situation is possible if another EA has thrown an order at the current price and it immediately started to fill (point 6).

But that still doesn't explain why the first EA stops seeing its order (with its magician) in the list of MT4Orders::OrdersTotal().

 

It was surprisingly easy to reproduce the situation on the live EA - at the moment one of the orders was executed, the EA lost sight of the other one as well.

But when trying to build a simple example for reproduction, everything works fine. It looks like I really made a bug somewhere in the wilds of my code.

 

Here is from the documentation:

"the order in which these transactions arrive in the terminal is not guaranteed, so you cannot base your trading algorithm on waiting for some trade transactions to arrive after others have arrived. " https://www.mql5.com/ru/docs/event_handlers/ontradetransaction

And from experience, TRADE_TRANSACTION_ORDER_DELETE, TRADE_TRANSACTION_DEAL_ADD, TRADE_TRANSACTION_HISTORY_ADD transactions can arrive in any order.

Hence we have situations where there is no deal or order in the history yet, but the order already exists. Or vice versa, the order is still there, but the deal has already been executed. But the situation where the order is simultaneously in the active and in the history is hardly possible.

Actually, this is the reason why we refused to use the CTrade class - it has all these pitfalls.

The way to fight this problem is that each EA keeps a list of its orders and monitors their state. Including "non-standard" states - "order sent but not yet in working order" (here they can double up) or "order deleted but not yet in history". It also helps to work on the same symbol at the same time when netting.

Документация по MQL5: Обработка событий / OnTradeTransaction
Документация по MQL5: Обработка событий / OnTradeTransaction
  • www.mql5.com
OnTradeTransaction - Обработка событий - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
Reason: