Change font in expert commentary window

Questions about MultiCharts and user contributed studies.
Kaos
Posts: 71
Joined: 01 Mar 2006
Location: Australia
Has thanked: 3 times
Been thanked: 6 times

Change font in expert commentary window

Postby Kaos » 24 Apr 2020

Hi all,

How do I code html inside my indicator so I can set the Expert Commentary window to have font = Courier New

eg:
Commentary("Long Entry = " + numtostr(1356.2,"1) + "" + Newline);
I would like that line in ExpertCommentary window be be in Courier New format

++++++++++++++
I have done some homework but still can't figure it out :-)

I can set the font on the chart textbox using Text_SetFontName (Text_Object,"Courier New");
but I need to change the Expert Commentary window as well

I went to this post and changed the internet explorer option so I can change the font size.
viewtopic.php?f=1&t=19389&p=70976&hilit ... ont#p70976

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Change font in expert commentary window

Postby JoshM » 24 Apr 2020

I would like that line in ExpertCommentary window be be in Courier New format
Any easy way to do that is probably with the `<span>` HTML element, since that one is for formatting/styling text. To do so, you'd use a `style` attribute with `<span>`.

For instance, this piece of HTML code makes the text bold:

Code: Select all

<span style='font-weight: bold;'>hello!</span>
Here is more information on `<span>` and here there's a lot more information on styling text in HTML.

But now to answer your actual question. Here's an example:

Code: Select all

Variables: formatStart(""), message(""), formatEnd(""); formatStart = "<span style='font-family: Courier New, monospace; font-size: 20px;'>"; message = "Bar close at " + NumToStr(Close, 1); formatEnd = "</span>"; Commentary(formatStart + message + formatEnd);
This code wraps the message inside the start and and tag of HTML's `<span>` element. That element's style uses `font-family` to get Courier New, and with `font-size` we make the text bigger.

Here's how that looks in the Expert Commentary:

Image
Attachments
Expert_Commentary_2020-04-25_06-48-20.png
(22.49 KiB) Not downloaded yet

Kaos
Posts: 71
Joined: 01 Mar 2006
Location: Australia
Has thanked: 3 times
Been thanked: 6 times

Re: Change font in expert commentary window

Postby Kaos » 27 Apr 2020

Hi Josh,

Thank you very much. I really appreciate it. I have implemented it and it works great except for 1 small issue.

In the textbox on the chart I can use multiple spaces to "pad" out the information to make it look like a table

The problem is the multiple spaces do not show up in the Expert Commentary window

Do you know what I might be missing please?

Here is my original code

Code: Select all

Commentary(""+newline); Commentary("using multiple spaces works in Textbox" + newline+newline); Text_String = "" + newline + "Buy @ "+NumToStr(L_Entry,Decimalz)+"" + newline + "StopLoss @ "+NumToStr(L_FirstStop,Decimalz)+"" + newline + "----------------" + newline + "Target @ "+NumToStr(L_Target,Decimalz)+"" + newline ; formatStart = "<span style='font-family: Courier New, monospace; font-size:" + numtostr(ecSize,0) + "px;'>"; formatEnd = "</span>"; Message = "Expert Commentary window problem when using multiple spaces" + newline; Message = Message + "Long Entry = "+NumToStr(L_Entry,Decimalz)+"" + newline; Message = Message + "Long StopLoss = "+NumToStr(L_FirstStop,Decimalz)+"" + newline; Message = Message + "Trade Risk = "+NumToStr(L_Risk,Decimalz)+" pts" + newline +newline; Message = Message + "Replace multiple spaces with dot works but doesn't look the best" + newline; Message = Message + "Long Entry....= "+NumToStr(L_Entry,Decimalz)+"" + newline; Message = Message + "Long StopLoss.= "+NumToStr(L_FirstStop,Decimalz)+"" + newline; Message = Message + "Trade Risk....= "+NumToStr(L_Risk,Decimalz)+" pts" + newline; Message = Message + "Replace multiple spaces with underscores works but doesn't look the best" + newline; Message = Message + "Long Entry____= "+NumToStr(L_Entry,Decimalz)+"" + newline; Message = Message + "Long StopLoss_= "+NumToStr(L_FirstStop,Decimalz)+"" + newline; Message = Message + "Trade Risk____= "+NumToStr(L_Risk,Decimalz)+" pts" + newline; Commentary(formatStart + message + formatEnd + newline);
2020-04-27_Expert Commentary issue.jpg
(189.11 KiB) Not downloaded yet
+++++++++++++++++++

I had a look at this website
https://crunchify.com/basic-html-how-do ... e-in-html/
to try and do it myself but I couldn't get it to work.

+++++++++++++++++++

Also an update for anyone else
You can't use the Internet Explorer fix I linked to earlier if you want to use the <span style='font-weight: bold;'>hello!</span> idea
viewtopic.php?f=1&t=19389&p=70976&hilit ... ont#p70976

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Change font in expert commentary window

Postby JoshM » 27 Apr 2020

The problem is the multiple spaces do not show up in the Expert Commentary window.
If you use multiple `&nbsp;` symbols in the text, one for each space, it should work properly. It's a bit annoying (and ugly), but you have to swap the ' ' (space) for `&nbsp;` in the sentence. That way it should work!

Here's what I got:

Image

The code used:

Code: Select all

Variables: formatStart(""), message(""), formatEnd(""); formatStart = "<span style='font-family: Courier New, monospace;font-size: 20px;'>"; message = "H&nbsp;&nbsp;&nbsp;e&nbsp;&nbsp;&nbsp;l&nbsp;&nbsp;&nbsp;l&nbsp;&nbsp;&nbsp;o&nbsp;&nbsp;&nbsp;!"; formatEnd = "</span>"; Commentary(formatStart + message + formatEnd);
Attachments
Expert_Commentary_2020-04-27_10-34-42.png
(21.69 KiB) Not downloaded yet

User avatar
Anna MultiCharts
Posts: 560
Joined: 14 Jul 2017
Has thanked: 42 times
Been thanked: 141 times

Re: Change font in expert commentary window

Postby Anna MultiCharts » 28 Apr 2020

Hello Kaos,

You can refer to HTML help, e.g: https://developer.mozilla.org/en-US/doc ... ndamentals

Our engineers have prepared a code example for you. The result of it is as shown in the screenshot.

Code: Select all

var: font_ita ("<span style='font-family: ; font-size:; font-style: italic;'>"), font_nrm ("<span style='font-family: ; font-size; font-style: normal;'>"), font_size20 ("<span style='font-family: ; font-size:20px; font-style: ;'>"), font_size10 ("<span style='font-family: ; font-size:10px; font-style: ;'>"), font_family_Courier_New ("<span style='font-family: Courier New; font-size:; font-style: ;'>"), font_family_Arial ("<span style='font-family: Arial; font-size:; font-style: ;'>"), preformatted_text_begin ("<pre>"), preformatted_text_end ("</pre>"); Commentarycl("t e s t 1"); Commentarycl(preformatted_text_begin); Commentarycl("t e s t 2"); Commentarycl(font_ita); Commentarycl("t e s t 3"); Commentarycl(font_size20); Commentarycl("t e s t 4");
screenshot-1.jpg
(148.04 KiB) Not downloaded yet

Kaos
Posts: 71
Joined: 01 Mar 2006
Location: Australia
Has thanked: 3 times
Been thanked: 6 times

Re: Change font in expert commentary window

Postby Kaos » 28 Apr 2020

Just wanted to say thanks to Josh and Anna for all the help. I really appreciate it.


Return to “MultiCharts”