Object created but unable to Find

 

This script creates a Horizontal line object that actually shows on the chart.

If I display the Objects List, the object name is included in the list.

However when I loop through ObjectsTotal() the object name does not Print.

In addition, ObjectFind() also fails to locate the object. 

Any ideas to correct my coding problem ??

#property strict
void OnStart()
{
    string myObject = "newObject";
    Print("---myObject ",myObject); 
     
    ObjectCreate(myObject,OBJ_HLINE,0,0,MarketInfo(_Symbol,MODE_ASK)); 
       
    Print("---ObjectsTotal() ",ObjectsTotal());
       
    for(int i=ObjectsTotal(); i>0; i--)
        Print("---ObjectName(i) ",ObjectName(i));
    
    if(ObjectFind(myObject))
         Print("---object was found");
    else Print("---object not found");
  
}
 
michaelMNB:

This script creates a Horizontal line object that actually shows on the chart.

If I display the Objects List, the object name is included in the list.

However when I loop through ObjectsTotal() the object name does not Print.

In addition, ObjectFind() also fails to locate the object. 

Any ideas to correct my coding problem ??

for(int i=ObjectsTotal(); i>0; i--)

should be

for(int i=ObjectsTotal()-1; i>=0; i--)


Please read the documentation. ObjectFind does not return a bool, it returns the window.


In future please post in the correct section

I will move your topic to the MQL4 and Metatrader 4 section.

 

KW-- The solution works Great.

Sorry about posting to the wrong section, I'll be more careful in the future.

Again, thanks for your help.

Reason: