Question about the OnTradeTransaction function - page 6

 
Mikalas:

No, transactions are not lost, they just may not come in a certain sequence.

Only TRADE_TRANSACTION_REQUEST always comes first, otherwise you will not get the order ticket.

Read the documentation CAREFULLY.

Michael, sorry, but it seemed to me that you only replied to the last post, and it's as a consequence of everything that was described in the first one on this page.

And it's strange to hear you recommend to read documentation. I read it, reread it and read it again.

What do you mean by "Warrant Ticket"? I don't see it in the documentation.

 
AlexeyVik:

Michael, I'm sorry, but it seemed to me that you only responded to the last post, and it was as a consequence of everything described in the first one on this page.

And it seems strange to hear your recommendation to read the documentation. I read it, reread it and read it again.

What do you mean by "order ticket"? I have not seen this in the documentation.

An ulong ticket is a unique number that is assigned to an order.

This number will not change during the lifetime of the order as well as in the history.

We obtain information about the order using tikcet.

 
Mikalas:

An ulong ticket is a unique number that is assigned to a placed order.

This number does not change throughout the lifetime of the order, as well as in the history.

We get information about the order using tikcet.

Thank you Mikhail. Actually, I assumed that you meant the ticket of the order. But it should have been more precise.


But still, the behavior of tickets is quite strange.

Example: Tickets and volumes from run in the tester.

We open a position in Buy 0.1 lot, Ticket 2. SellStop 0.78 Ticket 3 is placed.

When SellStop is activated, the position is left with 0.68; order 3 with the volume 0.78 and negative profit appears in the history.

At the same time there is a position with ticket 4

And it is absolutely unclear where the loss from the position with the ticket 2 has disappeared to.


In general, we cannot always believe what is written. Because it is not completely written.

If a position opens with a pending order, the ticket stays, but if the order closes another one, the new one is created.

 

The same thing happens with the ticket if the position and the pending order are in the same direction. The ticket changes.


 
AlexeyVik:

Apparently this is the loss of transactions... and, first of all, (clipping from documentation)

Vasily, is this a tester or a demo? I have samples from the tester. I wonder if there is a difference between OnTradeTransaction triggering in the tester and on the account? I will check it on occasion.

This is a demo. Maybe the event model is different in the tester and in real time.

 

I have several bots in MT5 on Forts. Including several on the same instrument. I use to determine how many contracts which "robot" has, by jogging through the history of trades. It all basically works. I have decided to try usingOnTradeTransaction. The idea how to implement it is simple - when a deal comes, we look how many contracts are bought or sold and what bot made the deal (using special comment to the deal or Magic Number) and save this information in a file. The question is this. If we have OnTradeTransaction in each EA, how will it be called sequentially or in parallel? Suppose, for example, a deal has been executed - a lot of events have occurred and OnTradeTransaction will be consistently called in each bot for each event? I.e., is it easier to make one OnTradeTransaction handler that will be responsible for all bots? If anything, I'm not a programmer, although I have programmed a lot of things already. The code may be cheesy, but I always get it to work properly.

 
votor:

I have several bots in MT5 on Forts. Including several on the same instrument. I use to determine how many contracts which "robot" has, by jogging through the history of trades. It all basically works. I have decided to try usingOnTradeTransaction. The idea how to implement it is simple - when a deal comes, we look how many contracts are bought or sold and what bot made the deal (using special comment to the deal or Magic Number) and save this information in a file. The question is this. If we have OnTradeTransaction in each EA, how will it be called sequentially or in parallel? Suppose, for example, a deal has been executed - a lot of events have occurred and OnTradeTransaction will be consistently called in each bot for each event? I.e., is it easier to make one OnTradeTransaction handler that will be responsible for all bots? If anything, I'm not a programmer, although I have programmed a lot of things already. The code may be cheesy, but I always make it work properly.

Yes, OnTradeTransaction will work in each EA. They should be filtered by symbol and if there is more than one Expert Advisor on one symbol, then by magik.

 

Thank you for your reply. I already checked it and I see that it works in all EAs. The question is (maybe it's a stupid question) if all theseOnTradeTransactions are processed in all EAs in series, first in one EA, then in the next one, etc., rather than in parallel, right? It means that since their processing is sequential(?), we better make one handler for all bots and filter what we need in it.

 
votor:

Thank you for your reply. I already checked it and I see that it works in all EAs. The question is (maybe it's a stupid question) if all theseOnTradeTransaction posts in all EAs work sequentially, first in one EA, then in the next one, etc., rather than parallel, right? I mean, since their processing is sequential(?), it would be better to create one handler for all bots and filter what we need in it.

I haven't checked it, but there seems to be no regularity. It's like who got up first, leaves no stone unturned. And it's possible that if you get up at the same time, then each one the slipper.

So far it seems to me the best option to filter by symbol and magician. Whose position he writes information about it.

 

Something I'm not good at explaining, apparently. Here's a real-life example. Here is the code:

void OnTradeTransaction(const MqlTradeTransaction& trans,

const MqlTradeRequest& request,

const MqlTradeResult& result)

{

Count++;

Print("Ontrade_test = ",Count);

}

The handler is implemented in two Expert Advisors so it is executed multiple times in two Expert Advisors when one trade is performed. The code produces:

18:31:06.495 ontrade_trans_functions (MXI-12.17,H1) Ontrade_test = 1

18:31:06.495 ontrade_trans_functions2 (MXI-12.17,H1) Ontrade_test = 1

18:31:06.497 ontrade_trans_functions (MXI-12.17,H1) Ontrade_test = 2

18:31:06.497 ontrade_trans_functions2 (MXI-12.17,M5) Ontrade_test = 2

18:31:06.498 ontrade_trans_functions (MXI-12.17,M5) Ontrade_test = 3

18:31:06.498 ontrade_trans_functions2 (MXI-12.17,H1) Ontrade_test = 3

18:31:06.500 ontrade_trans_functions (MXI-12.17,M5) Ontrade_test = 4

18:31:06.500 ontrade_trans_functions2 (MXI-12.17,H1) Ontrade_test = 4 ...

and so on.

You can see that the OnTradeTransaction response time in the two Expert Advisors is the same in milliseconds. So, I have a question: does the trade event comes first to one OnTradeTransaction in one EA and then to the next one in another EA or does it somehow get to all handlers of all EAs at once? You know, like a parallel multi-threaded operation or whatever it is called in programming. I'm sure that everything happens sequentially, it is just processed within one millisecond, but I asked just in case.

Reason: