With what to replace OnTradeTransaction() in mql4? - page 4

 

Catching all events per tick, comparing with previously recorded data.

All in arrays.

Actually, sometimes there are brakes, when there are a lot of ticks. That's why I made a Delay between checks of 1 second.

It concerns monitoring of many positions.

And if you only monitor positions of a particular robot, it is of course easier there.

 

I have a simple task, and there are no more than two or three dozen orders at work.

And therefore I will use a timer to check what's in OrdersTotal() and write volumes in new and old variables with substitution at each iteration, and if the volume has changed - take further steps.

 
Aleksandr Volotko:

I have a simple task, and there are no more than two or three dozen orders at work.

And therefore I will use a timer to check what's in OrdersTotal() and write volumes in new and old variables with substitution at each iteration, and if the volume has changed - take further steps.

The volume will not change when a pending order triggers.

 
Artyom Trishkin:

The volume will not change when the pending order triggers.

Well, I filter orders by type in the loop and calculate the volume of the open cumulative position.

It saddens me that I have to waste resources and waste my time, when MT5 allows me to simply wait for a specific event without any stress.

 
Aleksandr Volotko:

Well, I filter orders by type in the loop and calculate the volume of open cumulative position.

It's sad that you have to train like this and waste resources, when in MT5 you can simply wait for a specific event without any stress.

Well mt5 is an order of magnitude higher than mt4.

This also applies to other functions.

 
In my specific situation, with transactions once a day, and the event once a day will be committed 60*60*24=86,400 extra gestures. And there is no other way to do it yet.

 
Aleksandr Volotko:
In my specific situation, if we deal once a day and get an event once a day, we will have 60*60*24=86,400 extra efforts. And there is no other way yet.

It depends on the task.

If we want to catch opening/closing (not partial) of a position and setting/deleting of an order, then we don't need to go through the list every time in a loop.

We can simply check the current and previous values of OrdersTotal(). If we detect a difference, we have an event, and then we look at the value.

I did everything using hash sum of order and position properties. As soon as it has changed - we have some event - then we look what exactly has changed there.

But I had a task to track everything, and any changes.

 
Aleksandr Volotko:
In my specific situation, if trades are executed once a day and an event takes place once a day, we will have to make 60*60*24=86,400 extra efforts. And there is no other way.

There is also this approach (if the appearance of a new order is only possible from the EA side):

  1. At the start of the EA, an array of its orders is generated by means of bypassing all orders on the list.
  2. On every new tick, the presence of the order is checked using

if (OrderSelect(nTicket, SELECT_BY_TICKET) && OrderCloseTime() == 0)

If the order is there, update its data if necessary. This is if monitoring of SL/TP/volume is necessary. If it is not required, we do not do anything else at all.

If the order is found in the list of closed (OrderCloseTime() > 0), then delete it from the array. The array will only be replenished when the order is opened by an EA.

As a result, we won't have to go through the entire list of orders on every tick. Operations are only possible with its own array.

 

I'll try comparing OrdersTotal() values for now (thanks to @Artyom Trishkin), that should be enough. I won't have partial closures.

During initialization, I will assign value -1 to the old order, so that at start the full check is always performed, regardless of presence of orders in the market.

After that, a new order will either appear (event) or the old one will be deleted (event) and even the symbol doesn't matter - we may check everything completely, it is still many times less frequent than endless fussing.

 
Aleksandr Volotko:

I'll try comparing OrdersTotal() values for now (thanks to @Artyom Trishkin), that should be enough. I won't have partial closures.

During initialization, I will assign value -1 to the old order, so that at start the full check is always performed, regardless of presence of orders in the market.

After that, the new order will either appear (event) or the old one will be deleted (event) and even the symbol does not matter - we can run a full check on all of them, it is still many times less frequent than endless pounding.

But it must be handled carefully, today I faced that one position has closed and the other opened on another one, and almost at the same time between ticks.

In the end OrdersTotal() remained 8. The Expert Advisor's logic got confused - it has not recalculated the new data