Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:



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



    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 lightsun47, Today, 03:51 PM
      0 responses
      4 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      8 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      44 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      13 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      8 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X