Is that have any limitation under 2-D array?  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
~Zola~
Posts: 22
Joined: 28 Nov 2016
Has thanked: 5 times
Been thanked: 1 time

Is that have any limitation under 2-D array?

Postby ~Zola~ » 11 Jul 2019

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; namespace PowerLanguage.Indicator{ public class Z_testing_array2 : IndicatorObject { private int[,] Score = new int[24001,1]; public Z_testing_array2(object _ctx):base(_ctx){} protected override void Create() { // create variable objects, function objects, plot objects etc. } protected override void StartCalc() { // assign inputs } protected override void CalcBar(){ // indicator logic Score[(int)Bars.Open[0],0] = Score[(int)Bars.Open[0],0] + 1; Score[(int)Bars.Open[0],1] = (int)(Bars.Close[0] - Bars.Open[0]); Output.WriteLine(" Bar:{0} Score:{1}, Time:{2}", Score[(int)Bars.Open[0], 1], Score[(int)Bars.Open[0], 0], Bars.BarUpdateTime); } } }
MC shows that "System.InderOutOfRangeException"

~Zola~
Posts: 22
Joined: 28 Nov 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Is that have any limitation under 2-D array?

Postby ~Zola~ » 11 Jul 2019

I have downscale the 2D array to double[3400, 1], but the issue still happen. I only resolve the error when I change it to single array. How could I resolve this problem?

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Is that have any limitation under 2-D array?

Postby ABC » 12 Jul 2019

~Zola~,

your code declares a 2-D array with one row only and consequently you receive an error when you try to access the second row.
Take a look at the link below for examples on how to create multi dimensional arrays in C#:
https://docs.microsoft.com/en-us/dotnet ... nal-arrays

Regards,

ABC

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; namespace PowerLanguage.Indicator{ public class Z_testing_array2 : IndicatorObject { private int[,] Score = new int[24001,1]; public Z_testing_array2(object _ctx):base(_ctx){} protected override void Create() { // create variable objects, function objects, plot objects etc. } protected override void StartCalc() { // assign inputs } protected override void CalcBar(){ // indicator logic Score[(int)Bars.Open[0],0] = Score[(int)Bars.Open[0],0] + 1; Score[(int)Bars.Open[0],1] = (int)(Bars.Close[0] - Bars.Open[0]); Output.WriteLine(" Bar:{0} Score:{1}, Time:{2}", Score[(int)Bars.Open[0], 1], Score[(int)Bars.Open[0], 0], Bars.BarUpdateTime); } } }
MC shows that "System.InderOutOfRangeException"
Last edited by ABC on 12 Jul 2019, edited 2 times in total.

~Zola~
Posts: 22
Joined: 28 Nov 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Is that have any limitation under 2-D array?

Postby ~Zola~ » 12 Jul 2019

~Zola~,

your code doesn't declare a 2-D array and consequently you receive an error when you try to access a second dimension of a one dimensional array.
Take a look at the link below for examples on how to create multi dimensional arrays in C#:
https://docs.microsoft.com/en-us/dotnet ... nal-arrays

Regards,

ABC

Code: Select all

using System; using System.Drawing; using System.Linq; using PowerLanguage.Function; namespace PowerLanguage.Indicator{ public class Z_testing_array2 : IndicatorObject { private int[,] Score = new int[24001,1]; public Z_testing_array2(object _ctx):base(_ctx){} protected override void Create() { // create variable objects, function objects, plot objects etc. } protected override void StartCalc() { // assign inputs } protected override void CalcBar(){ // indicator logic Score[(int)Bars.Open[0],0] = Score[(int)Bars.Open[0],0] + 1; Score[(int)Bars.Open[0],1] = (int)(Bars.Close[0] - Bars.Open[0]); Output.WriteLine(" Bar:{0} Score:{1}, Time:{2}", Score[(int)Bars.Open[0], 1], Score[(int)Bars.Open[0], 0], Bars.BarUpdateTime); } } }
MC shows that "System.InderOutOfRangeException"
Thanks for your reply.
I declared "private int[,] Score = new int[24001,1];", anything I still missing?

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Is that have any limitation under 2-D array?

Postby ABC » 12 Jul 2019

Thanks for your reply.
I declared "private int[,] Score = new int[24001,1];", anything I still missing?
~Zola~,

check out the link I posted.

Regards,

ABC

~Zola~
Posts: 22
Joined: 28 Nov 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Is that have any limitation under 2-D array?

Postby ~Zola~ » 12 Jul 2019

Thanks for your reply.
I declared "private int[,] Score = new int[24001,1];", anything I still missing?
~Zola~,

check out the link I posted.

Regards,

ABC
the link "int[,] array2Da = new int[4, 2]"
my code "int[,] Score = new int[24001,1]"

It seems that no difference.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Is that have any limitation under 2-D array?  [SOLVED]

Postby ABC » 12 Jul 2019

~Zola~,

when you declare an array in C# the number within brackets is the number of elements. The first element however is at index 0.

That's why int[,] array2Da = new int[4, 2] creates a two dimensional array with four rows and two columns, but int[,] Score = new int[24001,1] is not really two dimensional as it has 24001 rows, but just one column (although technically it is a two dimensional array).

Regards,

ABC


the link "int[,] array2Da = new int[4, 2]"
my code "int[,] Score = new int[24001,1]"

It seems that no difference.

~Zola~
Posts: 22
Joined: 28 Nov 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Is that have any limitation under 2-D array?

Postby ~Zola~ » 12 Jul 2019

~Zola~,

when you declare an array in C# the number within brackets is the number of elements. The first element however is at index 0.

That's why int[,] array2Da = new int[4, 2] creates a two dimensional array with four rows and two columns, but int[,] Score = new int[24001,1] is not really two dimensional as it has 24001 rows, but just one column (although technically it is a two dimensional array).

Regards,

ABC


the link "int[,] array2Da = new int[4, 2]"
my code "int[,] Score = new int[24001,1]"

It seems that no difference.

Thank you very for your guide.
This is my fault.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Is that have any limitation under 2-D array?

Postby ABC » 12 Jul 2019

~Zola~,

you are welcome. I am glad to hear that you have got it working.

Regards,

ABC


Return to “MultiCharts .NET”