Download MetaTrader 5

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

To add comments, please log in or register
Icham Aidibe
10815
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) ?

Roberto Jacobs
49166
Roberto Jacobs  
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
10815
Icham Aidibe  
3rjfx:

In my opinion:

Yep. Thanks.
Alain Verleyen
Moderator
35138
Alain Verleyen  
How to detect order close by stoploss? - MQL4 forum
  • www.mql5.com
How to detect order close by stoploss? - MQL4 forum
Osama Shaban
1584
Osama Shaban  
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
5084
Jose Miguel Soriano  
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