When a deal is closed by hitting a SL ....

 

Hi,

I'd like to know when a deal is closed by hitting a SL how to detect it ? By browsing the history I can know if the deal has been closed or not, but how to read the way the deal is closed (sl hit) ?

 
Icham Aidibe:

Hi,

I'd like to know when a deal is closed by hitting a SL how to detect it ? By browsing the history I can know if the deal has been closed or not, but how to read the way the deal is closed (sl hit) ?

In my opinion:

if(OrderClosePrice() == OrderStopLoss())
 
3rjfx:

In my opinion:

Yep. Thanks.
 
How to detect order close by stoploss? - MQL4 forum
  • www.mql5.com
How to detect order close by stoploss? - MQL4 forum
 
bool LastClosedTrade(){ 
   int cnt, total; 
   total = OrdersHistoryTotal(); 
   for(cnt=0;cnt<total; cnt++){ 
      OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY); 
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC && OrderClosePrice()==OrderStopLoss()){
         return(true);
      }
   }
   return(false);
}
But you must put many things into considerations, like case of OP_BUY and OP_SELL order types and if price went more points that it should be "< and >", ... , ...
 
Icham Aidibe:

Hi,

I'd like to know when a deal is closed by hitting a SL how to detect it ? By browsing the history I can know if the deal has been closed or not, but how to read the way the deal is closed (sl hit) ?

//-------------------------------- ES CIERRE POR SL ----------------------------------------------
bool esCierreSL(int ind, int modoInd= SELECT_BY_TICKET)
{
    bool resp= OrderSelect(ind, modoInd, MODE_HISTORY)? (StringFind(OrderComment(), "[sl]", 0)>-1): false;
    return(resp);
}
Reason: