Current Spread displayed as an Object

 

Hi Forum,

I created a small indicator printing the spread as a label-object. It works fine. I just have a technical question:

The label-object is printed with every tick. Is it a problem when the object is printed and printed again? Is is "better" to delete it before creating it new?

I do it this way:

int start()
  {
   ObjectCreate("Spread", OBJ_LABEL, 0, 0, 0);
   ObjectSet("Spread", OBJPROP_CORNER, 3);
   ObjectSet("Spread", OBJPROP_XDISTANCE, 3);
   ObjectSet("Spread", OBJPROP_YDISTANCE, 1);
   ObjectSetText("Spread", DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD),1), 10, "Verdana", Black);
   WindowRedraw();
   return(0);
  }
I can't use Comment() because this is just a small part of a more complex indicator. I just wanted to know if this is the "cleanest" way to do it by using a label-object.
 
Create and set co-ordinates of your label in init then just use ObjectSetText in start.
 
mar:

Hi Forum,

I created a small indicator printing the spread as a label-object. It works fine. I just have a technical question:

The label-object is printed with every tick. Is it a problem when the object is printed and printed again? Is is "better" to delete it before creating it new?

I do it this way:

I can't use Comment() because this is just a small part of a more complex indicator. I just wanted to know if this is the "cleanest" way to do it by using a label-object.
ObjectCreate() an Object that already exists will generate an error. . . you just aren't seeing the error . . . do an ObjectFind() to see if it exists before you try and create it, if it already exists there is no need to create it again . . . just do as GumRai says and change the text each time.
 
Thanks guys!!