Text label cut short!?

 

I have an indicator shown in a separate window and I want to place a text label in the window. The code I have is:

void CreateTradeLabel()
{
 string name = "tradelabel";
 int chart_ID = 0;
 
 if(ObjectFind(0,name) != 0)
 {
 if(!ObjectCreate(chart_ID,name,OBJ_LABEL,1,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create text label! Error code = ",ErrorDescription(GetLastError()));
     }
//--- set label coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,300);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,10);
//--- set the chart's corner, relative to which point coordinates are defined
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,0);
//--- set the text
   ObjectSetText(name,indi_label,10,"Arial",White);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,True);
//--- enable (true) or disable (false) the mode of moving the label by mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,False);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,False);
 }
 return;
}

The problem is with the string "indi_label".

I have a print statement for the string which shows as :

This is a snapshot of where the text label goes in the indicator window:


Any ideas why the string has been cut short please?

I've tried StringInit(indi_label,200,0) but this has no effect.

 
sd59:

I have an indicator shown in a separate window and I want to place a text label in the window. The code I have is:

The problem is with the string "indi_label".

I have a print statement for the string which shows as :

This is a snapshot of where the text label goes in the indicator window:


Any ideas why the string has been cut short please?

I've tried StringInit(indi_label,200,0) but this has no effect.

I think the maximum of characters should not exceed 63 characters. Similar as an object name in ObjectCreate. See the note: https://docs.mql4.com/objects/objectcreate

 
Petr Nosek:

I think the maximum of characters should not exceed 63 characters. Similar as an object name in ObjectCreate. See the note: https://docs.mql4.com/objects/objectcreate

This is what I originally thought so I used StringInit which I have used in other EA's for strings much longer than 63 characters and this has worked fine. It does not work here!

Also the line of code I have to print the string indi_label is:

 String indi_label;
 indi_label = "----- Number of data for symbol = " +(string)i + "  Total data = " + (string)num_data + "   Percentage = " + DoubleToStr(perc,0) + "%";
 Print(indi_label);

So I assign the whole string to indi_label which prints out as shown above - so the length of the string doesn't seem a problem.

Still confused!

 
sd59:

This is what I originally thought so I used StringInit which I have used in other EA's for strings much longer than 63 characters and this has worked fine. It does not work here!

Also the line of code I have to print the string indi_label is:

So I assign the whole string to indi_label which prints out as shown above - so the length of the string doesn't seem a problem.

Still confused!

OK sorry I shouldn't confuse 'Print' with a string object but I still don't know why StringInit does not work?

 
sd59:

This is what I originally thought so I used StringInit which I have used in other EA's for strings much longer than 63 characters and this has worked fine. It does not work here!

Also the line of code I have to print the string indi_label is:

So I assign the whole string to indi_label which prints out as shown above - so the length of the string doesn't seem a problem.

Still confused!

The problem aren't StringInit() or your string "indi_label" which contains the whole text but if you use longer string than 63 characters in the ObjectSetText() function then the function uses only 63 characters.

 
I also have this problem. It's very annoying such a short character limit, as well as the limit in the Experts log :-/ Is there a work around other than splitting the string and using two objects placed one next to the other?
 
Pimpinela:
I also have this problem. It's very annoying such a short character limit, as well as the limit in the Experts log :-/ Is there a work around other than splitting the string and using two objects placed one next to the other?

I ended up using two objects.

 
That's cool thanks. Two objects is the way to go.
Reason: