Announcement

Collapse
No announcement yet.

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.

    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 NullPointStrategies, Today, 05:17 AM
      0 responses
      46 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      66 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X