Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1913

 
Alekseu Fedotov #:

The point is only one, so that the ChartSetSymbolPeriod() function is not pulled unnecessarily;

In principle, yes. But the question was about error presence, not about expediency of this condition...

 

Good afternoon, dear developers!

I am faced with the need to group orders to work with each group separately (closing, topping up, etc.). I think the task is not too difficult, but I have no idea how to solve it. I have a very unclear idea, that's all. No one has faced such a problem? Grouping may be done in any way(global variables terminal, comments, etc.). I would be grateful for any help.

 
AMarkov (global variables terminal, comments, etc.). I would be grateful for any help.

Why do not you want to use Magik? Because there may be more than one magician in one EA...

 
Magik
Alexey Viktorov #:

Why isn't a magician suitable? After all, there can be more than one magician in one councillor...

Magik is also suitable. I assume that all these options will have almost the same algorithm. So, it does not matter. The main thing is to find the solution).

 
AMarkov #:
Magik

Magik is also suitable. I assume that all these options will have almost the same algorithm. So it's all the same. The main thing is to find a solution).

Of course the solution is the same. Determine the criterion by which the order belongs to this or that group and identify it according to that criterion...
 
Alexey Viktorov #:
Of course the solution is the same. You define the criterion according to which the order belongs to this or that group and identify it according to this criterion...

Thank you for your participation. The mission statement is clear to me. I'm stuck with the implementation...

Tried it with the comments. Up to the second group it numbers correctly. On the third it returns one for the comment, although the first group is still on the market. The idea is not to multiply numbers, but to take the vacated ones. I hope I explained it clearly).

for(int a=1; a<10; a++)

{

comment=";

for(int i=0; i<OrdersTotal(); i++)

{

if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

{

if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)

{

//Print(OrderComment();

if(OrderComment()==IntegerToString(a)) continue;

else

{

comment=IntegerToString(a);

break;

}

}

}

}

if(comment!="") break;

}

if(CountOfBuy(magic)<1 && CountOfSell(magic)<1) comment="1";

 
Anatoliy Markov #:

Thank you for your participation. The mission statement is clear to me. I'm stuck with the implementation...

Tried it with the comments. Up to the second group it numbers correctly. On the third it returns one for the comment, although the first group is still on the market. The idea is not to multiply the numbers, but to take the vacated ones. I hope I explained it clearly).

Not quite clear, but still use the button to insert code


or ALT+s

 
void OnTick()
{
  //---
    
    for(int a=1; a<10; a++)
     {
       comment="";
       for(int i=0; i<OrdersTotal(); i++)
         {
          if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
            {
             if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
               {    
                  if (OrderComment()==IntegerToString(a)) continue; 
                  else
                  {
                   comment=IntegerToString(a);
                   break;                  
                  } 
               }
            } 
         } 
        if(comment!="") break; 
     }
    if (CountOfBuy(magic)<1 && CountOfSell(magic)<1) comment="1";
  //---
}
Да, так более информативно. Т.е. этот незамысловатый модуль должен давать коммент для 
последующего присвоения ордеру. Когда открыта группа с комментом 1, он дает коммент 2 (это правильно). 
Когда открыта 2-я группа, опять дает 1. Не могу понять.
 

Good evening everyone!

I've written a function that determines if a pending order is already set, but the function doesn't work for some reason. Can you please tell us where the error is? Sincerely, Vladimir.

//+------------------------------------------------------------------+
//| Функция IsMainPendingOrder (установлен отложенный ордер):        |
//| возвращает истину, если в советнике уже установлен отложенный    |
//| ордер, в противном случае возвращает ложь.                       |
//| Применим для функции с типом данных bool, чтобы хранить          |
//| логические значения true (истина) или false (ложь).              |
//+------------------------------------------------------------------+
bool IsMainPendingOrder()
  {
   int orders_total=OrdersTotal(); // количество установленных отложенных ордеров
//--- перебираем все установленные отложенные ордера
   for(int i=orders_total-1; i>=0; i--)
     {
      ulong  order_ticket=OrderGetTicket(i); // тикет ордера
      /* если отложенного ордера нет, значит и у нашего советника отложенного ордера нет */
      if(OrderSelect(i)==false)
         return false; // поэтому возвращаем ложь
     }
   /* если отложенный ордер уже есть и его мэджик совпадает с мэджиком нашего советника */
   if(OrderGetInteger(ORDER_MAGIC)==Magic_Number)
      return true;  // то возвращаем истину
   /* в противном случае, если отложенный ордер уже есть, но его мэджик не совпадает с мэджиком нашего советника */
   else
      return false; // значит это чья-то чужая позиция, поэтому возвращаем ложь
  }
 
MrBrooklin a pending order is already set, but the function doesn't work for some reason. Can you please tell us where the error is? Sincerely, Vladimir.

I HAVE FOUND THE ERROR MYSELF!!!

Here is a normally working code. May be useful for someone. Regards, Vladimir.

//+------------------------------------------------------------------+
//| Функция IsMainPendingOrder (установлен отложенный ордер):        |
//| возвращает истину, если в советнике не установлен отложенный     |
//| ордер, в противном случае возвращает ложь.                       |
//| Применим для функции тип данных bool, чтобы хранить              |
//| логические значения true (истина) или false (ложь).              |
//+------------------------------------------------------------------+
bool IsMainPendingOrder()
  {
   int orders_total=OrdersTotal(); // количество установленных отложенных ордеров
//--- перебираем все установленные отложенные ордера
   for(int i=orders_total-1; i>=0; i--)
     {
      ulong  order_ticket=OrderGetTicket(i); // тикет ордера
      /* если отложенного ордера нет, значит и у нашего советника отложенного ордера нет */
      if(OrderSelect(i)==false)
         return true; // поэтому возвращаем значение истина
      else // в противном случае
         return false; // возвращаем значение ложь
     }
   /* если отложенный ордер уже есть и его мэджик совпадает с мэджиком нашего советника */
   if(OrderGetInteger(ORDER_MAGIC)==Magic_Number)
      return true;  // то возвращаем истину
   /* в противном случае, если отложенный ордер уже есть, но его мэджик не совпадает с мэджиком нашего советника */
   else
      return false; // значит это чужой ордер, поэтому возвращаем значение ложь
Reason: