• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBar and Bars.Count off by 2?

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

    CurrentBar and Bars.Count off by 2?

    In debugging some code I found that that the Current Bar variable and the Bars.Count numbers are off by 2.

    Place the below code in any indicator or strategy and you will see what I am talking about, the last print statement shows them off.

    PHP Code:
    if(BarsInProgress == 0) Print(CurrentBar +" " BarsArray[0].Count); 

    #2
    Hello cutzpr,
    Thanks for your post.

    That is because CurrentBar and BarsArray[0].Count are not the same values. CurrentBar is a NinjaTrader value for how many bars are on the chart. Count is going to be how many indexes there are in that Array.

    There will always be two less CurrentBar indexs than the size(Count) of the array when using Calculate.OnBarClose. If you use Calculate.OnEachTick for the same code you can see that it will be one less(since it includes the currently building bar).
    JoshNinjaTrader Customer Service

    Comment


      #3
      Originally posted by cutzpr View Post
      In debugging some code I found that that the Current Bar variable and the Bars.Count numbers are off by 2.

      Place the below code in any indicator or strategy and you will see what I am talking about, the last print statement shows them off.

      PHP Code:
      if(BarsInProgress == 0) Print(CurrentBar +" " BarsArray[0].Count); 
      Count is indexed starting at 1: CurrentBar is indexed starting from 0. If using Calculate.OnBarClose, then the forming bar would not be counted in CurrentBar, but would be in Count, so there should be a difference of 2.
      Last edited by koganam; 03-10-2019, 06:29 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by mestril, Yesterday, 10:22 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by hir04068, Yesterday, 09:29 PM
      5 responses
      18 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by bubblegum, Today, 03:51 AM
      1 response
      3 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by johnnybegoode, 05-24-2019, 10:16 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by manugarc, Today, 01:15 PM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X