int count = 0; for (int i = OrdersHistoryTotal() - 1; i >= 0; i--) { if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol() == Symbol()) { if (count == 1) { //Action break; } count++; } } }