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

 
Forexman77:

Reworked your EA a bit, comments in the code. Pay attention to the formation of signal and stop. I put them especially without thinking. Change it to your taste if necessary.

Files:
 
artmedia70:
Well, the t++ kind of works either way


The only option is this?

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
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++;
          t++;
      }
      else if (OrderType() < 2)
          t++;
      else 
      {
         Print("Позиций в рвнке нет!");
      }
      
      pr ("FindOrders(): " + "t = " + t);
      pr ("FindOrders(): " + "p = " + p);
   }
}

It doesn't look like much. It's not optimised. The repetition of t++ is not happy...

 
hoz:


The only option is this?

It doesn't look like much. It's not optimised. The repetition of t++ is not happy...

And why would you want to increase t in any case ? In fact, what is there anyway:

if (OrderType() > 1 && OrderType() < 6)
      {
          p++;
          t++;
      }
      else t++;

If the order type is greater than 1 and less than 6, increase p, increase t

Otherwise (even if the order type is==6), we again increase t

It is strange, isn't it?

 
artmedia70:

Why would you want to increase t anyway? In fact, what is there anyway:

If the order type is higher than 1 and lower than 6, we increase p, increase t

Otherwise (even if the order type==6) we again increase t

It is strange, isn't it?




While I was writing your comment, I had already rewritten mine. Above is the corrected version.
 
hoz:

While I was writing your comment, I had already rewritten mine. The above is the corrected version.
Why should I increase t if the order is pending and then increase t again if the next order is a market one?
 
Create an array of six elements. Pass it to the function by reference. Once an order has been selected and it fits all the filters (symbol, magik), increment the array cell addressed by the order type. After the function is running, you will have the number of orders sorted by their type in the array.
 
artmedia70:
And why should we increase t, if the order is pending, and then increase t again, if the next order is a market one?


t is the number of all the orders.

p - number of pending orders

If the condition:

if (OrderType() > 1 && OrderType() < 6)

is true, then both t and p are incremented, since any order of the type 2 to 5 is both a pending and a general order. Therefore both counters should be incremented. And if the condition is true:

else if (OrderType() < 2)

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.

 
artmedia70:
Create an array of six elements. Pass it to the function by reference. Once an order has been selected and it fits all the filters (symbol, magik), increment the array cell addressed by the order type. After the function is running, you will have the number of orders sorted by their type in the array.

I have already understood that the array is more preferable here))) Is there any inconsistency in the above variant? (Just for the sake of interest, everything seems to be clear now).
 
hoz:

That here the array will be preferable, I've already understood))) And in that variant, which I described above is inaccurate? (Just for the sake of interest. I think everything is clear already)

How about this?

//+-------------------------------------------------------------------------------------+
//| Поиск своих ордеров                                                                 |
//+-------------------------------------------------------------------------------------+
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);
}
 
hoz:

I've already understood that the array is preferable here))) And in that variant, which I described above is not accurate? (Purely for the sake of interest. I think everything is clear already)

Something like that is what I had in mind. So... the direction to think...

int i_magic=123;
int OrdersMassive[7];
//+----------------------------------------------------------------------------+
int start() {
   FindOrders(OrdersMassive);
   int i, num=0;
   for (i=0; i<=7; i++) {
      Print("Количество "+GetNameOP(i)+" = "+OrdersMassive[i]);
      num+=OrdersMassive[i];
      }
   Print("Всего ордеров = "+(num-OrdersMassive[6]));
   return(0);
}
//+----------------------------------------------------------------------------+
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;
      }
}   
//+----------------------------------------------------------------------------+
string GetNameOP(int op) {
   switch (op) {
      case OP_BUY      : return("Buy");
      case OP_SELL     : return("Sell");
      case OP_BUYLIMIT : return("Buy Limit");
      case OP_SELLLIMIT: return("Sell Limit");
      case OP_BUYSTOP  : return("Buy Stop");
      case OP_SELLSTOP : return("Sell Stop");
      case 6           : return("Неторговое изменение баланса");
      default          : return("Не знаю, чё за тип такой...");
   }
}
//+----------------------------------------------------------------------------+

And what you have there, I did not really look ...

Reason: