Robot enabled. Stop order management activated. Attempting to toggle trailing stop. CurrentBar: 51701, BarsInProgress: 0, Count: 51703, T3Period: 20 T3 indicator values count: 51703 Error in TrailingStopClick: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index Stack Trace: at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource) at NinjaTrader.NinjaScript.Series`1.IsValidDataPoint( Int32 barsAgo) at NinjaTrader.NinjaScript.NinjaScriptBase.IsValidDat aPoint(Int32 barsAgo) at NinjaTrader.NinjaScript.Strategies.StopEntryRobotT 3.TrailingStopClick(Object sender, RoutedEventArgs e) in xxx.cs:line 350
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
barsAgo issue when accessing indicator
Collapse
X
-
barsAgo issue when accessing indicator
I just added indicator to my strategy, attached, and I'm getting barsAgo errors. I cannot figure out what the issue is and AI is of no help either. To trigger the error, click Robot:OFF button, then click on T3 Trail: ON button. Exception details are in the output:
HTML Code:Tags: None
-
Hello MiCe1999,
Thank you for your post.
This message is indicating the specific index requested from a collection does not exist. Indexes must be a non-negative number and less than the size of the collection. The error may be indicating the index requested is larger than the number of elements in the collection.
In the case of barsAgo values with Series, any barsAgo index must be less than CurrentBar (the total number of bars is the size of a Series collection).
The help guide discusses ‘Make sure you have enough bars in the data series you are accessing’ .Code:// require BarsInProgress 0 to have 3 bars processed, require BarsInProgress 1 to have 4 bars processed if (CurrentBars[0] < 3 || CurrentBars[1] < 4) return; Print(Times[0][3]); // this does not cause an error as CurrentBars[0] is equal to or greater than 3 Print(Times[1][4]); // this does not cause an error as CurrentBars[1] is equal to or greater than 4 Print(Times[0][5]); // this line of code will cause an invalid index error. When CurrentBars[0] is 4 there is no bar 5 bars ago
NinjaScript > Educational Resources > Tips > Make sure you have enough bars in the data series you are accessing
You'll need to debug the script using prints to determine which line of code in particular is hitting the indexing error. Once you identify which line is getting the error, you can further debug by printing out the size of the collection being accessed along with the index you are trying to access.
https://support.ninjatrader.com/s/ar...nd-TraceOrders
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment