Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Chartbars.FromIndex

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

    Using Chartbars.FromIndex

    While Using

    for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)

    To render a small square on top of all the bars in visible portion of the screen bars, I also get the same exact bars rendered in a different location if I scroll back.

    Why would this be happening?

    #2
    Hello r3n3v,

    If you scroll without adjusting the scale you should see the same number of bars being rendered. The FromIndex and ToIndex are the currently visible bars. To access data from the visible bars you need to use GetValueAt with the index in the loop.

    The example here shows getting the high of each visible bar in the loop, as you scroll you would have the same number of bars and different highs https://ninjatrader.com/support/help...tsub=fromindex

    Comment


      #3
      Ok Thanks makes sense! So how would we adjust the scale ?
      Last edited by r3n3v; 06-29-2023, 12:02 PM.

      Comment


        #4
        Hello r3n3v,

        By adjust the scale I mean if you use the mouse to drag on the X scale that will include or exclude bars. The FromIndex and ToIndex are the indexes of the bars currently scaled into the chart. If you had a chart where 50 bars are visible your loop would cover 50 bars. If you later dragged the scale so 100 bars are visible your loop now works over 100 bars. If you drag the chart to the left or right the amount of bars should generally stay the same so the loop continues to loop that amount of bars however the indexes change.

        Comment


          #5
          Ok I understand that now. Thanks. What I'm wondering is how would we go about int leaving the drawn squares only on the viewable screen and not have it duplicate when I scroll? Hope my question makes sense.

          Comment


            #6
            Hello r3n3v,

            What are your squares based off of?

            Nothing is left on the screen or duplicated when you scroll, each time you scroll the OnRender is re run for the new set of bars. Your logic needs to recalculate the squares based on the visible data.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            47 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            23 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            33 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            51 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            42 views
            0 likes
            Last Post CarlTrading  
            Working...
            X