When you scan the orders collection by the "for" loop, you have to check if the selected order is on the current symbol, otherwize you will quickly do some greek salad...
PHP Code:
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if(OrderSymbol()==Symbol()) TrailingPositions();
}