Questions from a "dummy" - page 32

 
tol64:
I pass these object properties explicitly (ANCHOR_RIGHT_UPPER, CORNER_RIGHT_UPPER):

I think I've got it. Did you show a sample function, not a working piece of code?

That's it, I'm taking the weekend off. Sorry for the interruption :)

 

A better version of this function, but something can be tweaked (in general, I would implement all this as an object, or several objects).

Although, you can put the function in a library and use it however you want.

bool Create_BMP_Label(long   chart_id,  // id графика
                      string bmp_nm,    // имя объекта
                      string bmp_path,  // путь к обекту
                      long   anchor,    // точка привязки
                      long   corner,    // угол привязки
                      int    x_dist,    // координата по шкале X
                      int    y_dist)    // координата по шкале Y
{
//----------------------------------------------------------------------------//
//Work variables
bool Result = true; //Returned importance
//----------------------------------------------------------------------------//

ResetLastError();

Result =  ObjectCreate(chart_id,bmp_nm,OBJ_BITMAP_LABEL,0,0,0); // создание объекта

  if(Result)
  {
  ObjectSetString(chart_id,bmp_nm,OBJPROP_BMPFILE,0,bmp_path);   // BMP файл
  ObjectSetInteger(chart_id,bmp_nm,OBJPROP_ANCHOR,anchor);       // установка точки привязки
  ObjectSetInteger(chart_id,bmp_nm,OBJPROP_CORNER,corner);       // установка угола привязки
  ObjectSetInteger(chart_id,bmp_nm,OBJPROP_XDISTANCE,x_dist);    // установка координаты X
  ObjectSetInteger(chart_id,bmp_nm,OBJPROP_YDISTANCE,y_dist);    // установка координаты Y
  ObjectSetInteger(chart_id,bmp_nm,OBJPROP_SELECTABLE,false);    // нельзя выделить объект, если FALSE
  ObjectSetString(chart_id,bmp_nm,OBJPROP_TOOLTIP,"\n");         // нет всплывающей подсказки, если "\n"
  }
//The execution errors checking
  if(GetLastError()!=0)
  {
  Result = false;
  }  
//----------------------------------------------------------------------------//
return(Result);
//----------------------------------------------------------------------------//
}
 
Interesting:

A better version of this function, but something can be tweaked (in general, I would implement all this as an object, or several objects).

Although, you can put the function in a library and use it however you want.



It's nice.)) And in the form of an object, what's the advantage, if you take this function as an example? So far, I have implemented everything in the form of functions. Maybe I'm going in the wrong direction and will have to redo everything later?
 
tol64:
(That's nice.)). What is the advantage of using this function as an object? For now I have implemented everything in the form of functions. Maybe I follow the wrong way and will have to redo everything later?

Well, why all of them. A function could be made more universal and packed into, say, a library.

Classes have advantages too, but these are tricks related to OOP (the main task will be to use the code in various projects without thinking about the implementation).

Example

As I see from the screenshot, you have something like an information panel (maybe some other functionality), so you can consider this panel as a number of unrelated objects (graphics, text, etc.), or you can view them as objects connected by one class. Thus, if you change one "input" parameter "Corner", this change will affect all that relates to the panel.

It is the same with the binding to the chart. By specifying a chart to the class, we indicate this chart to all objects controlled by the class as well.

 
Interesting:

Well, why all of them. A function could be made more universal and packed into, say, a library.

Classes have advantages too, but these are tricks of OOP (the main task will be to use the code in various projects without thinking about the implementation).

Example

As I see from the screenshot, you have something like an information panel (maybe some other functionality), so you can consider this panel as a number of unrelated objects (graphics, text, etc.), or you can view them as objects connected by one class. So if you change one "input" parameter "Corner", this change will affect all that relates to the panel.

I have the same problem with the binding to the chart. Once we indicate a chart to the class, we indicate this chart and all objects that this class controls.

You have a very remarkable ability. Explain everything very clearly in a couple of lines. Thank you. ))

After I get acquainted with all the functions I need and practice using them, I'll start to study the structures, classes and OOP. It's a pity that nature forces me to go to bed sometimes. I have to crawl away from the computer. ))

 

I have written this script:

bool del;

void OnStart()
  {
   long chart_id  = ChartID();
   int amount_obj = ObjectsTotal(chart_id,0,OBJ_LABEL);
   int i;
   
   Print("Всего объектов типа OBJ_LABEL: ",amount_obj);
   
   for(i=0; i<amount_obj; i++)
      {
       string name_obj = ObjectName(chart_id,i,0,OBJ_LABEL);
       del = ObjectDelete(chart_id,name_obj);
       
       if(del == false || GetLastError() != 0) Print(ErrorDescription(GetLastError()),", ",GetLastError());
       
       ChartRedraw();
      }
  }

Task: remove all objects of type OBJ_LABEL from the chart. But some are skipped and remain. An error is written in the logbook:

Please tell me how to do it correctly.

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Типы объектов
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Типы объектов
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы объектов / Типы объектов - Документация по MQL5
 
tol64:

I have written such a script:

The task: delete all objects of OBJ_LABEL type from a chart. But some of them are skipped and remain. An error is written in the log:

Please advise how to do it correctly.

It seems to me that the loop should be descending rather than ascending, although I haven't gone into details (but since MQL4 the deletion of orders has been done in a descending loop).

The trick is that if you start deleting from large indexes then the original list won't change, except for deleting selected item (from the tail of the list)...

 
Interesting:

It seems to me that the cycle should be descending rather than ascending, although I haven't gone into details (since MQL4, orders are deleted in a descending cycle).

The trick is that if we start deleting from a large index then the original list won't change, except for deleting a selected item (from the tail of the list)...

I have tried to start the cycle from the end:

   for(i=amount_obj-1; i>=amount_obj; i--)

Now there are no errors in log, but not a single object is deleted).

 
tol64:

Tried to start the cycle from the end:

Now there are no errors in the logbook, but no objects are deleted either.)

i>=0
 
tol64:

In quadruplet, I use this approach: all objects are groups, the name part is common in the group.

Deleting

// удаление по маске всех объектов индюка
   for (int i = ObjectsTotal() - 1; i >= 0; i--)
    {
      string name = ObjectName(i);
      if (StringFind(name, "sig_nal") == 0)
      {
         ObjectDelete(name);
      }
    }

for different groups

// удаление по маске всех объектов индюка
   for (int i = ObjectsTotal() - 1; i >= 0; i--)
   {
      string name = ObjectName(i);
      if (StringFind(name, "signal") == 0)
      {
         ObjectDelete(name);
      }
      else if (StringFind(name, "Asignal") == 0)
      {
         ObjectDelete(name);
      }
   }

and here function IgorM

***

( just in case ) Sorting by ObjectName(not sure if it is relevant for 5)

[ВНИМАНИЕ, ТЕМА ЗАКРЫТА!] Любой вопрос новичка, чтоб не захламлять форум. Профи, не проходите мимо. Без вас никуда. - MQL4 форум
  • www.mql5.com
[ВНИМАНИЕ, ТЕМА ЗАКРЫТА!] Любой вопрос новичка, чтоб не захламлять форум. Профи, не проходите мимо. Без вас никуда. - MQL4 форум