How to read object width size?

 

Hello all! 

I want to set an info panel on my EA, and I want it to have a rectangle as a background with text over it. Now, everything seems to be OK, but when a line of text gets larger, and my code tries to read the size, the ObjectGet() function returns 0... you can find below the code responsible of drawing the background and the text below. It is inside a function that's called on EveryTick if the user sets the info panel to activated.

//---Get background

// Here it gets the size it should be, largetst_width reads the width of all lines of text and only keeps the largest one, 
text_distance and center_multiplier are user inputs to adjust for scaling. text_offset is a function I made to calculate 
the height it should have to cover all lines.

      ObjectCreate (bot_name + "1", OBJ_RECTANGLE_LABEL,0,0,0);
      ObjectSetInteger (ChartID(), bot_name + "1", OBJPROP_COLOR, background_color);
           
      ObjectSet (bot_name + "1", OBJPROP_CORNER, 1);
      ObjectSet (bot_name + "1", OBJPROP_XDISTANCE, largest_width + (text_distance * center_multiplier));
      ObjectSet (bot_name + "1", OBJPROP_YDISTANCE, 10);
      
      ObjectSet (bot_name + "1", OBJPROP_XSIZE, largest_width + 20);
      ObjectSet (bot_name + "1", OBJPROP_YSIZE, text_offset(11));

// Chart P/L

// Here we have repetitive lines creating the info to show, like account name, balance and bla bla bla. 
The trouble gets on the object that's constantly changing in size, that is for the floating P/L from the chart, 
as if it goes from 0.00 to 10.00 the width changes, and when the ObjectGet() is called from the 2nd time and on to get the size, 
it straight returns 0 for reasons I don't understand, therefore, the largest_width value is not updated and the text gets outside the rectangle. 
I know it keeps returning 0 as the Comment() function shows it.
      
      if (Open_Trades())
      {
         for (int i = 0; i < OrdersTotal(); i++)
         {      
            if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == magic_number)
               chart_floating += OrderProfit();
         }
      }
      
      else
         chart_floating = 0;
         
      string chart_pl = "Flotante en la gráfica: " + DoubleToStr (chart_floating, 2) + " " + AccountCurrency ();
      
      ObjectCreate (bot_name + "11", OBJ_LABEL,0,0,0);
      
      ObjectSet (bot_name + "11", OBJPROP_CORNER, 1);
      ObjectSet (bot_name + "11",OBJPROP_XDISTANCE, 20);
      ObjectSet (bot_name + "11", OBJPROP_YDISTANCE, text_offset(10));
      
      ObjectSetText (bot_name + "11", chart_pl, 10, NULL, text_color); 
      
      largest_width = (ObjectGet(bot_name + "11", OBJPROP_XSIZE) > largest_width)? ObjectGet(bot_name + "11", OBJPROP_XSIZE) : largest_width; 
      
      Comment(ObjectGet(bot_name + "11", OBJPROP_XSIZE));
 
Fernando Jose Velasco Borea:

Hello all! 

I want to set an info panel on my EA, and I want it to have a rectangle as a background with text over it. Now, everything seems to be OK, but when a line of text gets larger, and my code tries to read the size, the ObjectGet() function returns 0... you can find below the code responsible of drawing the background and the text below. It is inside a function that's called on EveryTick if the user sets the info panel to activated.

You can refer to this: https://www.mql5.com/en/forum/35582
 
Seng Joo Thio:
You can refer to this: https://www.mql5.com/en/forum/35582

Thanks! It did worked out!