how can i find a specific magic_nub order by not using loop(for)

 

how can i find a specific magic_nub order by not using loop(for)

 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

int GetOrdersTotalByMagic(long const magic_number)
  {
   long order_ticket;
   int total=0;
//--- selection through the entire history
   HistorySelect(0,TimeCurrent());
//--- go through all pending orders
   for(int i=0;i<OrdersTotal();i++)
      if(order_ticket=OrderGetTicket(i))
         if(magic_number==OrderGetInteger(ORDER_MAGIC)) total++;
//---
   return(total);

 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

any include file(.MQH) have include above?

Documentation on MQL5: Trade Functions / HistorySelect
  • www.mql5.com
Trade Functions / HistorySelect - Documentation on MQL5
 

Two questions:

1. Don't you want a total for the current orders matching the condition? Why looking in the history?

2. If you want the volume for these orders, why not make a function like that, to be called only once , and modifications to the volume to be operated straight in a OnTrade event() ? 

 
TheEconomist:

Two questions:

1. Don't you want a total for the current orders matching the condition? Why looking in the history?

2. If you want the volume for these orders, why not make a function like that, to be called only once , and modifications to the volume to be operated straight in a OnTrade event() ? 

ok, I will made a function and use OrderSelect

input long order_magic=55555;

void OnTrade()
  {

   if(AccountInfoInteger(ACCOUNT_TRADE_MODE)==ACCOUNT_TRADE_MODE_REAL)
     {
      Alert("Script operation is not allowed on a live account!");
      return;
     }
//--- place or delete order
   if(GetOrdersTotalByMagic(order_magic)==0) 

   {
      //--- no current orders - place an order
      int res=SendRandomPendingOrder(order_magic);
      Print("Return code of the trade server",res);
     }
   else // there are orders - delete orders
     {
      DeleteAllOrdersByMagic(order_magic);
     }
  }
//+------------------------------------------------------------------+
//| receive the current number of orders with specified ORDER_MAGIC  |
//+------------------------------------------------------------------+
int GetOrdersTotalByMagic(long const magic_number)
  {
   long order_ticket;
   int total=0;
//--- selection through the entire history
   HistorySelect(0,TimeCurrent());
//--- go through all pending orders
   for(int i=0;i<OrdersTotal();i++)
      if(order_ticket=OrderGetTicket(i))
         if(magic_number==OrderGetInteger(ORDER_MAGIC)) total++;
//---
   return(total);
  }

 

after I look the mql5 reference

i find it is hard to find orders type, because need to have many lines of code

 

type=GetOrderType(HistoryOrderGetInteger(ticket,ORDER_TYPE));  

 

string GetOrderType(long type)
  {
   string str_type="unknown operation";
   switch(type)
     {
      case (ORDER_TYPE_BUY):            return("buy");
      case (ORDER_TYPE_SELL):           return("sell");
      case (ORDER_TYPE_BUY_LIMIT):      return("buy limit");
      case (ORDER_TYPE_SELL_LIMIT):     return("sell limit");
      case (ORDER_TYPE_BUY_STOP):       return("buy stop");
      case (ORDER_TYPE_SELL_STOP):      return("sell stop");
      case (ORDER_TYPE_BUY_STOP_LIMIT): return("buy stop limit");
      case (ORDER_TYPE_SELL_STOP_LIMIT):return("sell stop limit");
     }
   return(str_type);
  }