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

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 Stanfillirenfro, Today, 07:23 AM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by FitSpressoHonest, Today, 09:14 AM
          0 responses
          1 view
          0 likes
          Last Post FitSpressoHonest  
          Started by Davide999, 05-18-2023, 03:55 AM
          4 responses
          557 views
          1 like
          Last Post kcwasher  
          Started by rexsole, Today, 08:39 AM
          2 responses
          7 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          6 responses
          29 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X