int PositionTicketByLot(string f_symbol="",
int f_cmd=-1,
int f_magic=-1,
double f_lotMin=0,
double f_lotMax=0)
{
int f_ticket=-1;
double f_min=MathMin(NormalizeDouble(f_lotMin,2),
NormalizeDouble(f_lotMax,2));
double f_max=MathMax(NormalizeDouble(f_lotMin,2),
NormalizeDouble(f_lotMax,2));
for(int i=OrdersTotal()-1; i>=0; i--)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
int f_type=OrderType();
if(f_type==OP_BUYLIMIT || f_type==OP_SELLLIMIT ||
f_type==OP_BUYSTOP || f_type==OP_SELLSTOP)
continue;
if((f_symbol==OrderSymbol() || f_symbol=="") &&
(f_cmd==OrderType() || f_cmd==-1) &&
(f_magic==OrderMagicNumber() || f_magic==-1) &&
((f_min<=OrderLots() && OrderLots()<=f_max) || (f_lotMin==0 && f_lotMax==0)))
return OrderTicket();
}
return f_ticket;
}