ChartArea Max X value
ChartArea Max X value
17 Oct 2024, 15:45
Hi
Is there anyway of accessing a chart's Maximum X value. i.e. the datetime of the far right of the visible area (similar to the TopY property for the Y axis) ? I couldnt find anything except for LastVisibleBarIndex but this doesn't take into account any white space beyond the last bar (and the y axis scale).
What i'm trying to do is to add some labels to certain lines that i've added to my chart but I want them to always appear on the far right of the chart and I need a suitable datetime for the DrawText time parameter.
Thank you
Replies
couscousmckoy
18 Oct 2024, 08:09
( Updated at: 18 Oct 2024, 08:49 )
RE: ChartArea Max X value
PanagiotisCharalampous said:
Hi there,
You can use a combination of Chart.FirstVisibleBarIndex + Chart.MaxVisibleBars to get the last index on the chart.
Best regards,
Panagiotis
Thank you Panagiotis. Works a treat. For some reason I assumed that the maximum index was the index of the last printed bar and that if you tried to reference an index greater than that it would throw an error. Not sure why I thought that - I was obviously wrong!
For anyone else wanting to do something similar here is the code snippet (draws vertical line 2 bars in from the right hand edge of the screen, but same would work for DrawText - you just need to work out a suitable offset back from that last index to allow all your text label to display before it disappears off the right hand edge of the ChartArea).
Chart.DrawVerticalLine("line", Chart.FirstVisibleBarIndex+Chart.MaxVisibleBars-2, Color.Red);
(Panagiotis - any plans to include a line label property as a standard feature? Would be nice)
PS - actually quite like this: steps the label in so that it is printed 5% of the way in from the right hand edge
Chart.DrawText("LastBarLowLabel", "Last Bar Low", Chart.FirstVisibleBarIndex+((int)(Chart.MaxVisibleBars*0.95)), Bars.LowPrices.Last(1), Color.Black);
Chart.DrawTrendLine("LastBarLowLine", Bars.Count-2, Bars.LowPrices.Last(1), Chart.FirstVisibleBarIndex+Chart.MaxVisibleBars, Bars.LowPrices.Last(1), Color.Black, 1, LineStyle.Dots);
@couscousmckoy
PanagiotisCharalampous
18 Oct 2024, 09:31
RE: RE: ChartArea Max X value
(Panagiotis - any plans to include a line label property as a standard feature? Would be nice)
No specific plans at the moment
@PanagiotisCharalampous
PanagiotisCharalampous
18 Oct 2024, 05:50
Hi there,
You can use a combination of Chart.FirstVisibleBarIndex + Chart.MaxVisibleBars to get the last index on the chart.
Best regards,
Panagiotis
@PanagiotisCharalampous