double buy_last_price=0;
double sell_last_price=0;
for(int ot=OrdersTotal()-1;ot>=0;ot--) {
if(!OrderSelect(ot,SELECT_BY_POS)) continue;
if(OrderSymbol()!=_Symbol) continue;
if(OrderMagicNumber()!=magic) continue;
if(OrderType()==0 && (OrderOpenPrice()<buy_last_price || buy_last_price==0)) buy_last_price=OrderOpenPrice();
if(OrderType()==1 && OrderOpenPrice()<sell_last_price) sell_last_price=OrderOpenPrice();
}
if(Ask <= buy_last_price - step*_Point) {
// можно купить
}
if(Bid>=sell_last_price + step*_Point) {
// можно продать
}
step и magic заменить на свои