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 helpwanted, Today, 03:06 AM
      1 response
      10 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      9 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      387 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X