Download MetaTrader 5

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

To add comments, please log in or register
How to earn at MQL5.community? Come and find out!
Icham Aidibe
10043
Icham Aidibe 2015.06.08 14:58 

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) ?

Roberto Jacobs
46456
Roberto Jacobs 2015.06.08 15:20  
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())
Icham Aidibe
10043
Icham Aidibe 2015.06.08 16:17  
3rjfx:

In my opinion:

Yep. Thanks.
Alain Verleyen
Moderator
30735
Alain Verleyen 2015.06.08 18:05  
How to detect order close by stoploss? - MQL4 forum
  • www.mql5.com
How to detect order close by stoploss? - MQL4 forum
Osama Shaban
1448
Osama Shaban 2015.06.08 23:07  
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 >", ... , ...
Jose Miguel Soriano
4963
Jose Miguel Soriano 2015.06.09 12:26  
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);
}
To add comments, please log in or register