for(int i=OrdersHistoryTotal()-1; i>=0;i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { if(OrderSymbol()==Symbol() && OrderMagicNumber()==MY_MAGIC_NUMBER_HERE) { if (StringFind(OrderComment(), "[sl]", 0)!=-1) { Print("Order#",OrderTicket()," Closed by SL"); break; } } } }