Determining when Stop Loss is hit

 

How can an EA know when a position was closed by the stop loss?

I need some sample code or location where to find it.

 

SR

You would need to look at your Order History, something like this as a starting point

int cnt;
//

cnt=OrdersHistoryTotal()-1;
//
//

while (cnt>=0)
{
if (OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY())
  {
   if (OrderStopLoss() == OrderClosePrice()) Print("This Order closed by StopLoss: ", OrderTicket());


   cnt--;
  }
}

but this doesnt account for Slippage...

Good Luck

-BB-

 
[sl] shows up in the comment, check for that too
 
phy wrote >>
[sl] shows up in the comment, check for that too

DOH!

if (StringFind(OrderComment(), "[sl]", 0)!=-1) Print("This Order closed by StopLoss: ", OrderTicket());

Thanks Phy, that handles Slippage too :)

-BB-

Reason: