I'm trying to redraw two existing vertical lines using this code:
protected override void OnBarUpdate()
{
if (Bars.IsFirstBarOfSession && ToDay(Time[0]) == ToDay(DateTime.Now)) {
line1 = Draw.VerticalLine(this, "Line1", new DateTime([B]2016,9,15,10,29,43[/B]), Brushes.Red, DashStyleHelper.Solid, 2, true);
line2 = Draw.VerticalLine(this, "Line2", new DateTime([B]2016,9,15,10,30,07[/B]), Brushes.Blue, DashStyleHelper.Solid, 2, true);
}
}
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
if(!chartScale.IsVisible)
return;
DateTime timeToCheck = new DateTime(2016,9,15,12,30,00);
// Find the chart-canvas x-coordinate of the bar at the specified time
int xCoordinate = chartControl.GetXByTime(timeToCheck);
DateTime dt1 = chartControl.GetTimeByX(xCoordinate-2);
DateTime dt2 = chartControl.GetTimeByX(xCoordinate+2);
// Print the x-coordinate value
Print("xCoordinate " + xCoordinate);
Print("Time-2 " + dt1);
Print("Time+2 " + dt2);
[B]line1.StartAnchor.Time[/B] = dt1;
[B]line2.StartAnchor.Time[/B] = dt2;
}
If you comment the lines with StartAnchor.Time changing, lines on chart would be drawn correctly (see 2nd screenshot).
What I'm doing wrong?

Comment