1 min read

MQL4: Draw Object Text Longer Than 63 Chars

By default, when creating a text label using ObjectCreate in MQL4, the maximum text length is limited to 63 characters, as noted in this Stack Overflow post.

If you need to display a longer string, you can work around this limitation by splitting the string into chunks and creating multiple objects for each part.

Here’s a utility function that does just that:

void CreateMultiLabel(string baseName, int x, int y, string text) {
   int maxLen = 63;
   int parts = (StringLen(text) + maxLen - 1) / maxLen;
 
   for (int i = 0; i < parts; i++) {
      string partText = StringSubstr(text, i * maxLen, maxLen);
      string name = baseName + "_part" + IntegerToString(i);
 
      if (ObjectFind(0, name) >= 0)
         ObjectDelete(name);
 
      ObjectCreate(0, name, OBJ_LABEL, 0, 0, 0);
      ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
      ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x + i * 450); // Adjust spacing if needed
      ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
      ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 10);
      ObjectSetInteger(0, name, OBJPROP_COLOR, clrWhite);
      ObjectSetString(0, name, OBJPROP_FONT, "Courier New");
      ObjectSetString(0, name, OBJPROP_TEXT, partText);
   }
}

Here’s an example of how you might draw a very long table header across multiple columns:

string header = StringFormat("%-8s %-10s %-10s %-12s %-10s %-18s %-14s %-10s %-12s",
      "Symbol", "BuyDeals", "BuyLots", "BuyProfit", "SellDeals", "SellLots", "SellProfit", "NetLot", "NetProfit");
 
CreateMultiLabel("StatsHeader", x, y, header);