Is there a way to be notified in my EA that an order was closed by SL or TP?

 

Hi all, besides iterating through the OrderHistory(), Is there a way to be notified in my EA that an order was closed by SL or TP?

Is there a callback function where my EA is notified of such events?

void onClosedOrderEvent (double profit, datetime orderClosedTime);

 

No. You need to read through the order history pool.

CB

 
Hi all. Manage to solve my problem with this.
 
So are you triggering an event based upon a change in the number of open orders? CB
 
Yes. Use GlobalVariable to persist the last total order.
 

How do you handle the possibility of someone opening or closing an order manually? Or is it sufficient to assume this won't happen?

How do you know the change in order total is due to an order that this particular EA cares about? Or are you happy to limit yourself to one EA per trading account.

Do you not need to know further detail about the specific order which has been closed due to SL or TP?

CB

 

i assume (according to the post the OP has written in the comment section of the article) trough MagicNumber...

int start()
{
    CheckEvents( MagicNumber );
    OrderInfoObj orderInfo;
    if ( (orderInfo = eventBuyClosed_SL) > 0 )
        Alert( Symbol(), ": Buy position was closed by StopLoss!", orderInfo.ticket, orderInfo.closedPrice ... );
    ....
return(0); 

}