I am trying to render data that was calculated on a higher time frame on the same chart. The price is correct but the bar numbers are of course different.
I was trying to use DateTime timeslot1=Times[1].GetValueAt(startBar) of the higher time frame to get the DateTime, and convert it to chart X using double val1=(double)chartControl.GetXByTime(timeslot1). I'm then converting the price to char y using PriceToY(val1, chartScale), and I get to see the line, but with X offset.
Please see the image and the relevant code below.
Your help is much appreciated.
...
DrawDXLine(Times[timeFrame].GetValueAt(startBar),Times[timeFrame].GetValueAt(endBar),
startPrice,endPrice,
(dir>0?SwingsUpStroke:indicator.SwingsDownStroke),chartControl,chartScale);
...
protected void DrawDXLine(DateTime timeslot1, DateTime timeslot2, double val1, double val2,
Stroke stroke, ChartControl chartControl, Gui.Chart.ChartScale chartScale)
{
DrawDXLine((double)chartControl.GetXByTime(timeslot1),(double)chartControl.GetXByTime(timeslot2),
PriceToY(val1, chartScale), PriceToY(val2, chartScale),
stroke.Brush, stroke.DashStyleHelper, chartControl, chartScale, stroke.Width, stroke.Opacity);
}
protected void DrawDXLine(double x1, double x2, double y1, double y2, Brush brush, DashStyleHelper dashStyle,
Gui.Chart.ChartControl chartControl, Gui.Chart.ChartScale chartScale, float width=1f, int opacity = 100)
{
Point p1 = new Point(x1, y1);
Point p2 = new Point(x2, y2);
DrawDXLine(p1, p2, brush, dashStyle, chartControl, chartScale, width, opacity);
}
protected void DrawDXLine(Point p1, Point p2, Brush brush, DashStyleHelper dashStyle,
ChartControl chartControl, Gui.Chart.ChartScale chartScale, float width=1f, int opacity=100)
{
SharpDX.Direct2D1.DashStyle tempDashStyle;
if (!Enum.TryParse(dashStyle.ToString(), true, out tempDashStyle)) tempDashStyle = SharpDX.Direct2D1.DashStyle.Dash;
SharpDX.Direct2D1.StrokeStyleProperties properties = new SharpDX.Direct2D1.StrokeStyleProperties() {DashStyle=tempDashStyle};
SharpDX.Direct2D1.StrokeStyle strokeStyle = new SharpDX.Direct2D1.StrokeStyle(Core.Globals.D2DFactory, properties);
SharpDX.Direct2D1.Brush dxBrush = brush.ToDxBrush(RenderTarget);
dxBrush.Opacity = opacity/100f;
RenderTarget.DrawLine(p1.ToVector2(), p2.ToVector2(), dxBrush, width, strokeStyle);
dxBrush.Dispose();
strokeStyle.Dispose();
}

Comment