Download MetaTrader 5
To add comments, please log in or register
MQL5.community allows users to store their source codes in MQL5 Storage. Try it!
mar
1143
mar 2014.02.05 11:07 

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.
Keith Watford
Moderator
8006
Keith Watford 2014.02.05 11:49  
Create and set co-ordinates of your label in init then just use ObjectSetText in start.
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.05 12:15  
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.
mar
1143
mar 2014.02.05 12:55  
Thanks guys!!
/
To add comments, please log in or register