Wrong character

Hi there!

This code is supposed to display an upward-pointing arrow on the button, but I'm only getting a question mark.

I also tried using Arial, but that didn't work either.

I don't want to use Wingdings on purpose.

What's the cause, and how can I fix it?

bool CreateUpArrowButton(
   string name = "UpArrowButton",
   int x = 20,
   int y = 20,
   int width = 40,
   int height = 30
)
{
   if(ObjectFind(0, name) >= 0)
      ObjectDelete(0, name);

   if(!ObjectCreate(0, name, OBJ_BUTTON, 0, 0, 0))
   {
      Print("Error: ", GetLastError());
      return false;
   }

   ObjectSetInteger(0, name, OBJPROP_CORNER, CORNER_LEFT_UPPER);
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE, x);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE, y);
   ObjectSetInteger(0, name, OBJPROP_XSIZE, width);
   ObjectSetInteger(0, name, OBJPROP_YSIZE, height);

   ObjectSetString(0, name, OBJPROP_TEXT, "↑");
   ObjectSetString(0, name, OBJPROP_FONT, "Segoe UI Symbol");
   ObjectSetInteger(0, name, OBJPROP_FONTSIZE, 18);

   ObjectSetInteger(0, name, OBJPROP_COLOR, clrWhite);
   ObjectSetInteger(0, name, OBJPROP_BGCOLOR, clrDodgerBlue);
   ObjectSetInteger(0, name, OBJPROP_BORDER_COLOR, clrBlue);
   ObjectSetInteger(0, name, OBJPROP_STATE, false);
   ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
   ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);

   ChartRedraw(0);
   return true;
}
stranger7:
↑

/en/forum/473426

Paul Anscombe #:

did you read the documentation?  CharToString uses ANSI codes

Ascii Symbol (up arrow) not displaying on chart
Ascii Symbol (up arrow) not displaying on chart
  • 2024.09.20
  • www.mql5.com
Hi, can anyone tell me what I am doing wrong here? I get no errors. Thank you...
Ioannis Christopoulos #:

/en/forum/473426

Thanks, but it did not help much.

So, what's the solution? As I said, I don't want to use Wingdings.

stranger7 #:

So, what's the solution? As I said, I don't want to use Wingdings.

Note that this diagnostic response may be unique to my terminal/MetaEditor settings. If yours are the same, here you go.

MT5 AI Assistant

Cause

The font is a red herring — by the time the text reaches the terminal it probably isn't ↑ (U+2191) any more, it's already ? (U+003F). ObjectSetString(..., OBJPROP_TEXT, ...) can only draw what's in the string, and both Segoe UI Symbol and Arial do contain U+2191, so changing the font can't help.

That single ? is the classic signature of a lossy code-page conversion of the string literal, not of a bad glyph at render time. The usual trigger is a source file stored in an ANSI/legacy code page (e.g. Windows-1252) or the character having been pasted through a step that dropped it: U+2191 has no mapping in CP1252, so it is replaced by one ? . MetaEditor even warns about this when saving a file in such an encoding.

What I verified in your terminal

I compiled and ran a throwaway test script (deleted afterwards, no existing file touched) with a UTF-8 source file, build 6361:

literal:   len=1 codes=U+2191
generated: len=1 codes=U+2191

and both OBJ_BUTTON s came back from the terminal with description: "↑" . So the whole chain — compiler → OBJPROP_TEXT → button — works fine when the source bytes actually arrive as U+2191. Which means the character is being lost before the terminal sees it, i.e. in your file's encoding (ANSI) or in whatever produced that literal.

Quick 1-line confirmation, add right after ObjectSetString :

Print("len=", StringLen(ObjectGetString(0, name, OBJPROP_TEXT)),
      " cp=", StringGetCharacter(ObjectGetString(0, name, OBJPROP_TEXT), 0));
  • cp=63 (or len=0 ) → the string is already broken, exactly as above.
  • cp=8593 (= 0x2191) → the string is fine and the problem would be on the drawing side (wrong/invisible font name), which your test with Arial largely rules out.

Fix — build the character from its code point

This is the robust fix: the source stays pure ASCII, so no editor, locale, or code-page setting can mangle it.

   // ObjectSetString(0, name, OBJPROP_TEXT, "↑");          // loses the glyph in an ANSI file
   ObjectSetString(0, name, OBJPROP_TEXT, ShortToString(0x2191));   // U+2191 ↑ built at runtime

Equivalent alternative, if you prefer a literal: use the escape sequence, which is also pure ASCII in the source:

   ObjectSetString(0, name, OBJPROP_TEXT, "\x2191");   // U+2191 ↑

If you'd rather keep the visible ↑ in the source, then fix the file encoding instead: in MetaEditor use File → Save As and pick UTF-8 (or UTF-16), and set the default under Tools → Options → General → Default encoding. Your IDE default is already utf-8 , so a file saved earlier as ANSI is the likely culprit.

Notes

  • No Wingdings needed, and nothing else in your function is wrong: corner, sizes, colors, OBJPROP_STATE , HIDDEN , and the ChartRedraw call are all fine. The button centers its text, so with height = 30 and FONTSIZE = 18 the arrow fits.
  • For crisp small-size arrows/triangles, U+25B2 "▲" / U+25BC "▼" exist in virtually every font; 0x2191 is fine with Segoe UI Symbol .
  • If you want a shape rather than a glyph, an OBJ_ARROW_UP object positioned over the button is an alternative, but the code-point fix above keeps your current design.
  • Verification artifacts: I opened a temporary EURUSD H1 chart, ran the test script, then closed the chart and removed the temp .mq5 / .ex5 / .png . No pre-existing file was modified.