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

My Strategy stopped working because yesterday is a Leap Day?

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

    My Strategy stopped working because yesterday is a Leap Day?

    I've been running this specific strategy for weeks no issue.

    Today is 3/1/24.

    Yesterday was 2/29/24 (leap day).

    My strategy ran no issues all day yesterday, but suddenly sometime during the new trading day (today), the strategy disabled & refuses to start with the following error:

    "Error on Calling 'OnbarUpdate' method on bar #: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

    I was able to find the offending code by doing a bunch of prints. After commenting out the line starting with "myBarsAgo", the strategy no longer errors out.

    Code:
    if ( ToTime(Time[0]) >= 00000 && ToTime(Time[0]) < 93000 ) {
            myBarsAgo = CurrentBar - Bars.GetBar(new DateTime(Time[0].Year, Time[0].Month, Time[0].Day-1, 18, 00, 00)); // fetch BarsAgo# for 6pm EST
            myOpenLevel = Open[myBarsAgo];
            }​
    I guess the good news is if I can't figure it out, I don't have to worry about this being an issue for another 4 years (aside from market replay).

    I can't wrap my head around as to why this is an issue, anyone have any ideas?

    Thanks!

    #2
    Hello squarewave,

    Thank you for your post.

    I am glad you were able to narrow down to the offending code by using prints. Are you able to reproduce the error when testing your strategy on the Playback connection with yesterday's data? I am curious what the results would be if you narrowed down the offending code even more, with individual prints for each value used in myBarsAgo, during the Playback connection on 2/29. This should help to know which exact value is throwing the "index out of range" error. We have a page in the help guide about this type of error here:


    For more information about Playback:


    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Thanks, that makes sense. I should have further investigated first before posting.

      So, it is not a leap day issue - that was a broad assumption on my part because I had not ever experienced this issue until today.

      I'm surprised I hadn't run into this error up until now, but technically it's a first day of the month issue:

      Time[0].Year = 2024
      Time[0].Month = 3
      Time[0].Day = 1
      Time[0].Day-1 = 0

      Since Day 0 doesn't exist, feeding that value to Bars.GetBar is causing the out of bounds error.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X