I'm having trouble correctly drawing on he price panel from values derived from a secondary one-minute series, and wondered if someone could tell me what I'm doing wrong. The code works as expected until I connect to a live data source, and then it displays results that seem to have no relation to the secondary series or the primary series.
I'm attaching images of the chart, disconnected and connected.
And here's the code (simplified):
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { try { if(Bars == null || Bars.Instrument == null || IsInHitTest) return; int firstBarPainted = ChartBars.FromIndex; int lastBarPainted = ChartBars.ToIndex; SharpDX.Direct2D1.Brush LineBrushDx = LineBrush.ToDxBrush(RenderTarget); int baridx; for (baridx = firstBarPainted; baridx <= lastBarPainted; baridx ++) { //get time of primary ser bar DateTime timeIdx = Time[CurrentBars[0] -( baridx)]; //get index of corresponding secondary ser bar int oneMinuteIdx = BarsArray[1].GetBar(timeIdx); // get high of secondary bar double price = Closes[1][CurrentBars[1]-oneMinuteIdx]; // draw line at secondary ser high, from primary ser bar to end of chartpanel. float xpos = chartControl.GetXByBarIndex(ChartBars, baridx); float y = chartScale.GetYByValue(price); Point startPoint = new Point(xpos, y); Point endPoint = new Point(ChartPanel.X + ChartPanel.W, y); RenderTarget.DrawLine(startPoint.ToVector2(), endPoint.ToVector2(), LineBrushDx, 2); } }catch (Exception ex){Print(Instrument.MasterInstrument.Name.ToString() + " " + BarsPeriod.BarsPeriodType.ToString() + " " +BarsPeriod.Value.ToString() + " " + Name.ToString() + " : " + ex.ToString());} }
Comment