Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with multiseries drawing in OnRender

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with multiseries drawing in OnRender

    Hi,

    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):

    Code:
    		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());}		
    		}
    Help would be much appreciated.
    Attached Files

    #2
    Hello,

    Thank you for sharing this issue. It appears that the issue may stem from an unhandled exception resulting from the assignment of timeIdx. I'm currently investigating this issue, and I will post back on this thread with any updates. It may be that timeIdx simply needs to be assigned in a different way, or there could be something else going on that needs reported to our development team.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Thanks, Dave. If you can think of any other way to do what I am wanting in the meantime, it would be much appreciated.

      Comment


        #4
        I believe I have found the problem: every reference needs to specify the BarsArray (e.g., Times[0], CurrentBars[0], etc).

        But I'd be interested to know why the code posted works on historical data, but not real-time data.

        Comment


          #5
          I'm glad to hear you've resolved the issue. I had been seeing slightly different results in my testing. I saw the unexpected results on both historical (disconnected) data, and live (connected) data. However, at the moment a connection was made, I saw the lines snap to their proper positions for an instant, then immediately jump back to the unexpected positions.

          If using BarsArray as an argument resolved the issue for you, then I suspect the reason you were seeing good results when disconnected was that there were not any bar updates being processed, thus eliminating the possibility of your logic being processed on the wrong data series update, which would have come into play once live data started coming in for both elements of BarsArray.
          Dave I.NinjaTrader Product Management

          Comment


            #6
            Yes, that makes sense. I had the same result when connected, with a momentarily correct chart followed by the incorrect one. But no problems at all since I specified the references.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by andrewtrades, Today, 04:57 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            7 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X