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
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
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,
Code:private Series<int[]>MySeries;
Code:MySeries = new Series<int[]>(this, MaximumBarsLookBack.Infinite);
Code:MySeries[0] = new []{0,1,2,3};
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); }
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.
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 DJ888, Today, 10:57 PM
|
0 responses
1 view
0 likes
|
Last Post
by DJ888
Today, 10:57 PM
|
||
Started by MacDad, 02-25-2024, 11:48 PM
|
7 responses
158 views
0 likes
|
Last Post Today, 10:23 PM | ||
Started by Belfortbucks, Today, 09:29 PM
|
0 responses
7 views
0 likes
|
Last Post
by Belfortbucks
Today, 09:29 PM
|
||
Started by zstheorist, Today, 07:52 PM
|
0 responses
7 views
0 likes
|
Last Post
by zstheorist
Today, 07:52 PM
|
||
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
151 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
Comment