ObjectType() is always -1 although it is an existing object?!?

 

Hi guys,

I open some charts, draw some lines and rectangles and then I drag the following script into one of the charts. 

This script should print the names and types of the objects found in all charts. Interestingly, the names are all correct but the object types are all -1 except the objects of the chart I drag the script into.

But why?!?! How can the name be correct and the object type is -1?

This is the script:

for (long chartID=ChartFirst(); chartID!=-1; chartID=ChartNext(chartID)) {
   string symbol=ChartSymbol(chartID);
   for (int i=0; i<ObjectsTotal(chartID); i++) {
      string objName=ObjectName(chartID, i);
      int objType=ObjectType(objName);
      Print(symbol+" "+objName+" "+objType);
   }
}
 
Marbo:

Hi guys,

I open some charts, draw some lines and rectangles and then I drag the following script into one of the charts. 

This script should print the names and types of the objects found in all charts. Interestingly, the names are all correct but the object types are all -1 except the objects of the chart I drag the script into.

But why?!?! How can the name be correct and the object type is -1?

This is the script:

Should use 

int objType = ObjectGetInteger(ChartID,objName,OBJPROP_TYPE);

instead.

 
Seng Joo Thio:

Should use 

instead.

That works perfect! Thank you very much!