Relating text font size to Y axis (price scale)
Relating text font size to Y axis (price scale)
23 Mar 2021, 13:32
Good morning
In my cBot I'm adding some text (a single digit number) to a chart with the Chart.DrawText function. I want to add that number above the last printed candle. All very easy. But then on occasions there might be another number that I want to display simultaneously above the same candle. Obviously looks a mess printed on top of each other, so I want to offset the 'Y' value of the second number by 1.5 times the height of the text (so they display stacked one above another, rather than superimposed over the top of each other). I have the text.fontsize, but I'm struggling to think how to relate that to the Y axis scale (i.e. price) in order to get a proper Y value to set it to. Any ideas? Or do I just hardcode a Y offset but I'm guessing that would come unstuck for different zoom settings.
Thanks in advance.
Replies
couscousmckoy
23 Mar 2021, 17:44
RE:
Hi amusleh
Thank you for your response. Works well. You also made me realise I could also just add "\r\n" into my text string to drop the second number down a line.
Cheers
amusleh said:
Hi,
Try StringBuilder:
using cAlgo.API; using System.Text; namespace cAlgo { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class Blank : Indicator { protected override void Initialize() { var stringBuilder = new StringBuilder(); stringBuilder.AppendLine("First Text"); stringBuilder.AppendLine("Second Text"); var text = stringBuilder.ToString(); Chart.DrawText("text", text, Chart.LastVisibleBarIndex, Bars.HighPrices[Chart.LastVisibleBarIndex], Color.Red); } public override void Calculate(int index) { } } }
With string builder you can easily add as many line as you want to, and then you just have to call the DrawText once.
You can't use font size, that's for chart controls not chart objects.
@couscousmckoy
... Deleted by UFO ...
amusleh
23 Mar 2021, 15:02
Hi,
Try StringBuilder:
With string builder you can easily add as many line as you want to, and then you just have to call the DrawText once.
You can't use font size, that's for chart controls not chart objects.
@amusleh