• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Get the Last Bar's Pixel Location

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

    How to Get the Last Bar's Pixel Location

    Hi,

    I need to constrain an anchor to not go past the last visible bar on the chart. For example, if I have a chart that has a Right Side Margin of say 350 pixels. How do I prevent the anchor from being dropped/moved beyond the last visible bar?

    I can find the right-most bar by using chartsBars.ToIndex but how do I compare the pixel location of ToIndex with ChartAnchor dataPoint?
    Last edited by Kabua; 10-17-2019, 07:31 AM.

    #2
    Hello Kabua,

    Thank you for your post.

    You could get the index of the last visible bar with ChartBars.ToIndex, yes. You can then get the chart-canvas coordinate of that bar using GetXByBarIndex:

    https://ninjatrader.com/support/help...bybarindex.htm

    Once you've got the application pixels, you can convert them to device pixels using ConvertToHorizontalPixels:

    https://ninjatrader.com/support/help...ntalpixels.htm

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you. I had the GetXByBarIndex but I couldn't figure out the ConvertToPixel function.

      For anyone looks for the same here's my code:

      Code:
                      var point = dataPoint.GetPoint(chartControl, chartPanel, chartScale);
      
                      var lastX = chartControl.GetXByBarIndex(GetAttachedToChartBars(), chartControl.PrimaryBars.ToIndex - 1);
                      var lastDevicePixelX = ChartingExtensions.ConvertToHorizontalPixels(lastX, chartControl.PresentationSource);
      
                      if (point.X > lastDevicePixelX)
                      {
                          // Do something...
                      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by darkgreen, Today, 03:35 PM
      0 responses
      3 views
      0 likes
      Last Post darkgreen  
      Started by GTBrooks, Today, 02:44 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChrisL  
      Started by GLFX005, Today, 12:22 PM
      4 responses
      41 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by AspenHiker, Today, 08:37 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by MartinT, Yesterday, 01:12 PM
      3 responses
      16 views
      0 likes
      Last Post MartinT
      by MartinT
       
      Working...
      X