The main problems with the code, I think, were that it didn't take spread and stop level into account, and then that the stop-loss for the SELL was placed below the open price. The following is a rehash of the code resolving those problems.
PHP Code:
void AdjustingPendingOrders()
{
Print ( "Adjusting the MT pending orders" );
double spread = MarketInfo( Symbol(), MODE_SPREAD );
double level = MarketInfo( Symbol(), MODE_STOPLEVEL );
double offset = MathMax( spread, level );
double price = Bid - offset * Point;
double SL;
for ( int N = OrdersTotal() - 1; N >= 0; N-- ) {
if ( ! OrderSelect( N, SELECT_BY_POS, MODE_TRADES ) )
continue;
if ( OrderType() != OP_BUYSTOP && OrderType() != OP_SELLSTOP )
continue;
//---- working with pending orders only
//---- modifying
if ( OrderType() == OP_BUYSTOP ) {
SL = price - StopLoss * Point;
} else {
SL = price + StopLoss * Point;
}
OrderModify( OrderTicket(), price, SL, OrderTakeProfit(), 0, CLR_NONE );
}
}