Question about the OnTradeTransaction function - page 5

 
papaklass:

OnTradeTransaction() is the RUNNER of a trade event. It doesn't matter what triggered the event, the important thing is that the event occurred.

Here is an extract from the documentation:

OrderSend() / OrderSendAsync() are TRADE FUNCTIONS.

For OnTradeTransaction() it makes no difference which function you used to send the trade order OrderSend() or OrderSendAsync().

I've read it so many times before creating the subject ... I won't say a word.

But nevertheless, my conclusion is that it's more probable to lose one transaction in a heap than to lose one transaction in a second, and maybe not even one (second). That's exactly what I'm trying to find out. Trying to get your opinion on this. What is the probability of losing a transaction if they are fairly rare and single?

 
papaklass:
In terms of probabilities, I don't know.

I'll have to rely on Michael's single opinion, based on his own experience. If he hasn't lost a single transaction in half a year from a pile of orders, then we will assume that one single order won't get lost.

I'm slowly getting the hang of it, trying not to break the logic, but sometimes one gets in the way of the other...

 
AlexeyVik:

We will have to rely on Michael's single opinion, based on his own experience. If he hasn't lost a single transaction in six months from a pile of orders, then we will assume that one single order won't get lost.

I am slowly mastering it, trying not to break the logic, but sometimes it turns out that one interferes with the other...

Alexei, ask yourself a simple question:

Which is better, to dig through history after each command, or 1 time, or maybe never, to double-check the order ( OnTradeTransaction was not triggered)?

Validation is not easy to implement (by the way, my example has mistakes), but the main principle is that EVERY order has its own magic.

And one more thing. I have already said that everyone is free to go his own way....

 
Mikalas:

Alexey, ask yourself a simple question:

Is it better to dig through the history after each command or to double-check the order (OnTradeTransaction did not work) once or never?

Validation is not easy to implement (by the way, my example has mistakes), but the main principle is that EVERY order has its own magic.

And one more thing. I have already said that everyone is free to go his own way....

Michael, it's the simple answer to this simple question that got me into this whole discussion. And so far I'm not going to give it up. But I still can't understand if transaction loss is possible after OrderSend() command or pending order's activation, or during position closing using stop/stop.

From your first answer I understood that even OrderSendAsync() you don't lose transaction. I'm trying to understand it in order to decide, whether it's necessary to bother checking at such, rather rare transactions. Moreover, taking into account what I've allocated.

