double OOP,SL;
int b=0,s=0,tip,TicketB=0,TicketS=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if(OrderSymbol()==Symbol())
{
tip = OrderType();
OOP = NormalizeDouble(OrderOpenPrice(),Digits);
if(tip==OP_BUY)
{
b++;
TicketB=OrderTicket();
if(Stoploss!=0 && Bid<=OOP - Stoploss * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;}
if(Takeprofit!=0 && Bid>=OOP + Takeprofit * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),slippage,clrNONE)) continue;}
if(TrailingStop>0)
{
SL=NormalizeDouble(Bid-TrailingStop*Point,Digits);
if(SL>=OOP+TrailingStart*Point && (TrallB==0 || TrallB+TrailingStep*Point<SL)) TrallB=SL;
}
}
if(tip==OP_SELL)
{
s++;
if(Stoploss!=0 && Ask>=OOP + Stoploss * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;}
if(Takeprofit!=0 && Ask<=OOP - Takeprofit * Point) {if(OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),slippage,clrNONE)) continue;}
TicketS=OrderTicket();
if(TrailingStop>0)
{
SL=NormalizeDouble(Ask+TrailingStop*Point,Digits);
if(SL<=OOP-TrailingStart*Point && (TrallS==0 || TrallS-TrailingStep*Point>SL)) TrallS=SL;
}
}
}
}
}