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

 

Please advise how to organise or which way to look:

Here, in order not to perform the calculation of bars, buffers were invented. With every new tick only the last bar is checked (as I understand it). When a new bar appears, calculation will start with this bar only.

Thanks to the buffer, the lines are not re-drawn on the whole history, but an additional segment is added to the last edge. There are 8 buffers in total.

What if I need to do a calculation a hundred times (let's say 100 times to draw a line, changing only one variable), and then draw the best result. And at a new tick or timer do the same thing, but with the existing "history" of results (drawings). Where and how do I store this information, so that I don't have to recalculate the entire history?

Or, more simply, how to increase the number of buffers in the indicator? Perhaps write them separately to a file? What is better
 
Ivan Butko #:

Please advise how to organise or which way to look:

Here, in order not to perform the calculation of bars, buffers were invented. With every new tick only the last bar is checked (as I understand it). When a new bar appears, calculation will start with this bar only.

Thanks to the buffer, the lines are not re-drawn on the whole history, but an additional segment is added to the last edge. There are 8 buffers in total.

What if I need to do a calculation a hundred times (let's say 100 times to draw a line, changing only one variable), and then draw the best result. And at a new tick or timer do the same thing, but with the existing "history" of results (drawings). Where and how do I store this information, so that I don't have to perform these calculations over the entire history?

Or, to put it more simply, how do I increase the number of buffers in an indicator? Maybe write separately to a file? What is the best way to

The indicators have 512 buffers.

 
Artyom Trishkin #:

There are 512 buffers in the indicators.

Oh, wow. Thank you. I must have been looking in the wrong place. I'll keep trying.

 
MrBrooklin #:

ERROR FOUND BY MYSELF!!!

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

It won't be useful for anybody. There are gross errors in your code. And there is no sense in correcting them.

You don't even bother to learn the basics of the language and try to write something.

Either take it seriously or give it up.

 
Koldun Zloy #:

No one can use it. There are gross errors in your code. And there is no point in correcting them.

You don't even bother to learn the basics of the language, and you're trying to write something.

Either get serious or give it up.

Good morning! Yes, you are absolutely right. We need to give up this pointless business of going to the

Any questions from newbies on MQL4 and MQL5, help and discussion on algorithms and codes

and wait for help here.

Regards, Vladimir.

 
MrBrooklin #:
Good morning! Yes, you are absolutely right. You need to quit this pointless business, which is to apply to the

Any questions from newbies on MQL4 and MQL5, help and discussion on algorithms and codes

and wait here for help.

Sincerely, Vladimir.

You're right, give it up.

You didn't even understand what I wrote in Russian.

Why do you want to get into programming?

 
Koldun Zloy #:

No one can use it. There are gross errors in your code. And there is no point in correcting them.

You don't even bother to learn the basics of the language, and you're trying to write something.

Either take it seriously or give it up.

Please explain what his mistakes are. Briefly, in a nutshell, what you should pay attention to. And if the code works, what are its "bugs"?

 
Ivan Butko #:

Please explain what his mistakes are. Can you briefly summarise what to pay attention to? And, if the code works, what would be its "bugs"?

//+------------------------------------------------------------------+
//| Функция 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; // значит это чужой ордер, поэтому возвращаем значение ложь

From the documentation... the inbox should have a ticket, not an index

bool  OrderSelect( 
   ulong   ticket      // тикет ордера 
   );

If there are several orders for different symbols and the one we are looking for is the second in the list, we will not find it. Or there is only one magik, but we need to find it by another symbol, we will get an incorrect answer from the function...

 
Alexey Viktorov #:

from the documentation... the inbox should have a ticket, not an index

Thanks Alexey for the tip! Very bad influence on me from sitting at the computer at night. I thought I started with the order ticket yesterday and had already written a line in the code:

ulong  order_ticket=OrderGetTicket(i); // тикет ордера

and then "moved off" it.

Alexey, may this variant of code be acceptable?

//+------------------------------------------------------------------+
//| Функция 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(order_ticket==0)
         return false; // поэтому возвращаем значение ложь
      else // в противном случае
         return true; // возвращаем значение истина
     }
   /* если отложенный ордер уже есть и его мэджик совпадает с мэджиком нашего советника */
   if(OrderGetInteger(ORDER_MAGIC)==Magic_Number)
      return true;  // то возвращаем истину
   /* в противном случае, если отложенный ордер уже есть, но его мэджик не совпадает с мэджиком нашего советника */
   else
      return false; // значит это чужой ордер, поэтому возвращаем значение ложь
  }

I have not touched Magic yet because the code is intended for a one-character EA.

Regards, Vladimir.

 
MrBrooklin #:

Thank you, Alexei, for the tip! Very bad influence on me from sitting in front of the computer at night. I thought I started with the order ticket yesterday and already wrote a line in the code:

and then "moved off" it.

Alexey, may this variant of code be acceptable?

I have not touched Magic yet because the code is intended for a one-character EA.

Sincerely, Vladimir.

This approach is not acceptable for me. Add a check for Magik and a symbol, two lines of code and you will get a normal approach to solving a task in return. And if you ignore my principles, the code is not quite right.

This is more logical.

//+------------------------------------------------------------------+
//| Функция  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(order_ticket > 0)
         return true; // поэтому возвращаем истину
     }
      return false; // если нет открытого отложенного ордера…
  }

And in this code, all you have to do is replace the blank check

      if(order_ticket > 0)

to check for a magician and a character

      if(OrderGetString(ORDER_SYMBOL) == _Symbol && OrderGetInteger(ORDER_MAGIC) == Magic_Number)

and it's already a more universal function...

Reason: