Notification of closed orders

 
Hi,

Is there any way for an expert to get a notification call when an order closes due to TP or SL, or do I have to just poll all my open orders at each tick if I want to act on the close?

Many thanks,
Kevin
 
BrandyLove:
Is there any way for an expert to get a notification call when an order closes due to TP or SL, or do I have to just poll all my open orders at each tick if I want to act on the close?
The latter only.
 
actually you can use OrderComment() command to check whether such an order closed due to TP or SL.
 
Thanks for the info
 
BrandyLove:
Thanks for the info

 
Hello
 
There is possible:
 1. check IN THE HISTORY the comment of SL or TP
 2. check IN THE HISTORY  if ClosePrice==TP  or  ClosePrice==SL
Here is more info:
 
  http://forum.mql4.com/8108
 
 
THX to WACKENA FOR THE HELP
 
 
master
 
If you're going to use the close price to determine whether the SL or TP was hit, it would be better to either compare the difference.. as in, it's a stop loss if abs( ClosePrice - StopLoss ) < abs( ClosePrice - TakeProfit ), or check whether the profit is positive or negative. (The latter assuming it's not a trailing stop!) This will account for the possibility of slippage, which would cause the close price equality test to fail.


Cheers,
Kevin
 
BrandyLove:
If you're going to use the close price to determine whether the SL or TP was hit, it would be better to either compare the difference.. as in, it's a stop loss if abs( ClosePrice - StopLoss ) < abs( ClosePrice - TakeProfit ), or check whether the profit is positive or negative. (The latter assuming it's not a trailing stop!) This will account for the possibility of slippage, which would cause the close price equality test to fail.


Cheers,
Kevin


 
HELLO
 
WHAT YOU THINK ABOUT COMPERING  OrderClosePrice() AND OrderOpenPrice():
 
OrderSelect(HistoryTotal(),SELECT_BY_POS,MODE_HISTORY); 
{
 
if(OrderType()==OP_BUY && OrderClosePrice()  >   OrderOpenPrice() ) 
....TP...
else
....SL...
 
 
if(OrderType()==OP_SELL && OrderClosePrice()  <    OrderOpenPrice() ) 
....TP...
else
....SL...
 
 
}
 
master001:
 
HELLO
 
WHAT YOU THINK ABOUT COMPERING  OrderClosePrice() AND OrderOpenPrice():
 ...


That's okay if you know that the stop losses always lose money. But then, I think you can just check profit >= 0 and then you don't need to test whether it's long or short since that logic would apply equally well to either. However, SL doesn't necessarily lose money if you're trailing it, so it's better to test the distance from the SL and TP level - the closer one is obviously the one that was hit. See the math in my above message.

It may also be possible to use the comment, but I'm not sure exactly how that works.
Reason: