OnTradeTransaction - page 9

 
Aleksey Mavrin:

Yes, you're right, because in this case it's a position identifier, constant throughout its life. I confused it with the position's ticket, which changes during rollovers and netting.

But I do not understand - when a position is partially closed, the ticket does not change to the ticket of the last order affecting the position?

I will review my codes, thanks. I have visited the forum not for nothing)

Concerning the "lost order" which is not in the list of current or historical orders: It seems to me this is not a bug, I just need to carefully look at the features of

I think this is not a bug, just need to carefully look at peculiarities of terminal-server MT-market (in the case of instant execution the market does not work). I think so, look - the terminal sends a market order, in the case of synchronous function - it waits and gets a reply from the server,

If there is no error, the reply may only be TRADE_RETCODE_DONE (in the case of instant execution it is requotes, but so far it is the market type), which essentially means that the server has sent the order to the market and it

It actually means that the server has sent the order and waits for its reply. The state of the order at this moment isORDER_STATE_STARTED if I am not mistaken and its ticket is known. If the order is executed, the server sends OnTradeTransaction to the terminal and the order status changes to ORDER_STATE_FILLED and the trade is known

and position becomes known. It is only at this point that the terminal records the order into the history. It does not do this beforehand since we are not sure what has happened to it and it has already given the initial reply from the server.

This is the time until the order is executed in the ECN network or somewhere else, they are not in either of the two lists. I.e. in the case of market order, it only appears in the history (I am not sure about the case of requotes during instant execution),

it will never appear in the list of open ones. And when a pending order triggers, it is removed from the list of the open ones because it has already become a market order and we wait for the market-server to respond, and then it is sent to history.

Am I right?

Not really.
 
Aleksey Mavrin:

Am I right?

Andrey explained it very well.

Forum on trading, automated trading systems and strategy testing

OnTradeTransaction

Andrey Khatimlianskii, 2019.12.17 08:24

No, things are worse.

The order at the moment of transformation from pending (or market) to historical (executed or cancelled) for some time disappears from the terminal at all. It does not appear either among pending (or "started" market), or among historical ones.

So it's not a matter of execution, but of synchronization of these two tables. The answer from the server came ("Order executed, generated transaction so-and-so"), it is removed from one table, but not entered into the other.


The problem is not OrderSend. There was BuyLimit for a long time. And suddenly it and Buy-positions are nowhere to be found. This is about the same situation that happens.

 
fxsaber:

Andrei has written it well.


It's not about OrderSend. It was BuyLimit for a long time. And suddenly neither it nor the Buy position is anywhere to be found. That's about the same situation that happens.


Artyom Trishkin:
Not really.

I have understood. Even the market order is in the list of current orders for some time (but it seems that it is not displayed in the terminal on the trade tab?

Then when the order has been executed and a corresponding transaction from the server has been received, the terminal performs the following actions

1. delete the order from current

2. write the order in historical

3. write the trade to the list

4. write the position to the list

and considering that the Expert Advisor and the terminal itself work in independent parallel streams, the terminal will not be able to open a position yet if you request it within this short period of time.

position, it won't be there yet. As I wrote before, if this were happening according to DBMS standards, there would be no such thing, because all 4 operations there would be combined into one transaction, and you couldn't get caught up in "intermediate states".

Right? But I'm actually interested - if we rely on OnTrade and OnTradeTransaction, then these handlers shouldn't have lag, they happen by creating changes in corresponding tables, right?

Or Terminal simply sends them to Expert Advisor when receiving events and changes tables at the same time? In the latter case, of course, it is wrong and needs to be corrected, especially if OnTradeTransaction, from which the actual information could be obtained, is not guaranteed.

 
Aleksey Mavrin:

Got it. Even the market order is present in the list of current orders for some time (only it seems that it is not displayed in the trading tab in the terminal?)

Sometimes you can even see it there with your eyes when it's in Started state. And it is easy to track with a robot.


Aleksey Mavrin:

And considering that the Expert Advisor and the terminal itself operate in independent parallel streams, the situation is as follows: if you request a position within this short period of time, it won't appear.

We are not referring to positions but only orders.

We need much less time to add an entry to the table than we sometimes get. And we are not serious, there is no guarantee that we will get the right trading environment.


Aleksey Mavrin:

And I actually wondered - if we rely on OnTrade and OnTradeTransaction, then these handlers shouldn't have lag, because they do happen when changes are written to appropriate tables?

Or Terminal simply sends them to Expert Advisor while receiving events and changes tables at the same time? In the latter case, of course, it is wrong and needs to be corrected, especially if OnTradeTransaction, from which the actual information can be obtained, is not guaranteed.

OnTrade in its pure form won't help.

You can combine waiting for order table synchronisation in it as well, it's a matter of taste. But you still have to wait.

 
Aleksey Mavrin:

Regarding the "lost order", which is not in the list of current or historical orders: I think it's not a bug, we just need to look closely at the features of Terminal-Server MT-Market (in the case of instant execution the market is out). I think the terminal sends a market order, in the case of synchronous function it waits and gets a reply from the server. If there is no error the reply may only be TRADE_RETCODE_DONE (in case of instant execution there are requotes, but so far it is the market order) which actually means that the server has sent the order to the market and waits for a reply. The state of the order at this moment is ORDER_STATE_STARTED if I am not mistaken and its ticket is known. If the order is executed, the server sends OnTradeTransaction to the terminal and the order status changes to ORDER_STATE_FILLED and the trade and position are known. Only at this moment the terminal records the order into the history.

The market has nothing to do with it.

The MetaTrader server sends the order to ECN or somewhere else, gets the answer, sends it to the terminal. And in the terminal the timing is off.

Reason: