Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar changing on me

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

    CurrentBar changing on me

    Something weird is happening with CurrentBar. I'm using that value in OnRender and the value of CurrentBar is changing while live ticks are coming in. I took a screenshot of the output window showing the value of CurrentBar changing on the same bar.

    Current Bar (CB) is the first value I'm printing to the output window. After CB you can see the Date/Time of that bar.
    Attached Files

    #2
    Hello TheBarChartist,

    Thank you for your post.

    We are trying to re-create what you are experiencing, so we may investigate further could you provide the code used for your outputs as seen in your screenshot?

    Comment


      #3
      Sure thing. This is inside OnRender:

      Code:
      if (Bars == null || sessionCount == 0) {return;}
                  
      int lastBarOnChart = CurrentBar - ChartBars.ToIndex + 1;
      int firstBaronChart = CurrentBar - ChartBars.FromIndex + 1;
                  
      Print("CB=" + CurrentBar.ToString() + ", Date/Time = " + ToDay(Time[0]).ToString() + "/" + ToTime(Time[0]).ToString() + ", Index = " + ChartBars.ToIndex.ToString() + ", SBs = " + SessionBars.Count.ToString() + ", LastBar = " + lastBarOnChart.ToString());
      SessionBars is just a Series tracking the CurrentBar of the first bar of a user defined session.

      Comment


        #4
        Hello TheBarChartist,

        The CurrentBar is not available to OnRender(). How are you passing CurrentBar to OnRender? What type of NinjaScript object is this? Are you using an indicator or chart style?
        Last edited by NinjaTrader_PatrickH; 04-25-2016, 02:38 PM. Reason: Typo

        Comment


          #5
          Maybe that's the problem. I access CurrentBar frequently in OnRender so that I can get values of Series that I need to update for various lines all over the charts.

          In this case the indicator is nothing special: it's just a OHL indicator with the plots customized to look the way I like, so I'm attaching it.

          The problem I was having was that CurrentBar was changing on me - always decreasing by 1020 - and so my lastBarOnChart variable was going negative. Consequently when I accessed the Series holding the bar number of the first bar of each session I was getting an error and the indicator was crashing. I worked around this problem by forcing lastBarOnChart to be no lower than zero.

          I've since changed the indicator to pass CurrentBar to OnRender via a dummy variable. I'll do this in my other indicators as well.
          Attached Files

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          668 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          377 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X