handle onPositionClose

To add comments, please log in or register
waza123
117
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

Rodrigo Malacarne
Moderator
8047
Rodrigo Malacarne  
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 

waza123
117
waza123  
Malacarne:

In case you want to identify a position closure, you may use, for instance

inside OnTrade() the event handler.

Regards,
Malacarne 

this is hack, and does not give me info that position for that symbol was opened.
Rodrigo Malacarne
Moderator
8047
Rodrigo 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...
Stanislav Korotky
22194
Stanislav Korotky  
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
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
galafron
138
galafron  

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.

To add comments, please log in or register