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
Index errors
Collapse
X
-
Hello galsermil,
From the error alone all we could discern is that there is a problem retrieving data using [0], there would need to be more context to know why that causes a problem. If you have a sample of the code that is having a problem we can likely provide suggestions on ways that you could further tests that situation.
JesseNinjaTrader Customer Service
-
Her is the offending line and the print staement hatfllows but is never executed
SorRSignal[0] = SupportandResistanceDetection1.SandRSignal[0];
Print(Instrument.FullName + " " + Time[0] + " S or R Signal " + SorRSignal[0]);
Here is the error Message
2022-03-24 11:43:18:916|3|4|Strategy 'ITEntryStartegyCopy': Error on calling 'OnBarUpdate' method on bar 4948: Index was outside the bounds of the array.
Comment
-
Hello galsermil,
From the given code we could say that is either the assignment to the plot or the accessing of the plot. The Print only contains your custom plot which is something that could have that error.
I would suggest to do a test and see which of these items is the problem:
You could try:
Code:SorRSignal[0] = 1;
and:
Code:Print( SupportandResistanceDetection1.SandRSignal[0]);
JesseNinjaTrader Customer Service
Comment
-
Hello galsermil,
Are you sure its the print statement? If so are you able to remove the other code and continue to see the error? The purpose of the two tests I provided in post 4 is so that you know specifically what the problem is so there is no guessing.
You can try each of those by its self to see which produces the error, depending on which part produces the error would determine what you need to do next.
Code:SorRSignal[0] = 1;
Code:Print( SupportandResistanceDetection1.SandRSignal[0]);
JesseNinjaTrader Customer Service
Comment
-
Jesse,
I don't know whether you have surmised whether my problem is the indicator or the Strategy, both are my products. The indicator simply determines whether the current bar closes within 2 ticks of a pivot line. I have it divided into two sections for up bars and down bars as the 2 tick zone is on opposite side of the pivot line.
I'm referencing two indicators, PriorDayOHLC, and IT_FTreset which is third party. The IT indicator requires an add data series as does the Strategy. Sample and typical code for all lines of which there are 16 in each section: if (Close[0] <= (PriorDayOHLC1.PriorLow[0] + (Zone * TickSize)) && (Close[0] >= (PriorDayOHLC1.PriorLow[0])))
SandRSignal[0] = 1;
else if (Close[0] <= (IT_FTreset1.PP[0] + (Zone * TickSize)) && (Close[0] >= (IT_FTreset1.PP[0])))
SandRSignal[0] = -1;
In checking for each line if true, I assign a value to the SandSignal[0] so it is visible to the Strategy
In the Startegy, I merely determine if the signal is present on the same bar as other signals which will permit an entry. I do the entries after <IsFirstTickOfBar> which requires the use of SorRSignal[1] but I never get that far. because the Index error disables me.
Comment
-
Hello galsermil,
If both parts of the code make an error then you have multiple problems.
The description of what you are doing won't really help me to understand why you are getting an index error, you would have to debug the situation with each piece of code to see why that is happening.
If you get an error with only the following code:
Code:SorRSignal[0] = 1;
If you see an error with only this line, making sure you commented out all the other lines, then we could focus on that as the first issue. I would need to see how you defined the variable for SorRSignal and how you created it in OnStateChange to better understand the problem.
Based on the comments you provided it sounds like the series SorRSignal[0] = 1; may be working in other areas, if that is actually working then please double check the tests I had provided previously. You will need to comment out or remove all the code that is having an error so you no longer have the error, then try each test by its self to see what gives the error.
JesseNinjaTrader Customer Service
Comment
-
ITEntryStartegyCopy.cs Jesse,
The Print statement is not causing an error but the assignment is. I am uploading the .cs file for the strategy rather than trying to give you the pieces you are interested in. It is not very long..
Comment
-
Hello galsermil,
The Print statement is not causing an error but the assignment is.
Code:SorRSignal[0] = 1;
JesseNinjaTrader Customer Service
Comment
-
Hello galsermil,
The code we were talking about is not within that strategy so I don't know what part of that you need help with.
If we loop back to post #3 you gave the example code:
Code:SorRSignal[0] = SupportandResistanceDetection1.SandRSignal[0]; Print(Instrument.FullName + " " + Time[0] + " S or R Signal " + SorRSignal[0]);
The steps I provided could be used with any code where you see the index error, you have to first find what specific part of the code has the problem. All I was showing was how to break down the code you provided into individual parts so you can test which part has the index error. Without knowing the specific code which is having an index error then we cannot continue.
I do see that you have similar code to what we have been talking about, if that is the problem then you need to debug the indicator if the indicator use is what causes the index error:
Code:Print(Instrument.FullName + " " + Time[0] + " S or R Signal " + SupportandResistanceDetection1.SandRSignal[0]);
JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
||
Started by strategist007, Yesterday, 07:51 PM
|
0 responses
14 views
0 likes
|
Last Post Yesterday, 07:51 PM |
Comment