Chart Draw number above candlestick permanently.

Created at 07 Apr 2023, 11:36
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!
YS

ys2310

Joined 03.12.2021

Chart Draw number above candlestick permanently.
07 Apr 2023, 11:36


With the following code, I can draw a number above last cadlestick. But the number dissapear when a new bar is formed.

ChartObjects.DrawText("Your Number", "1", Bars.Count-1, Bars.HighPrices[Bars.Count-1] + (Symbol.PipValue * 10), VerticalAlignment.Center, HorizontalAlignment.Center, Colors.GreenYellow);

How can I draw numbers above candlesticks and let the numbers stay permanently on there?

Thank you very much.


@ys2310
Replies

firemyst
08 Apr 2023, 05:13

Of course it does :-)

That's because each time you draw the number, you call the object on the chart the same name, so it replaces the one that was there previously with the same name, with the new values. You need to make the name of your object more "unique" -- the part highlighted in bold below:

ChartObjects.DrawText("Your Number", "1", Bars.Count-1, Bars.HighPrices[Bars.Count-1] + (Symbol.PipValue * 10), VerticalAlignment.Center, HorizontalAlignment.Center, Colors.GreenYellow);

 

So I would do one of 2 things:

1) append the current bar index onto the end of the name

2) append the current datetime it's drawn onto the end of the name

The "index" option would be easier if you ever have to go back and delete a particular object

 

Example if you're in the calculate method:

protected override void Calculate (int index)

{

ChartObjects.DrawText("Your Number" + index, "1", Bars.Count-1, Bars.HighPrices[Bars.Count-1] + (Symbol.PipValue * 10), VerticalAlignment.Center, HorizontalAlignment.Center, Colors.GreenYellow);

}


@firemyst