Multiline label or text (ObjectSetString) - page 2

 
Guys, anyone found a way or a custom control to have multiline label on a chart?
 
Johhny D:
Guys, anyone found a way or a custom control to have multiline label on a chart?

Hi,

Here's the technical answer and then I'll try my best to explain it.

You would need to learn how to code using MQL4 notation format and using the libraries that are located in the Include Folder of your MT4 Data Folder.  You would also need to know how to create Loops and code using Arrays so that you don't have to write multiple lines of code that do the same thing.  Or you could use the original MQL4 language with Arrays and Loops with ObjectCreate() functions, etc, and accomplish the same thing.

In my opinion, as you advance you will eventually need to learn MQL4 notation.


So,

The programmers created a class of "code" intended for the simple creation of buttons, dashboards, and other objects.

Using Arrays to store data so that you can use it later saves lines of code. Running loops to create objects also saves lines of code. MQL4 notation definitedly saves lines of code and also makes coding in MT4 more native since the notation is more like plain English as you develop it.

You can create a button with no color border and that's your plain text line on the screen.

This example could be modified to do that and create several lines under each other with slightly different text:

(Of course there is much more to make this work that is not shown here)

//+------------------------------------------------------------------+
void CreateButtons()
//-Loop to create mySymbols buttons
  {
   int x1pos = 2, y1pos = 60, x2pos = x1pos + XSize, y2pos = y1pos + YSize;
   int total = ArraySize(mySymbols);
   for(int i = 0; i < total; i++)
     {
      MyButtons[i].Create(0, indiname + " " + mySymbols[i] + " " + (string)i, 0, x1pos, y1pos, x2pos, y2pos);
      MyButtons[i].Text(mySymbols[i]);
      MyButtons[i].FontSize(FSize);
      MyButtons[i].Font(FontType);
      MyButtons[i].Color(TextColor);
      MyButtons[i].ColorBackground(BackgroundColor);
      MyButtons[i].ColorBorder(BorderColor);
      y1pos += YSize;
      y2pos += YSize;
     }
  }
//-End Of Function

The reference is found here: https://www.mql5.com/en/docs/standardlibrary/controls/cbutton

That basic dashboard on the reference link will spark a fire!


Hope that helps.  Many folks here just drop a link and call that an answer or tell you to go read. Hope fully I have pointed you in the right direction.

It does take work, dedication, and countless hours of studying and coding. AND believe me it's all well worth it!! Keep at it.

Documentation on MQL5: Standard Library / Panels and Dialogs / CButton
Documentation on MQL5: Standard Library / Panels and Dialogs / CButton
  • www.mql5.com
//|                                               ControlsButton.mq5 | //|                        Copyright 2017, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | //| defines                                                          |  INDENT_LEFT                         (11)      ...
 
latinofxtrader #:

Hi,

Here's the technical answer and then I'll try my best to explain it.

You would need to learn how to code using MQL4 notation format and using the libraries that are located in the Include Folder of your MT4 Data Folder.  You would also need to know how to create Loops and code using Arrays so that you don't have to write multiple lines of code that do the same thing.  Or you could use the original MQL4 language with Arrays and Loops with ObjectCreate() functions, etc, and accomplish the same thing.

In my opinion, as you advance you will eventually need to learn MQL4 notation.


So,

The programmers created a class of "code" intended for the simple creation of buttons, dashboards, and other objects.

Using Arrays to store data so that you can use it later saves lines of code. Running loops to create objects also saves lines of code. MQL4 notation definitedly saves lines of code and also makes coding in MT4 more native since the notation is more like plain English as you develop it.

You can create a button with no color border and that's your plain text line on the screen.

This example could be modified to do that and create several lines under each other with slightly different text:

(Of course there is much more to make this work that is not shown here)

The reference is found here: https://www.mql5.com/en/docs/standardlibrary/controls/cbutton

That basic dashboard on the reference link will spark a fire!


Hope that helps.  Many folks here just drop a link and call that an answer or tell you to go read. Hope fully I have pointed you in the right direction.

It does take work, dedication, and countless hours of studying and coding. AND believe me it's all well worth it!! Keep at it.

Yevgen Drumachyk #:
Guys, anyone found a way or a custom control to have multiline label on a chart?

Hi, I have created a simple library for custom controls, it is not complete and you might need to edit the code as needed( for example handling errors and events ). 

I have used the library in a sample indicator that draws multiline text areas custom controls( see attached zip file for the sample project and files )

---

The function createTextArea in the TextArea.mqh file is used to draw text areas

How does it work:

1. Draw a rectangle as a the text area background

2. Draw a label for each line of the text area ( each label can have a maximum of 63 characters )

3. Take a screen shot of the chart and save to file as a bitmap

4. Draw a bitmap label with dimensions and offset of the rectangle background

5. Set the bitmap label source file as the chart screen shot

6. Delete all other objects except the bitmap label

---

library usage example

---

Installation : 

1. Unzip the archive ( see attached )

2. Move icon_pack_mql_gray_small and icon_pack_mql_small into data folder/Images

3. Move StickyNotes folder into data folder/Indicators

example project

result

---

Development

I will create an article/s for further development of the library in the future


---

Enjoy for now 

Files:
textarea.zip  196 kb
 
balazs321: How could I do it without defining a new object for every line?

You can't. Create multiple labels. See: I want to move the EA comment from left to right corner ? - MQL4 programming forum - Page 2 #13 (2022)

Reason: