OnTradeTransaction - page 5

 
Anatoli Kazharski:
Yeah, that's about right. Just haven't tested it that way yet.

Try it...

Added by

case TRADE_TRANSACTION_DEAL_ADD:
  if (trans.order != my_order_ticket)
  {
    if(trans.symbol==Symbol())
    {
      if(проверяем магик)
      {    
        //Сработал SL или TP
      }
    }
  }
break;
 
prostotrader:

What's wrong with this method?

case TRADE_TRANSACTION_DEAL_ADD:
  if (trans.order != my_order_ticket)
  {
   //Сработал SL или TP
  }
break;

Because the last known SL and TP positions may not coincide with the deal price and there will be nothing to compare it with.

And you don't like to share your codes, but you look at other people's ones with great pleasure...

This will not always work:

int    G_LastTicket  = 0;   //Последний известный тикет
double G_LastSLlevel = 0.0; //Последний известный уровень SL
double G_LastTPlevel = 0.0; //Последний известный уровень TP
//——————————————————————————————————————————————————————————————————————————————
void  OnTradeTransaction (const MqlTradeTransaction &trans,   // структура торговой транзакции
                          const MqlTradeRequest     &request, // структура запроса
                          const MqlTradeResult      &result)  // структура ответа
{
  if(trans.type == TRADE_TRANSACTION_DEAL_ADD)
  {
    if(PositionsAny (G_Symbol))
    {
      G_LastSLlevel = GetSLlevel (G_Symbol);
      G_LastTPlevel = GetTPlevel (G_Symbol);
      Print ("SLlevel: " + G_LastSLlevel);
      Print ("TPlevel: " + G_LastTPlevel);
    }
    
    if(trans.deal != G_LastTicket)
    {
      if(trans.price == G_LastSLlevel)
        Print ("Сработал SL");
        
      if(trans.price == G_LastTPlevel)
        Print ("Сработал TP");
    }
  }
}
 
prostotrader:
Try it...
I'll give it a try sometime for sure. I'll give it a try sometime. Thanks. I'm busy with other tasks at the moment.
 
prostotrader:

What's wrong with this method?

Should storemy_order_ticket
 
fxsaber:
You have to keepmy_order_ticket

Do you even know what you are talking about?

my_order_ticket - this order has a place to live if you have

and you are obliged to keep them.

 
fxsaber:
You have to storemy_order_ticket
Not only that.
 
Anatoli Kazharski:
I'll give it a try sometime. Thank you. (chuckles) I'm busy with other tasks at the moment.
Good luck with the code!
 
Andrey Dik:
Not only that.

Yes, it is actually proposed to maintain and store the actual environment itself, comparing it with what OnTradeTransaction produces.

This is not a solution.

 
fxsaber:

Yes, it is actually proposed to maintain and store the actual environment itself, comparing it with what OnTradeTransaction produces.

This is not a solution.

You're just not following the topic closely. :)

The original topic starter wrote:

"How do I know inOnTradeTransaction() that SL/TP has triggered? "

What should be the solution?

You can not remember or check anything at all, except the position itself, provided that

You did not operate any other orders

case TRADE_TRANSACTION_DEAL_ADD:
  if (!PositionSelect(Symbol())
  {
   //Сработал SL или TP

  }
break;
 
prostotrader:

You're just not following the topic closely. :)

The original topic starter wrote:

You are the one who is rather inattentive, I am notthe topic starter.

You should also show code like this:

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

Well, what's the big deal - who needs it, finish it himself, do not like it - there is a job! Is it so?

Reason: