namespace NinjaTrader.NinjaScript.Indicators
{
public class aaTest : Indicator
{
private Series<int>[] aaa;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your nouveau custom Indicator here.";
Name = "aaTest";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = false;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
aaa= new Series<int>[8];
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0 || CurrentBar <= 10 )
return;
for(int i=0; i<=7; i++)
aaa[i][0]= 2;
}
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to initialize a Series array of int ?
Collapse
X
-
How to initialize a Series array of int ?
"Error on calling 'OnBarUpdate' method on bar 11: Object reference not set to an instance of an object." Compilation is OK. Thanks for your help
Code:Tags: None
-
Sorry but you didn't read carefully my original question and my code example.
I didn't ask for :
An array of int (very simple) BUT
for SERIES arrays of int.
I need 8 series of int per bar = one series array (of dimension eight) int per bar.
example :aaa[2][4] = the current prior/last 5th int element of the 3rd serie.
Thanks
Comment
-
Hello vindiou,
To declare a series of int arrays,
To initialize,Code:private Series<int[]>MySeries;
To set,Code:MySeries = new Series<int[]>(this, MaximumBarsLookBack.Infinite);
To Reference,Code:MySeries[0] = new []{0,1,2,3};
Please let us know if you need further assistance.Code:Print(MySeries[0][0] + " " + MySeries[0][1]);
Alan P.NinjaTrader Customer Service
- Likes 1
Comment
-
Thanks but that still isn't what I need.
I don't need a Series int array
BUT
an array of Series int
This is why I declared :
private Series<int>[] aaa;
Maybe I should initialize aaa to : ?
for (int i=1; i<=8; i++)
aaa[i] = new Series<int>(this,MaximumBarsLookBack.TwoHundredFif tySix);
The compiler seems to accept this, but how do I set aaa?
Moreover, how do I reference aaa if for example, I need to know what was the value of the 4th last/prior element of my 3rd Series for the current bar?
aaa[3][4] doesn't seem to work...Last edited by vindiou; 08-28-2018, 12:33 AM.
Comment
-
Hello vindiou,
In your code you could set aaa with,
aaa[0][i]= 5;
And you could reference the 4th element of the third series with,
aaa[3][4]
Assuming its been set and is not null.
I would suggest you look into Lists in C# as they are easier to work with,
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
-
Sorry but your solution doesn't work, try it.
Indicator 'aaTest': Error on calling 'OnBarUpdate' method on bar 11: Object reference not set to an instance of an object.
aaa[i][0]= 5; OR aaa[0][i]= 5; gives the same error message
BTW, my question is on arrays, not lists.
Here's the code :
Code:namespace NinjaTrader.NinjaScript.Indicators { public class aaTest : Indicator { private Series<int>[] aaa; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your nouveau custom Indicator here."; Name = "aaTest"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = false; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; IsSuspendedWhileInactive = true; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { aaa= new Series<int>[8]; } } protected override void OnBarUpdate() { if (BarsInProgress != 0 || CurrentBar <= 10 ) return; for(int i=0; i<=7; i++) aaa[i][0]= 5; } } }
Comment
-
Hello vindiou,
If you would like a series where each slot in the series contains 8 values, you could use,
Code:private Series<int[]>MySeries1;
Code:else if (State == State.Configure) { MySeries1 = new Series<int[]>(this, MaximumBarsLookBack.Infinite); }If this is not what you’re looking for, please provide more information on what you’re trying to do exactly, as the following is confusing.Code:protected override void OnBarUpdate() { if(CurrentBar<100) return; MySeries1[0]= new int[8]; for(int i=0; i<=7; i++) { MySeries1[0][i]= i; } foreach(int i in MySeries1[0]) { Print(i.ToString()); } }
I don't need a Series int array
BUT
an array of Series int
I didn't ask for :
An array of int (very simple) BUT
for SERIES arrays of int.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
-
I don't understand why you have difficulties to understand my original request.
I feel like you are trying to avoid to answer to it and find another solution because of some reason, maybe NinjaTrader hasn't implemented this.
Once again, I don't need a single Series of an int Array
I need an Array of Series (of int type).
Do you understand the difference between ??
private Series<int[]>MySeries1;
and
private Series<int>[] MySeries1;
Why didn't you test my last code and tell me what's wrong with it?
ThanksLast edited by vindiou; 08-29-2018, 01:31 PM.
Comment
-
Hello vindiou,
Thank you for your response.
To create, initialize, and set the values of an Array of Series<int> please see the basic code below. I have also attached the indicator for your reference to this post.
Please keep in mind we do not provide programming education nor do we provide debugging assistance.
Please let me know if you have any questions.Code:public class TestArrayOfSeriesType : Indicator { private Series<int>[] SeriesArray; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @""; Name = "TestArrayOfSeriesType"; } else if (State == State.DataLoaded) { SeriesArray = new Series<int>[8]; for (int i = 0; i < SeriesArray.Length; i++) SeriesArray[i] = new Series<int>(this, MaximumBarsLookBack.TwoHundredFiftySix); } } protected override void OnBarUpdate() { SeriesArray[0][0] = CurrentBar; Print(""); Print(Time[0]); Print(SeriesArray.Length); Print(SeriesArray[0][0]); } }Attached Files
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
576 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment