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

Swing strategy

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

    Swing strategy

    Hello, im coding a strategy using swing indicator to plot divergences. I have a problem, it compiles well but then in the LOG i have the following error ; Error on calling on state change method: index was outside the bounds of the array. I atach the strtegy so you can see where is the mistake. Thanks in advance for your help!
    Attached Files

    #2
    Hello Auxtin Maquieyra,

    Thanks for opening the thread.

    The attached export is in a compiled assembly. I am unable to view the source code, so I could not give any hints for anything that stands out.

    That said, indexing issues are common run time errors that can be resolved with some debugging steps and some research on that type of error. We have a forum post that discusses indexing issues when we try to reference a bar before there are enough bars on a chart. This issue is seen in the OnBarUpdate() method, however the type of error can be referenced to help better understand the error you are receiving in OnStateChange(). Since the error reports it came from OnStateChange(), that method should be reviewed and checked for indexing issues.

    Since NinjaScript is based on C#, there are many instances where programmers in other projects have hit similar errors. If you are troubleshooting a programming issue and there is not a thread on this subject in our Support Forums, there may be information on this particular error externally that can useful to reference.

    I've included some publicly available resources to help better understand this type of error and how debugging steps can be taken to simplify the code and narrow down the exact issue.

    Making sure there are enough bars in the data series you are accessing (example of indexing runtime error) - https://ninjatrader.com/support/foru...ead.php?t=3170

    Debugging your NinjaScript code - https://ninjatrader.com/support/foru...ead.php?t=3418

    If you are looking for services to debug the code, we can have a representative of our EcoSystem reach out with information on NinjaScript Consultants who would be happy to debug the code at your request.

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello Auxtin Maquieyra,

      Thanks for opening the thread.

      The attached export is in a compiled assembly. I am unable to view the source code, so I could not give any hints for anything that stands out.

      That said, indexing issues are common run time errors that can be resolved with some debugging steps and some research on that type of error. We have a forum post that discusses indexing issues when we try to reference a bar before there are enough bars on a chart. This issue is seen in the OnBarUpdate() method, however the type of error can be referenced to help better understand the error you are receiving in OnStateChange(). Since the error reports it came from OnStateChange(), that method should be reviewed and checked for indexing issues.

      Since NinjaScript is based on C#, there are many instances where programmers in other projects have hit similar errors. If you are troubleshooting a programming issue and there is not a thread on this subject in our Support Forums, there may be information on this particular error externally that can useful to reference.

      I've included some publicly available resources to help better understand this type of error and how debugging steps can be taken to simplify the code and narrow down the exact issue.

      Making sure there are enough bars in the data series you are accessing (example of indexing runtime error) - https://ninjatrader.com/support/foru...ead.php?t=3170

      Debugging your NinjaScript code - https://ninjatrader.com/support/foru...ead.php?t=3418

      If you are looking for services to debug the code, we can have a representative of our EcoSystem reach out with information on NinjaScript Consultants who would be happy to debug the code at your request.

      Please let us know if we can be of further assistance.
      Thank you very much for your response, Can you now see the code?
      Attached Files

      Comment


        #4
        Hello Auxtin Maquieyra,

        Yes, I am able to see the source code now.

        The State.DataLoaded section of the OnStateChange() method stands out. You are referencing Closes[1] and Closes[2] in your swing indicators, but you have not added any additional data series.

        I suggest moving forward by reviewing the Multi Time Frame and Instruments documentation for a complete walk through and reference for creating and using Multi Series NinjaScripts. This information is publicly available; I'll provide a link below.

        Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

        Please let me know if I can be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Originally posted by Auxtin Maquieyra View Post
          Hello, im coding a strategy using swing indicator to plot divergences. I have a problem, it compiles well but then in the LOG i have the following error ; Error on calling on state change method: index was outside the bounds of the array. I atach the strtegy so you can see where is the mistake. Thanks in advance for your help!
          Auxin,

          You need to have at least 26 (same as your largest period used) bars for your MACD indicator first. Try this or something similar to make sure you have enough bars, it might work:


          Code:
          protected override void OnBarUpdate()
          {
              if (CurrentBar < 26)
                  return;
          }

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          2 views
          0 likes
          Last Post gentlebenthebear  
          Started by samish18, Yesterday, 08:31 AM
          2 responses
          9 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by Mestor, 03-10-2023, 01:50 AM
          16 responses
          389 views
          0 likes
          Last Post z.franck  
          Started by rtwave, 04-12-2024, 09:30 AM
          4 responses
          31 views
          0 likes
          Last Post rtwave
          by rtwave
           
          Started by yertle, Yesterday, 08:38 AM
          7 responses
          30 views
          0 likes
          Last Post yertle
          by yertle
           
          Working...
          X