How to Use ChartObjects.DrawText

Created at 19 Jul 2015, 15:28
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
EM

emelenium

Joined 23.09.2013

How to Use ChartObjects.DrawText
19 Jul 2015, 15:28


 ChartObjects.DrawText("TEXT", "TEXT", StaticPosition.TopRight, Colors.Yellow):

How to do it like this? :


@emelenium
Replies

Spotware
20 Jul 2015, 04:20

Dear Trader,

You could write two objects and use the “\n” new line in the text to move the second Object down to a separate line so that it does not overlap the first. The following code snippet illustrates it:

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

We hope this helps you.


@Spotware

spike.bhv
20 Jul 2015, 05:44

ChartObjects.DrawText("text1", "TEXT\nTEXT", StaticPosition.TopRight, Colors.Yellow);

This is also possible. 


@spike.bhv

emelenium
20 Jul 2015, 17:56 ( Updated at: 21 Dec 2023, 09:20 )

How to do it like this? :


@emelenium

emelenium
20 Jul 2015, 19:23

thank


@emelenium

spike.bhv
21 Jul 2015, 05:43


ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text3", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

or

ChartObjects.DrawText("text1", "TEXT\nTEXT\nTEXT", StaticPosition.TopRight, Colors.Yellow);

 


@spike.bhv

equantfx
06 Dec 2016, 11:46

just a small update:

 

ChartObjects.DrawText("text3", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

 

should be

 

ChartObjects.DrawText("text3", "\n\nTEXT", StaticPosition.TopRight, Colors.Yellow);

From what I am seeing the \n is calculated frop the TopRight and not the previously drawn text element. if you use just \n instead of \n\n the thrid line overwrites the second.


@equantfx

kricka
11 Apr 2017, 01:23

Major update needed

One font and one size are just not enough to present a cBot visual for traders nowadays. With the high resolution monitors becoming a norm for traders, my question is why there is not an update in several years to this so important method.


@kricka

iulianalinchiru
25 Apr 2018, 22:57

RE:

Spotware said:

Dear Trader,

You could write two objects and use the “\n” new line in the text to move the second Object down to a separate line so that it does not overlap the first. The following code snippet illustrates it:

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

We hope this helps you.

Hi there,

Wondering what's the formula for a new line, upside from current, if we use .BottomLeft positioning.

Thank you for your answer!


@iulianalinchiru

iulianalinchiru
25 Apr 2018, 23:00

RE: RE:

iulianalinchiru said:

Spotware said:

Dear Trader,

You could write two objects and use the “\n” new line in the text to move the second Object down to a separate line so that it does not overlap the first. The following code snippet illustrates it:

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

We hope this helps you.

Hi there,

Wondering what's the formula for a new line, upside from current, if we use .BottomLeft positioning.

Thank you for your answer!

Or, if you can give me a solution for aligning text from bottom to upside, 5 rows lets say...


@iulianalinchiru

PanagiotisCharalampous
26 Apr 2018, 09:28

Hi iulianalinchiru,

You can use the overload of the DrawText method that allows you to specify the absolute x and y values where the text would be drawn. Then, you will have to write some logic that will keep track where each row has been drawn and draw the next one accordingly.

Best Regards,

Panagiotis


@PanagiotisCharalampous

researchscrap
29 Nov 2018, 04:19

RE: Text or Font Size

Spotware said:

Dear Trader,

You could write two objects and use the “\n” new line in the text to move the second Object down to a separate line so that it does not overlap the first. The following code snippet illustrates it:

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

We hope this helps you.

Similar MT4 code - Note:  avaiability of font size parameter

bool  ObjectSetText(
   string   object_name,         // object name
   string   text,                // description
   int      font_size=0,         // font size
   string   font_name=NULL,      // font name
   color    text_color=clrNONE   // text color
   );

There appears to be no way to incorporate text size into this code

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

Q1: How is font size incorporated with the above code ?

Q2: is font size feature non existent ?

Thanks in advance

 


@researchscrap

PanagiotisCharalampous
29 Nov 2018, 10:36

Hi researchscrap,

There is no text font size feature at the moment.

Best Regards,

Panagiotis


@PanagiotisCharalampous

researchscrap
29 Nov 2018, 21:57

Test

Thanks for response 

Typed a reply, hit submit and no post, perhaps hit cancel.


@researchscrap

radoslawkupisek
12 Sep 2019, 20:20

Hi, how to set corner in  Chart.DrawText method?

public ChartText DrawText(string name, string text, DateTime time, double y, Color color) for example:  Chart.DrawText("text", "test", ?,?, Color.White); It used to be StaticPosition, what can I use now?


@radoslawkupisek

PanagiotisCharalampous
13 Sep 2019, 09:08

Hi radoslawkupisek,

You can use DrawStaticText instead.

Best Regards,

Panagiotis


@PanagiotisCharalampous

tatorzth
05 Nov 2020, 11:12

RE: RE: Text or Font Size

researchscrap said:

Spotware said:

Dear Trader,

You could write two objects and use the “\n” new line in the text to move the second Object down to a separate line so that it does not overlap the first. The following code snippet illustrates it:

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

We hope this helps you.

Similar MT4 code - Note:  avaiability of font size parameter

bool  ObjectSetText(
   string   object_name,         // object name
   string   text,                // description
   int      font_size=0,         // font size
   string   font_name=NULL,      // font name
   color    text_color=clrNONE   // text color
   );

There appears to be no way to incorporate text size into this code

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);
ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

Q1: How is font size incorporated with the above code ?

Q2: is font size feature non existent ?

Thanks in advance

 

How can i modify below code to show my calculation value (var, int and double) ?

ChartObjects.DrawText("text1", "TEXT", StaticPosition.TopRight, Colors.Yellow);

ChartObjects.DrawText("text2", "\nTEXT", StaticPosition.TopRight, Colors.Yellow);

sorry for stupid question. i am self learning cbot programing because few people use this application in my country.

 

Regards,

WB


@tatorzth

PanagiotisCharalampous
05 Nov 2020, 12:38

Hi tatorzth,

The second parameter in the DrawText() method is the value that will be printed. Put your calculation value there,

Best Regards,

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous