Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 121

 
r772ra:

How about this?

My version of the function is shorter ... :)

//+----------------------------------------------------------------------------+
void FindOrders(int &mass[]) {
   int i, t, k=OrdersTotal()-1;
   ArrayInitialize(mass,0);   
   for (i=k; i>=0; i--) {
      if (!OrderSelect(i,SELECT_BY_POS))  continue;
      if (OrderMagicNumber()!=i_magic)    continue;
      if (OrderSymbol()!=Symbol())        continue;
      t=OrderType();
      mass[t]=mass[t]+1;
      }
}   
//+----------------------------------------------------------------------------+
 
r772ra:

Maybe so.

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
void FindOrders(int& t, int& p)
{
   t = 0;
   p = 0;
 
   for (int i=OrdersTotal() - 1; i>=0; i--)
      {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderType() > 1 && OrderType() < 6)   p++;
      if (OrderType() < 6)  t++;
       }
  pr ("FindOrders(): " + "t = " + t);
  pr ("FindOrders(): " + "p = " + p);
}

It doesn't work either. I had a flaw there. It's like this now:

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
void FindOrders(int& t, int& p)
{
   t = 0;
   p = 0;
 
   for (int i=OrdersTotal() - 1; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      if (OrderType() > 1 && OrderType() < 6)
      {
          p++;
      }
      if (OrderType() < 6)
          t++;
      else 
      {
         pr("Позиций в рвнке нет!");
      }
      
      pr ("FindOrders(): " + "t = " + t);
      pr ("FindOrders(): " + "p = " + p);
   }
}

When there are no orders in the market, the counters don't go zero. This is bullshit. What is wrong here I do not know. I will look at what Artem has written.

 
hoz:

It's not working either. I had a flaw there. That's the way it is now:

When there are no orders in the market, the counters don't come up zero. This is bullshit. What is wrong here I do not know. I will look at what Artem has written.


Take this out of the loop.

pr ("FindOrders(): " + "t = " + t);
pr ("FindOrders(): " + "p = " + p);
I take it this is the output of the information.
 
r772ra:


Take this out of the loop

I take it this is the output of the information.


Right. (chuckles) Well, what happened to me. Some silly mistakes. I've been digging in C++ for a month. And now I have such silly mistakes in µl. My brain must be burnt out :(
 
In general, is it OK to search for orders on every tick? Or is it better to execute on every bar? I still don't have it in my head which is better in one case and which in the other.
 
hoz:
In general, is it OK to search for orders on every tick? Or is it better to execute on every bar? I still do not know what is better in one case and what is better in another.
If a position is closed within a bar during monitoring by the bar opening, the Expert Advisor will not know about the changes in the number of positions until the next bar opens.
 
hoz:


t is the number of all orders.

p is the number of pending orders

If the condition is true:

is true, then both t and p are incremented, since any order of the type 2 to 5 is both a pending order and an order. This means we should increment both counters. And if the condition is true:

Then there is no pending order but there is a market order. It means we will increase the t counter, i.e. the counter of the total orders number.

And if there is nothing, then we will print that there are no orders


t = OrdersTotal();

why count???? counted???

 

Hello! Looking for errors in this function.

The idea is that pending orders that have not opened should be deleted two days after they are placed.

min=1440;

if(OrdersTotal()<1)
{return;
 }
  for(int i=OrdersTotal()-1;i>=0;i--)
   {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
     {
      if(OrderSymbol()==Symbol())
       {
        if(OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
        {
          if(TimeCurrent()-OrderOpenTime()>min)            
            {
            OrderDelete(OrderTicket());
          return;
          }
        }
      }
    }
return;}
 
pako:



Thank you, pako.

 
skyjet:

Hello! Looking for errors in this function.

The idea is that pending orders that have not opened should be deleted two days after they are placed.

min=1440;

if (OrdersTotal()>0)
{  for (int i=OrdersTotal()-1; i>=0; i--)
   {  if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {  if (OrderSymbol()!=Symbol()) continue;
         if (OrderType()==OP_BUYSTOP || OrderType()==OP_SELLSTOP)
         {  if(TimeCurrent()-OrderOpenTime()>=min)
            {  OrderDelete(OrderTicket());
               return;
         }  }
}  }  }