Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetBarIdxByX on second data series

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

    GetBarIdxByX on second data series

    HI

    Sorry having difficulty forcing a mouse point to focus on BarsArray[0]
    I currently use this which works fine - but it fails when I add a second data series. What is the correct notation to force it to use BarsArray[0]?
    thanks
    Code:
    barIdx                 = ChartBars.GetBarIdxByX(chartControl, clickPixelX);

    #2
    Hello Mindset,

    That is referencing the primary specifically. If you are seeing an error we would need that detail to better assist here.
    ChartBars references the primary chart series: https://ninjatrader.com/support/help.../chartbars.htm

    In multi series scripts you may need to add additional conditions into your logic to prevent the secondary series from being used where the primary is currently being used. The X/Y related conversion methods would not be able to be used for a secondary series as that series is not charted.

    Comment


      #3
      I assumed that the primary would be dominant however I get an index issue in on render which I assume means it's looking at both bar collections?
      So if I want to force the script to ONLY look at barsarray[0] again how do I get that?
      Secondly here is my mousepoint method - anything I should be adding there to prevent errors in multiple series?
      Code:
      public void MiddleMouseButtonExample_MouseDown(object sender, MouseButtonEventArgs e)
      {
      if (e.MiddleButton == MouseButtonState.Pressed)
      {
      // convert e.GetPosition for different dpi settings
      clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.Get Position(ChartPanel as IInputElement).X, ChartControl.PresentationSource);
      clickPoint.Y = ChartingExtensions.ConvertToVerticalPixels(e.GetPo sition(ChartPanel as IInputElement).Y, ChartControl.PresentationSource);
      if (clickPoint.Y > 0)
      {
      clickSet = true;
      barIdx = -1;
      }
      // trigger the chart invalidate so that the render loop starts even if there is no data being received
      ChartControl.InvalidateVisual();//impacts performance so check if required
      e.Handled = true;
      }
      }

      Comment


        #4
        Hello Mindset,

        If you are getting an error in OnRender you may need to use Prints to identify why that's happening. I couldn't say why thats happening without seeing the specific code that threw the error and what values were observed at that time.

        The secondary series has nothing to do with rendering/ChartBars/Mouse events so that should be irrelevant. The objects you are using in the code provided point to specific series already which is the primary charted series.

        The GetBarIdxByX should not be able to throw a index error unless you supplied an X value which was not valid. If that resulted in an invalid bar ID and you used that ID for some other series that would cause an indexing error.

        If you are using items like Close.GetValueAt in OnRender you could instead specify the primary series by using Closes[0].GetValueAt.




        Comment


          #5
          Hi Jesse

          thanks for the input. I have already spent something like 10 hours trying to solve this error - I am just not that good at coding!!
          everything I do relates to x and y co ordinates - so I don't use getvalueat but rather GetYByValue.
          Let me do the print thing again and see if can highlight the issue more precisely.

          I should add my code works perfectly on one series so I didn't think it would be difficult to add a second series in the same panel - but I have used NT long enough to know that was a simplistic assumption.

          Comment


            #6
            Well 10 hours of work just to realise somehow I had missed the following in on bar update
            Code:
            if (BarsInProgress != 0 || CurrentBars[0] < 10 )
            return;

            Comment


              #7
              Jesse

              On doing some research I found that NT did a patch for a protected memory issue with SharpDx. I have installed the latest version but
              I too am now getting this error on random occasions - on using prints through the code I isolated the issue to this line
              Code:
              RenderTarget.DrawLine(stopStart, stopEnd, stopBrushDx,25 );
              Edit - resolved . I was disposing of a Brush whilst still trying to use it somewhere else
              Last edited by Mindset; 02-14-2022, 03:00 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              600 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              347 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              103 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              558 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              558 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X