• 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

1 bar discrepancy between ISeries<T>.Count and real count

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

    1 bar discrepancy between ISeries<T>.Count and real count

    For all Series data types, both ISeries<T> and others like TimeSeries, Count method returns one bar more than one can access in reality. To see this, place the following in OnBarUpdate:
    Code:
    Print("CurrentBar+1: " + (CurrentBar + 1) + " OpenCount: " + Open.Count + " TimeCount: " + Time.Count);
    and reload the indicator/strategy
    On the last bar loaded you should see all of the above being equal, in reality CurrentBar+1 (since it is 0 indexed) is still one less than, eg. Open.Count or Time.Count.

    One additional test you can do is in OnStateChange() in the State.Transition from State.Historical you can place the following:
    Code:
    Print("Test: " + Open[Open.Count - 1]);
    Having all historical data loaded the attempt to access Open.Count - 1 index results in out of range error.

    #2
    Hello gregid,

    When the scripts starts, the Count is set to the full slot collection including the first real-time bar that will exist and will start building as real-time data is received.

    To find the last historical bar, you would want to subtract 1 to find the bar previous to this first real-time bar, and adjust minus 1 as the index is 0 based and does not start at 1.

    The first real-time bar, before it is populated will be null.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea

      Correct me if I am wrong, but I think I know what/why it is happening (and is needed).
      The default indexing is for Calculate.OnEachTick (or OnPriceChange) but in order to allow for easy referencing when Calculate.OnBarClose, NT implements custom indexer that is the default - 1 for OnBarClose case. So when the bar closes the new item is instantly added to the Series but OnBarClose indexing uses 0 for referencing recently closed bar and skipping the newly created.
      I have updated my code taking Calculate method into cosideration and it seems to be working fine for all cases now.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ajay8000, Yesterday, 11:31 PM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Marco  
      Started by simjs, Yesterday, 11:23 PM
      0 responses
      5 views
      0 likes
      Last Post simjs
      by simjs
       
      Started by akuntysh, Yesterday, 10:41 PM
      0 responses
      4 views
      0 likes
      Last Post akuntysh  
      Started by Wolf1, Yesterday, 08:26 PM
      0 responses
      7 views
      0 likes
      Last Post Wolf1
      by Wolf1
       
      Started by pparmley, Yesterday, 04:30 PM
      0 responses
      9 views
      0 likes
      Last Post pparmley  
      Working...
      X