order accounting

 

Dears

how to get the total of orders by orderType and OrderSymbol.

and is there a way to know if the order close or not (orderClose event)

 

any help 

 
happylife:

Dears

how to get the total of orders by orderType and OrderSymbol.

and is there a way to know if the order close or not (orderClose event)

Loop through the orders and count the ones of the type you are interested in. 

Only orders selected by tick or from the history pool might be closed,  all from the history pool will be closed  . . .  if the OrderCloseTime() is not 0 the order is closed.

 
RaptorUK: Only orders selected by ticket
happylife: how to get the total of orders by orderType and OrderSymbol.
Example of a orderSelect loop, filtering by magic number and pair
// extern int     Magic.Number.Base          = ...
// int      magic.number.max;                   // Export to OpenOrder/MySelect
// string   market.pair;                        // Export to OpenOrder/MySelect
// int init(){
//    market.pair       = Symbol();
//    magic.number.max  = Magic.Number.Base + MN.COUNT - 1;
// }
bool     MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES){
   if(!OrderSelect(iWhat, eSelect, ePool) )  return (false);
   int      mn = OrderMagicNumber();
   if(mn < Magic.Number.Base              )  return (false);
   if(mn > magic.number.max               )  return (false);
   if(OrderSymbol()      != market.pair   )  return (false);
   if(ePool != MODE_HISTORY               )  return (true);
   return(OrderType() <= OP_SELL);  // Avoid cr/bal forum.mql4.com/32363#325360
                                    // https://forum.mql4.com/30708
                                    // Never select canceled orders.
}
int      MyOrdersTotal(int op=-1, int ePool=MODE_TRADES){   #define OP_ALL -1
   if(ePool == MODE_TRADES)     int    iPos = OrdersTotal()        - 1;
   else                                iPos = OrdersHistoryTotal() - 1;
   for(int nOrders=0; iPos >= 0; iPos--) if(
      MySelect(iPos, SELECT_BY_POS, ePool)) if(
      op == OP_ALL || op == OrderType()
   )  nOrders++;
   return(nOrders);
}
 
WHRoeder:
Example of a orderSelect loop, filtering by magic number and pair
WHRoeder:
Example of a orderSelect loop, filtering by magic number and pair

thanks a lot, but i have one more thing.

i want to open a second order after the first order open in some condition, like this

double DealAsk1 = 0; 

int Deal11=0; 
int Deal22=0;

int start()
  { 

if(OrdersTotal()==0)
{
    DealAsk1 = 0;
    Deal11=0; 
    Deal22=0; 

    Deal11=OrderSend(Symbol(),OP_BUY,Lots,Ask,40,0,Ask+50*Point,Comments,10,0,Green);
    DealAsk1 = Ask;
}
if (Ask<=DealAsk1-50*Point)
{
    if (Deal22==0)
    {

        Deal22=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,Ask+50*Point,Comments,16384,0,Red);
        OrderModify(Deal11,Ask,0,Ask+Pip50_500*Point,0,Green);
     }
}

 }

its work fine, but if you close  the MetaTrader the EA ignore the DealAsk1 value and deal with it as ZERO value.

Any Help