OnTradeTransaction - page 3

 
Andrey Dik:
How do I know in OnTradeTransaction () that SL/TP has been triggered?

Use TRADE_TRANSACTION_DEAL_ADD

 
I believe the use of this function is mandatory, especially when executing orders, because trading functions do not return the result of opening a position, and it can only be traced through the ontranzation. In mt4 it's easier, of course
 
prostotrader:

Use TRADE_TRANSACTION_DEAL_ADD

Please expand the answer.

How do I know from this that the position has closed on SL/TP?

 
Andrey Dik:

Please expand the answer.

How do I know from this that the position has closed on SL/TP?

You have an open position.

If you are making any transactions with the position yourself, then you will have order tickers,

which you are operating on. But ifTRADE_TRANSACTION_DEAL_ADD is sent, but none of your

order is not shown in the message, then it means that you have triggered SL/TP

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

Added

If you use more than 1 EA,

then you need to do additional checks

on the magician and symbol

Added

But better not to use SL and TP at all, i.e. they are not output in trading

I use SL and TP in my system, and they are not output in the trading system, but stored on the server. I, for example, use SL and TP

pending orders. To be fair, it should be noted that

working with pending orders is much more time consuming

but more secure, because the orders are already in the trading system and

It is easy to track them by ticket.

 
prostotrader:

You have an open position.

If you are making any operations on the position yourself, then you will have order tickers,

which you operate on. But ifTRADE_TRANSACTION_DEAL_ADD is sent, but none of your orders

order is not shown in the message, then it means that the SL/TP

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

Added

If you use more than 1 EA,

then you need to do additional checks

on the magician and symbol

Added

But better not to use SL and TP at all, i.e. they are not output in trading

I use SL and TP in my system, and they are not output in the trading system, but stored on the server. I, for example, use SL and TP

pending orders. To be fair, it should be noted that

working with pending orders is much more time consuming

but more secure, because the orders are already in the trading system and

It is easy to track them by ticket.

Thanks, seems to understand now how to detect that SL/TP has triggered (but I must say it's still a rectal method, there should be an easier way).

And what about limit orders instead of SL/TP, isn't it fraught with danger if we're talking about withdrawing positions to LP? Limits will be visible in the stack and therefore easier to "eat". Although then it turns out that TP is more profitable to put as a limit order?

 
Andrey Dik:

Thanks, it seems to be clear now how to determine that SL/TP is triggered (but I must say it's still a rectal method, there must be an easier way).

And what about limit orders instead of SL/TP, isn't it fraught with danger if we're talking about withdrawing positions to LP? Limits will be visible in the stack and therefore easier to "eat". Although then it turns out that TP is more profitable to put as limiters?

---> there should be an easier way)

There should be, but there isn't, yet.

-->and therefore easier to "eat".

Then why are you setting SL/TP at all ?

Setting pending orders as SL/TP, you are 100% sure to be protected from slippage

and failure to trigger.

 
prostotrader:

By setting pending orders as SL/TP you are 100% sure to be protected from slippage

and not working.

Limit order can be rejiggered. SL is identical to a stop pending order.
 
If the SL or TP slips, then the price of the trade triggering the stop will not match the corresponding SL or TP price of the position, then how do you know what triggered the SL or TP (both SL and TP can close in profit or loss - you cannot tell from this by profit)?
 

It's as if both of you have never really traded....

--->Limit can be redirected. SL is identical to a stop loss order.

You will be notified of this "accident", whereas any other orders (stored on the server) are not predictable at all.

--->If the SL or TP slips, ....

Everything can be found out, it pays to think a bit and read carefully what is being written to you.

Added

All my statements apply ONLY to stock trading.

 
prostotrader:

It's as if both of you have never really traded....

--->Limit can be redirected. SL is identical to a stop loss order.

You will be notified of this "accident", whereas any other orders (stored on the server) are not predictable at all.

--->If the SL or TP slips, ....

Everything can be found out, it's worth a little thought and to read carefully what is written to you.

I've never handled OnTradeTransaction () event before, it wasn't necessary because there was no need to consider what triggered it in trading logic. SL or TP. Do you think it shows my trading experience?)))

prostotrader:

Everything can be found out, it's worth a little thought and careful reading of what is written to you.

I read very carefully, but I don't see anyone giving a sensible answer in the form of a working code. Or is it a fucking secret and great sorcery - secret knowledge and the ability to determine what worked?