ObjectName() does not work as per the object list index

 

Problem

ObjectName() does not work as per the object list index.

I wrote a script to display the names of all objects on the chart in the new order on the terminal, referring to the documentation of ObjectName(), but it does not work in the order of the object list.


What I want to do

I want to know how to get ObjectName() to return object names that correspond to the order of the object list.


What I did

  1. Manually created objects
  2. Detected the object creation event from 1. and output the name of the created object to the terminal
  3. Confirmed that objects are listed in the order they were created in the object list (Ctrl + B)
  4. Executed the code to display the object names in reverse order of creation to the terminal
  5. Confirmed that the order of the object names displayed in 3. on the terminal is different from the object list (in neither ascending nor descending order)

Codes

void OnStart()
{
    Print("---------------------");
    int num = ObjectsTotal(0, -1, -1);
    for (int i = 0; i < num; i++)
    {
        Print(ObjectName(0, i, -1, -1));
    }
}


Solution

A screenshot (screen.png) is also attached.
Please let me know your guidance. Thank you for your assistance.

Files:
screen.png  54 kb
 
vows.ingenue_0j but it does not work in the order of the object list.
You are reading the list from the bottom up.
 
William Roeder #:
You are reading the list from the bottom up.

Thank you for your reply.

Yes, since it was originally displaying in reverse order, that is not a problem.

I also asked the same question on a Japanese forum, and another person informed me that ObjectName() is designed to display object names in sequence for each type of object, and to meet my intention, I would need to prepare a separate array to process it.

 
Yochi #: I would need to prepare a separate array to process it.

Why? ObjectName(i) is your array.

 
William Roeder #:

Why? ObjectName(i) is your array.

Because using ObjectName() alone does not allow you to obtain the list of object names in the order they were created.

Pressing the Backspace key allows you to delete the created objects in reverse order.
I want to handle this order of objects in mql5.

Since I thought it would be disrespectful not to try your suggestion,
I read the list from top to down, but the terminal display still did not show the objects in the order they were created.(Attached file, screen2.png)

The code is as follows.
void OnStart()
{
    Print("---------------------");
    int num = ObjectsTotal(0, -1, -1);
    for (int i = num - 1; i >= 0; i--)
    {
        Print(ObjectName(0, i, -1, -1));
    }
}
Files:
screen2.png  39 kb
 
I believe the list you see in Objects List of metatrader are not sorted according to creation date/time.
 
Yochi #: Because using ObjectName() alone does not allow you to obtain the list of object names in the order they were created.
Correct. It is ObjectName and your loop that does. If you want to see the opposite order, change your loop.
Reason: