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 burtoninlondon, Today, 12:38 AM
      0 responses
      5 views
      0 likes
      Last Post burtoninlondon  
      Started by AaronKoRn, Yesterday, 09:49 PM
      0 responses
      12 views
      0 likes
      Last Post AaronKoRn  
      Started by carnitron, Yesterday, 08:42 PM
      0 responses
      11 views
      0 likes
      Last Post carnitron  
      Started by strategist007, Yesterday, 07:51 PM
      0 responses
      13 views
      0 likes
      Last Post strategist007  
      Started by StockTrader88, 03-06-2021, 08:58 AM
      44 responses
      3,982 views
      3 likes
      Last Post jhudas88  
      Working...
      X