waza123:
Is there a handle ?
onPositionClose(){
// do something
}
Handle which will check, when broker closing the position by SL or TP, the trigger will launch onPositionClose function and give me the position info
In case you want to identify a position closure, you may use, for instance
if(!PositionSelect(_Symbol)) { Print("Position was closed."); }
inside OnTrade() the event handler.
Regards,
Malacarne
Malacarne:
this is hack, and does not give me info that position for that symbol was opened.
In case you want to identify a position closure, you may use, for instance
inside OnTrade() the event handler.
Regards,
Malacarne
waza123:
this is hack, and does not give me info that position for that symbol was opened.
You asked about a position being closed, not opened...
this is hack, and does not give me info that position for that symbol was opened.
You should use OnTradeTransaction event. The question was discussed and sample code provided here - https://www.mql5.com/en/forum/11996

Detect stop trigger in OnTradeTransaction backtest
- www.mql5.com
Unfortunately, i get only DEAL_ENTRY_IN provided by MqlTradeTransaction passed to OnTradeTransaction. - - Category: technical indicators
On tradeTransaction is the way to go ;
void OnTradeTransaction(const MqlTradeTransaction &trans, const MqlTradeRequest &request, const MqlTradeResult &result) { if(trans.symbol!=symbol) return; if(trans.type != TRADE_TRANSACTION_DEAL_ADD) return; if(!PositionSelect(symbol)) // position closed {} }
it is definitively a PositionClosed event trap.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Is there a handle ?
onPositionClose(){
// do something
}
Handle which will check, when broker closing the position by SL or TP, the trigger will launch onPositionClose function and give me the position info