OnTradeTransaction - page 6

 
prostotrader:

You may not remember anything at all

I agree that this would work (in the case of a full pour)
void OnTradeTransaction ( const MqlTradeTransaction &Trans, const MqlTradeRequest &Request, const MqlTradeResult &Result )
{
  if ((Trans.type == TRADE_TRANSACTION_DEAL_ADD) && (Trans.position > 0) && !PositionSelectByTicket(Trans.position))
    Print("Position #" + (string)Trans.position + " - triggered SL/TP.");
}

But the conversation seems to be getting a little wider.
 
Andrey Dik:

You're very inattentive, I'm notthe topic starter.

You should also show me code like this:

//——————————————————————————————————————————————————————————————————————————————
void  OnTradeTransaction (const MqlTradeTransaction &trans,   // структура торговой транзакции
                          const MqlTradeRequest     &request, // структура запроса
                          const MqlTradeResult      &result)  // структура ответа
{
  
}  

If you do not like it, you may use Joba! Is it so?

I have spent enough time to answer your question.

If your question wasn't so "abstract", perhaps the answer would be more specific.

Namely:

1. FORTS or FOREX

2. What type do you use netting or hedgie

3. whether other orders are used during the lifetime of the position

The question is the same as the answer.

 
fxsaber:
I agree that this would work (in the case of a full fill)
void OnTradeTransaction ( const MqlTradeTransaction &Trans, const MqlTradeRequest &Request, const MqlTradeResult &Result )
{
  if ((Trans.type == TRADE_TRANSACTION_DEAL_ADD) && (Trans.position > 0) && !PositionSelectByTicket(Trans.position))
    Print("Position #" + (string)Trans.position + " - triggered SL/TP.");
}

But the conversation seems to be getting a bit broader.

I don't recall that volume can be set for ST/TP.

If not (I'll check now), the position will close FULL or SL or TP

 
prostotrader:

I don't recall waiting for ST/TP to set volume, if not,

then the position will close FULL or SL or TP

The liquidity may just not be enough.
 
fxsaber:
Liquidity may just not be enough.
Yep, and the Broker may turn off the power :)....
 
prostotrader:
Yeah, and the Broker can turn off the power :)....
Take a low-liquid instrument and that's it.
 
fxsaber:
Take a low-liquid instrument and that's it.

This is why I recommended the use of pending orders

Added by

A lot depends on the market and the instrument...

 
<br/ translate="no">

To accurately identify which order was responded to in the OnTradeTransaction event, all events other than the first order event are signed with a ticket.

The first event is signed by both the ticket and request_id. The request_id is obtained by the user right after the order is submitted from the OrderSendAsinc function. This is how a specific OrderSendAsinc iteration is linked with the results obtained in OnTradeTransaction.

The ticket in OrderSendAsync might not even exist, and most likely it won't if we are firing orders at a hundred per second (retcode 10008 at best, and that's it).

 
dmipec:

The ticket in OrderSendAsync may or may not be there and most likely won't be if the orders are fired at a few thousands of units per second (retcode 10008 at best and all).

Well, not ten, just 30 per second on a standard login.

If you have written it correctly, the order(s) will definitely be there.

 
Vasiliy Sokolov:

Instead of analyzing events, you should analyze the trading environment and only if the trading environment has changed should you make the necessary decisions. OnTransaction can only be used in very limited cases, and it is usually better to do without it in your work. Look at MetaTrader 4, it does not have OnTransaction and everybody does without it.

I agree. But unfortunately in MT5, unlike in MT4, the trading environment may not correspond to reality. For example, when a pending order is executed for several milliseconds, it might be nowhere to be found. And even OnTradeTransaction won't help here.