• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 xsgex, Yesterday, 09:46 PM
          0 responses
          2 views
          0 likes
          Last Post xsgex
          by xsgex
           
          Started by Steve L, Yesterday, 09:36 PM
          0 responses
          1 view
          0 likes
          Last Post Steve L
          by Steve L
           
          Started by krugman25, Yesterday, 09:34 PM
          0 responses
          4 views
          0 likes
          Last Post krugman25  
          Started by indy73, Yesterday, 04:42 PM
          0 responses
          15 views
          0 likes
          Last Post indy73
          by indy73
           
          Started by Italianforex, Yesterday, 06:20 AM
          2 responses
          13 views
          0 likes
          Last Post gplatis
          by gplatis
           
          Working...
          X