TrendLine Selection
TrendLine Selection
30 Jul 2021, 15:23
Hello.
I want to select an ordinary trend line by Name that user draw in the chart . Is there some methods like
_chartTrendLine = SelectObjectByNme("TrendLine_1");
or
_chartTrendLine = ChartTrendLine("TrendLine_1");
TY for Help.
Replies
akbarlotfi15168
30 Jul 2021, 17:34
Tank You
Tank You for useful information I read a sample in forum
It solved my problem . I write the code like this:
var trendLines = Chart.FindAllObjects<ChartTrendLine>();
foreach (var trendLine in trendLines)
{
var chartTrendLine = trendLine as ChartTrendLine;
_chartTrendLine = chartTrendLine;
}
var BarIndex = MarketSeries.Close.Count - 1;
double trendLineLastValue = _chartTrendLine.CalculateY(BarIndex);
But I think there is something better that I have used for BarIndex .Can you help me?
@akbarlotfi15168
amusleh
31 Jul 2021, 08:22
Hi,
The code you pasted iterates over all available trend lines on your chart, and then you save each trend line reference to _chartTrendLine variable, at the end of the loop it will have a reference to the latest iterated trend line.
Then you get the latest bar index Y (Price) value by using the trend line CalculateY method.
I'm not sure what exactly you are trying to do, but that's what your code does.
@amusleh
amusleh
30 Jul 2021, 17:21
Hi,
All chart objects are inside Chart.Objects collection and you can iterate over it to find specific object by using Linq or a foreach loop:
@amusleh