Why does ObjectFind() never find my object??

 

Hi everyone,

Why does ObjectFind() never find my object??

Thanks!

#property strict

double t_SL[1];

int OnInit()
  {
   t_SL[0]= Bid;
  
   ObjectCreate("t_SL"+IntegerToString(0),OBJ_HLINE,0,0,t_SL[0]);
   ObjectSet("t_SL"+IntegerToString(0),OBJPROP_PRICE1,t_SL[0]);
   
   if(ObjectFind("t_SL"+IntegerToString(0)))
      Comment("Found");
   else
      Comment("Not found");
   
   return(INIT_SUCCEEDED);
  }
 
ccou:

Why does ObjectFind() never find my object??

It does.

You are not interpreting the return code of ObjectFind() properly.

Consider the what the documentation says:

If successful the function returns the number of the subwindow (0 means the main window of the chart), in which the object is found. If the object is not found, the function returns a negative number. To read more about the error call GetLastError().

 

Hello,

Try this:

  double t_SL[1];
   t_SL[0]= Bid;
  
   ObjectCreate("t_SL"+IntegerToString(0),OBJ_HLINE,0,0,t_SL[0]);
   ObjectSet("t_SL"+IntegerToString(0),OBJPROP_PRICE1,t_SL[0]);
   
   if(ObjectFind("t_SL"+IntegerToString(1)))
      Comment("Found");
   else
      Comment("Not found");
 

Thank you very much!!!

Reason: