Download MetaTrader 5
To add comments, please log in or register
Have you developed a trading robot? Publish it in the Market and make profit!
Tim
45
Tim 2014.03.13 13:08 

Hi Everyone,

I'm trying to create a label with a light blue background and black writing. I want to do this so the writing stands out more. I've tried to use the OBJPROP_BGCOLOR with both ObjectSet and ObjectSetInteger but the ID seems to have no effect on the label.

Any suggestions would be greatly appreciated.

Kind Regards,

Tim

JPS1
239
JPS1 2014.03.13 13:21  

Objects in the new builds either have bugs or Metaquotes is still working out the programming for them. Hard to say which one it is.

There are 3 or 4 threads here mentioning similar problems with Objects. One example can be seen here https://www.mql5.com/en/forum/150117

It would also help to post some code, so we can see exactly what you are doing. I'm assuming 2 labels overlapping, but I can only guess without seeing some source code.

Ian Venner
2583
Ian Venner 2014.03.14 01:47  

Which object type are you using ? I think OBJPROP_BGCOLOR is for the special OBJ_RECTANGLE_LABEL object.

   ObjectCreate("object",OBJ_RECTANGLE_LABEL,0,0,0,0);
   ObjectSet("object",OBJPROP_BGCOLOR,clrYellow);

I guess that creates a default position and size on the chart, but it does seem the BGCOLOR works now, the last time I played with that I couldnt get it to work im using build 616 maybe something is fixed or I might have done it wrong the first time.

Ian Venner
2583
Ian Venner 2014.03.14 02:15  

Im gonna see what else it does. This is all I need I have like ten half finished projects and now you got me playing with graphical objects ;)

EDIT:

I think it is more correct to do it like this

   ObjectCreate(0,"object",OBJ_RECTANGLE_LABEL,0,0,0,0);
   ObjectSetInteger(0,"object",OBJPROP_BGCOLOR,clrYellow);
   ObjectSetInteger(0,"object",OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,"object",OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0,"object",OBJPROP_XSIZE,100);
   ObjectSetInteger(0,"object",OBJPROP_YSIZE,100);

I havent figured out how to put text in it though. Maybe you have to make a regular label for the text and put it on top.

Ian Venner
2583
Ian Venner 2014.03.14 06:39  

Well that doesnt work either. I tried a bunch of different ways but they didn't work. there must be some way of doing a simple colored text label.

qjol
3243
qjol 2014.03.14 07:11  
SDC:

Well that doesnt work either. I tried a bunch of different ways but they didn't work. there must be some way of doing a simple colored text label.

what's wrong with 2 seperate objects ?
   ObjectCreate(0,"object",OBJ_RECTANGLE_LABEL,0,0,0,0);
   ObjectSetInteger(0,"object",OBJPROP_BGCOLOR,clrYellow);
   ObjectSetInteger(0,"object",OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,"object",OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0,"object",OBJPROP_XSIZE,100);
   ObjectSetInteger(0,"object",OBJPROP_YSIZE,100);
   
   ObjectCreate(0,"objectTxt",OBJ_LABEL,0,0,0,0);
   ObjectSetText("objectTxt","Text",25,"Times New Roman",clrBlack);
   ObjectSetInteger(0,"objectTxt",OBJPROP_BGCOLOR,clrBlack);
   ObjectSetInteger(0,"objectTxt",OBJPROP_XDISTANCE,110);
   ObjectSetInteger(0,"objectTxt",OBJPROP_YDISTANCE,128);
Ian Venner
2583
Ian Venner 2014.03.14 14:55  

Oh ok thats a combination I didnt try, the trouble is the documentation never old me which modifiers to use with which object, I tried several combinations but I didn't know to use OBJPROP_BGCOLOR with ObjectSetText() because OBJ_LABEL never used to require that. The last thing I tried before I gave up and went to bed was to put this on top of the OBJ_RECTANGLE_LABEL but it didnt work.

ObjectCreate(0,"text",OBJ_LABEL,0,0,0,0);
ObjectSetInteger(0,"text",OBJPROP_XDISTANCE,100);
ObjectSetInteger(0,"text",OBJPROP_YDISTANCE,100);
ObjectSetText("text","HELLO",14,"Tahoma",clrRed);

JPS1
239
JPS1 2014.03.15 00:48  
Its definitely doable. The problem is they won't overlap correctly each time you restart. I posted this in another thread (link is above). Only solution to the stacking order I mention above is to delete and recreate the objects on each DeInit() .... which is fine in most cases unless one wishes to "store" information in the object description.
Ian Venner
2583
Ian Venner 2014.03.15 01:37  
JPS:
Its definitely doable. The problem is they won't overlap correctly each time you restart. I posted this in another thread (link is above). Only solution to the stacking order I mention above is to delete and recreate the objects on each DeInit() .... which is fine in most cases unless one wishes to "store" information in the object description.

Did you try OBJPROP_BACK to help with the stacking order ?

It would help a lot if the documentation was not so vague about the usage of these objects and the modifiers that should be used with each one.

The strange thing is, the code I tried yesterday did not show the text, Since then I have restarted the terminal and now it does work.

void OnStart()
  {
//---
   ObjectCreate(0,"shape",OBJ_RECTANGLE_LABEL,0,0,0,0);
   ObjectSetInteger(0,"shape",OBJPROP_BGCOLOR,clrYellow);
   ObjectSetInteger(0,"shape",OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,"shape",OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0,"shape",OBJPROP_XSIZE,100);
   ObjectSetInteger(0,"shape",OBJPROP_YSIZE,100);
   
   ObjectCreate(0,"text",OBJ_LABEL,0,0,0,0);
   ObjectSetInteger(0,"text",OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0,"text",OBJPROP_YDISTANCE,100);
   ObjectSetText("text","HELLO",14,"Tahoma",clrRed);
  }
/
To add comments, please log in or register