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!
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
NinjaTrader
Swing strategy
Collapse
X
-
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!Tags: None
-
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
-
Originally posted by NinjaTrader_Jim View PostHello 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.Attached Files
Comment
-
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
-
Originally posted by Auxtin Maquieyra View PostHello, 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!
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 Stanfillirenfro, Today, 07:23 AM
|
1 response
3 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
20 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment