Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling 'OnStateChange' method: INdex was outside the bounds of the array.

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

    Error on calling 'OnStateChange' method: INdex was outside the bounds of the array.

    Hi,

    I just want to appreciate the effort from support as this is my first post but I've been lurking around before today.

    I'm trying to enable my strategy but it's showing "Error on calling 'OnStateChange' method: Index was outside the bounds of the array." What I am trying to do is have the strategy run on a custom bar chart (much like a unirenko chart) with buy triggers based on the MACD on a secondary series (3200 tick) chart. I suspect it's because the strategy tries to run but it's hasn't gotten enough data so I pulled up a chart with both data series (the custom bar chart and the 3200 tick chart) with the MACD on the 3200 tick chart. From the Data Box, I can see the MACD data beginning on bar number 1 on the 3200 tick chart and bar number 134 on the custom bar chart but the MACD doesn't plot until bar 20 of the 3200 tick chart and bar 264 of the custom bar chart. I changed the 'Bars required to trade' in the strategy properties to 300 to see if that helps but it's not fixing the issue.

    I appreciate any help. Also, I'm very new to this and I am not a coder.

    #2
    I just want to add that in another strategy I created with Strategy Builder I used the same two charts (custom bar with 3200 tick chart as an additional series) but with a buy trigger based on the CCI indicator on the 3200 tick chart as an additional data series and it loaded fine.

    Comment


      #3
      Hello Tai Nguyen,

      Welcome to the NinjaTrader forums!

      The error is in OnStateChange() and likely before any data is processing in OnBarUpdate().

      What is the specific line of code causing the error?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        The log tab doesn't specify the line of code causing the error and the code compiled without errors so I am not sure. Is there a way to find out?

        Comment


          #5
          Hello Tai Nguyen,

          You will need to debug the script using prints to find the line causing the error.

          Below is a link to a forum post that demonstrates using prints to understand behavior.


          Add prints throughout OnStateChange(). What is the last print to appear before the error appears?
          If the line after the last appearing print is commented out does the error still occur?
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          25 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          120 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          63 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 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