Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Swing strategy

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

  • aligator
    replied
    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;
    }

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • Auxtin Maquieyra
    replied
    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

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • Auxtin Maquieyra
    started a topic Swing strategy

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by Newtrader101, Today, 06:36 AM
1 response
13 views
0 likes
Last Post NinjaTrader_Spencer  
Started by Rainmakersg, Today, 12:34 AM
3 responses
20 views
0 likes
Last Post NinjaTrader_Jim  
Started by guidoisot, Today, 03:09 AM
2 responses
21 views
0 likes
Last Post guidoisot  
Started by ntbone, Yesterday, 10:31 PM
3 responses
23 views
0 likes
Last Post NinjaTrader_Jason  
Started by 7robert, Yesterday, 11:38 PM
3 responses
29 views
0 likes
Last Post 7robert
by 7robert
 
Working...
X