Purely logically, if OrderSend() isn't terminated until it gets reply, transaction can't be lost. But the activation of a pending order and closing a position do not fit into my logic. If a transaction in this case is triggered within MT5, respectively, it won't be lost, but if through a server... I don't know. (But I suppose the intuition says that the server sends me a response and activates OnTradeTransaction().

 

Guys, here's the problem:

If I open a position, OnTradeTransaction handles only TRADE_TRANSACTION_DEAL_ADD... Everything is fine.

If a SellStop, for example, is placed, only TRADE_TRANSACTION_ORDER_ADD is triggered... Everything is also normal.

But if I set a position and a pending order, TRADE_TRANSACTION_DEAL_ADD works and TRADE_TRANSACTION_ORDER_ADD works twice

why is it like this?

#include <Trade\Trade.mqh>


double point, FirstOpenPrice, TakeProfit, SecondOpenPrice, MaxPrice , MinPrice, SecondTake;
bool  NewStart;
       
    CTrade Trade;
    MqlTradeResult v_res, v_result;
    MqlTradeTransaction v_Trans;

/*******************Expert initialization function*******************/
int OnInit()
{
 point = _Digits%2 == 0 ? _Point : _Point * 10;
  NewStart = true;
   return(INIT_SUCCEEDED);
}/*******************************************************************/

/************************Expert tick function************************/
void OnTick()
{
 if(NewStart)
  {
   Trade.PositionOpen(Symbol(), ORDER_TYPE_BUY, 0.1, SymbolInfoDouble(_Symbol, SYMBOL_ASK), 0.0, 0.0);
    Trade.SellStop(0.78, SymbolInfoDouble(_Symbol, SYMBOL_BID)-52*point, Symbol(), 0.0, 0.0, 0, 0);
   NewStart = false;
  }
}/*******************************************************************/

/*********************TradeTransaction function**********************/
void OnTradeTransaction(const MqlTradeTransaction& trans,
                        const MqlTradeRequest& request,
                        const MqlTradeResult& result)
{

  ENUM_TRADE_TRANSACTION_TYPE type = (ENUM_TRADE_TRANSACTION_TYPE)trans.type;
   
   switch(type)
    {
     case TRADE_TRANSACTION_ORDER_ADD:
      {
       Print("order add    * Тикет ордера * ", trans.order);
        Print("order add    * Объём ордера * ", trans.volume);
       break;
      }
     case TRADE_TRANSACTION_DEAL_ADD:
      {
       Print("deal add    * Тикет сделки * ", trans.deal);
        Print("deal add    * Объём сделки * ", trans.volume);
       break;
      }
     default: break;
    }

}/*******************************************************************/
 
AlexeyVik:

Guys, here's the problem:

If I open a position, OnTradeTransaction handles only TRADE_TRANSACTION_DEAL_ADD... Everything is fine.

If a SellStop, for example, is placed, only TRADE_TRANSACTION_ORDER_ADD is triggered... Everything is also normal.

But if I set a position and a pending order, TRADE_TRANSACTION_DEAL_ADD works and TRADE_TRANSACTION_ORDER_ADD works twice

why is it so?

You must be mistaken somewhere. There must be at least two events in both cases: TRADE_TRANSACTION_ORDER_ADD and TRADE_TRANSACTION_DEAL_ADD. Why you don't get TRADE_TRANSACTION_ORDER_ADD is unclear.

Try to comment out the switch and print the full log of all events received in OnTradeTransaction.

 
C-4:

You have got it wrong somewhere. In both cases there must be at least two events: TRADE_TRANSACTION_ORDER_ADD and TRADE_TRANSACTION_DEAL_ADD. Why you don't get TRADE_TRANSACTION_ORDER_ADD is unclear.

Try to comment out the switch and print the full log of all events received in OnTradeTransaction.

Yes, I tried it. The Print(EnumToString(type)) was printed before switch(type); it printed exactly as I have described.

Here are the repeated experiments.




 

Checked your code on my own. - Everything works correctly.

Option without sendinga stop order to follow up:

2015.02.10 18:32:03.332 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_DEAL_ADD

2015.02.10 18:32:03.331 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_HISTORY_ADD

2015.02.10 18:32:03.327 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_ORDER_DELETE

2015.02.10 18:32:03.327 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_ORDER_ADD

2015.02.10 18:32:03.327 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_REQUEST

Option to send a stop order:

2015.02.10 18:35:59.633 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_REQUEST

2015.02.10 18:35:59.629 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_ORDER_UPDATE

2015.02.10 18:35:59.629 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_ORDER_ADD

2015.02.10 18:35:59.629 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_REQUEST

2015.02.10 18:35:59.629 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_DEAL_ADD

2015.02.10 18:35:59.629 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_HISTORY_ADD

2015.02.10 18:35:59.629 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_ORDER_DELETE

2015.02.10 18:35:59.629 TestOnTradeTransaction (EURUSD,M1) TRADE_TRANSACTION_ORDER_ADD


s.e., time for full cycle was a pleasant surprise: stably 60-70 msec. Well done, developers!
 
C-4:

Checked your code on my own. - Everything works correctly.

Variant without sendinga stop order afterwards:

Option with sending a stop order:

s.e., time for full cycle was pleasantly surprised: stably 60-70 msec. Well done to the developers, they did a great job!

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

And the order in which these transactions arrive at the terminal is not guaranteed

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


ps; It turns out that after losing a transaction it suddenly appears at the next OnTradeTransaction activation.

 
AlexeyVik:

Apparently this is the loss of transactions... and, first of all, (excerpt 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 in the account. I will check it on occasion.


ps; It turns out that after losing a transaction it suddenly appears when OnTradeTransaction is activated next time.

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

Only TRADE_TRANSACTION_REQUEST always comes first otherwise you wouldn't get a ticket for the order.

Read the documentation CAREFULLY.

Reason: