Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Odd error; strategy immediately disables.

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

    Odd error; strategy immediately disables.

    Hey folks. I'm hoping you can help. I've been away for the holidays and came back. I made 1 tweak to my algorithm and now it immediately disables whenever I try to use it on a chart. I've found this in the logs (thankfully). Can anyone tell me what now doesn't work?

    Log says:
    Strategy '[strategyname]': Error on calling 'OnBarUpdate' method on bar 0: 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.

    All I did was add an if statement within another if statement. Now it tells me that I'm trying divide by 0 or something. I literally changed nothing.

    #2
    Hello alphatango,

    The error means you are using an invalid index on a collection.

    For example using Close[1] when CurrentBar is 0 will cause this error.

    Below is a link to a forum post that discusses.


    What is the specific code in your script causing an error?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      It doesn't tell me what line throws the error.
      in fact, it compiles just fine. No errors. I'm not sure why it compiles, but throws errors post-editting.

      Now it won't activate and says this.
      Strategy 'MultiTimeframe': Error on calling 'OnStateChange' method: Index was outside the bounds of the array.

      I'm not sure how to force it to load the array more than I already have.

      EDIT:

      Found out it was something to do with plotting for a couple of moving averages I can't seem to get it to propagate. I was told I could add multiple timeframes to a chart. Not sure if I need to start a new thread for this.
      Last edited by alphatango; 01-15-2025, 05:47 PM.

      Comment


        #4
        Hello alphatango,

        AddDataSeries() must be called in State.Configure.

        Indicators must be instantiated in State.DataLoaded (on OnBarUpdate()).

        "It doesn't tell me what line throws the error."

        You will need to add debugging prints to determine which line is causing the error.

        Below is a link to a support article on adding debugging prints to understand behavior.


        Try printing the line number before each assignment, method call, and branching command you have added.


        " I was told I could add multiple timeframes to a chart"

        Plots are synchronized to the primary series only. But you can add an additional data series, and plot the information from that added series over the primary series.

        Below is a link to an example.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I found what was giving me grief. The print statement helped get me through.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          59 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          134 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          74 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          50 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X