Bug using Dynamic array

Questions about MultiCharts and user contributed studies.
HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Bug using Dynamic array

Postby HummerH1 » 04 Jan 2012

Hello

Here is my code

Code: Select all

var: Counter (0),J(0),MaxLines (0);

array: arrLineValue [] (0);

if date <> date[1] then
begin
Counter=Counter+1;
MaxLines = 6;
array_setmaxindex(arrLineValue,5);

arrLineValue[0] = 1;
arrLineValue[1] = 3;
arrLineValue[2] = 7;
arrLineValue[3] = 2;
arrLineValue[4] = 3;
arrLineValue[5] = 7;
end;

if Counter>=1 then
begin
For J = 0 To MaxLines-1
begin
if array_getmaxindex(arrLineValue) <> 5 then raiseruntimeerror(Text("arrLineValue",MaxLines ));

if Close crosses above arrLineValue[J] then
Print("Test");
end;
end;
it's giving me an error : ":: Array bounds. Wrong index value: 1."

How come? I've set the max index to 5. And it really is 5. I check it just before with:

Code: Select all

if array_getmaxindex(arrLineValue) <> 5 then raiseruntimeerror(Text("arrLineValue",MaxLines ));


Thanks for your help!

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Bug using Dynamic array

Postby TJ » 04 Jan 2012

Hello

Here is my code

Code: Select all

var: Counter (0),J(0),MaxLines (0);

array: arrLineValue [] (0);

if date <> date[1] then
begin
Counter=Counter+1;
MaxLines = 6;
array_setmaxindex(arrLineValue,5);

arrLineValue[0] = 1;
arrLineValue[1] = 3;
arrLineValue[2] = 7;
arrLineValue[3] = 2;
arrLineValue[4] = 3;
arrLineValue[5] = 7;
end;

if Counter>=1 then
begin
For J = 0 To MaxLines-1
begin
if array_getmaxindex(arrLineValue) <> 5 then raiseruntimeerror(Text("arrLineValue",MaxLines ));

if Close crosses above arrLineValue[J] then
Print("Test");
end;
end;
it's giving me an error : ":: Array bounds. Wrong index value: 1."

How come? I've set the max index to 5. And it really is 5. I check it just before with:

Code: Select all

if array_getmaxindex(arrLineValue) <> 5 then raiseruntimeerror(Text("arrLineValue",MaxLines ));


Thanks for your help!
It seems the array does not like the keyword combination "Cross above" or "Cross over".

The code works fine with "Cross below" or "Cross under".

I do not have an explanation. Maybe it is a bug. I will let MultiCharts tech support explain it.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: Bug using Dynamic array

Postby Dave Masalov » 05 Jan 2012

HummerH1, TJ,

This is how Cross keywords are implemented in MultiCharts. MC addresses previous values of the variable when determining the cross. But dynamic array had no values in its previous state (size=0).

This behavior has been described here: https://www.multicharts.com/pm/viewissu ... ue_no=MC-7

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: Bug using Dynamic array

Postby HummerH1 » 05 Jan 2012

That does not make any logical sense to me.
What solution can you offer instead?
What the point of having dynamic array if you cannot use it?
Why does it work with cross under and not cross over?
Why sometime I get error on index 3 only?

And I have a Counter. I do the code only if Counter=1.
So in its previous status, the array was already initialized.

User avatar
Katrin Yanenko
Posts: 55
Joined: 28 Nov 2011
Has thanked: 18 times
Been thanked: 23 times

Re: Bug using Dynamic array

Postby Katrin Yanenko » 05 Jan 2012

Hi,

The function Crosses Over is serial, it checks the previous values of both arguments ( in your case it’s "close" and "arrLineValue[J]").

In this case the array is already initialized and has dimension equal 5 on the current bar, and when referring to its values ​​on previous bars the error returns.

If you put this operation

Code: Select all

array_setmaxindex(arrLineValue,5);
out of this condition then there would not be an error:

Code: Select all

var: Counter (0),J(0),MaxLines (0);
array: arrLineValue [] (0);
array_setmaxindex(arrLineValue,5);

if date <> date[1] then
begin
Counter=Counter+1;
MaxLines = 6;

//array_setmaxindex(arrLineValue,5);
arrLineValue[0] = 1;
arrLineValue[1] = 3;
arrLineValue[2] = 7;
arrLineValue[3] = 2;
arrLineValue[4] = 3;
arrLineValue[5] = 7;
end;

if Counter>=1 then
begin
For J = 0 To MaxLines-1
begin
if array_getmaxindex(arrLineValue) <> 5 then
raiseruntimeerror(Text("arrLineValue",MaxLines ));

if Close crosses above arrLineValue[J] then
Print("Test");
end;
end;
Best Regards,
Katrin Yanenko
Last edited by Katrin Yanenko on 05 Jan 2012, edited 2 times in total.

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: Bug using Dynamic array

Postby HummerH1 » 05 Jan 2012

I'll try to put the

Code: Select all

array_setmaxindex(arrLineValue,5);
outside the if also.
I must have it inside as well.

But just for my understanding:

Why "crosses under" is acting different?
It also should check previous values of my arguments. Doesn't it?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Bug using Dynamic array

Postby TJ » 05 Jan 2012

HummerH1, TJ,

This is how Cross keywords are implemented in MultiCharts. MC addresses previous values of the variable when determining the cross. But dynamic array had no values in its previous state (size=0).

This behavior has been described here: https://www.multicharts.com/pm/viewissu ... ue_no=MC-7
Dave:

Thanks for the explanation.
You are correct, the array was not initialized in the prev state.
My oversight.

User avatar
Katrin Yanenko
Posts: 55
Joined: 28 Nov 2011
Has thanked: 18 times
Been thanked: 23 times

Re: Bug using Dynamic array

Postby Katrin Yanenko » 05 Jan 2012

Dear HummerH1,
Why "crosses under" is acting different?
Probably, the cross happens even before checking the non-initialized values.
It also should check previous values of my arguments. Doesn't it?
Yes, it should.

Best Regards,
Katrin Yanenko

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: Bug using Dynamic array

Postby HummerH1 » 05 Jan 2012

Quote:
Why "crosses under" is acting different?


Probably, the cross happens even before checking the non-initialized values.
Probably not. There is no cross at all. Otherwise according to my code, i would get the word "test" printed.
Quote:
It also should check previous values of my arguments. Doesn't it?

Yes, it should.
So why there is no any error????
It's really working too weirdly to say it is just the way it should work....


Anyway your solution is not working for me. Because the value of the max index is the variable "MaxLines" which is calculated in the first "if". So the previous value will stil be 0.

Is it a way i can check what is the previous value of the variable and if it is set or not?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Bug using Dynamic array

Postby TJ » 05 Jan 2012

try this modification: (original code with the = removed)

Code: Select all


if Counter > 1 then

....

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: Bug using Dynamic array

Postby HummerH1 » 05 Jan 2012

Thanks. Nope, it still fails.

I saw this 2 options:

1- I can put an else so as the first and second part of the code will not be called at the same iteration. But then I lose the first bar (15mins). So maybe I'll change de "if" to:

Code: Select all

if date of data2 <> date[1] of data2
where data2 will be a series based on a lower interval bar.

2- Or I can get rid off this dynamic array and use a regular one with the higher maxindex i could ever need.

User avatar
Katrin Yanenko
Posts: 55
Joined: 28 Nov 2011
Has thanked: 18 times
Been thanked: 23 times

Re: Bug using Dynamic array

Postby Katrin Yanenko » 06 Jan 2012

Quote:
Why "crosses under" is acting different?


Probably, the cross happens even before checking the non-initialized values.
Probably not. There is no cross at all. Otherwise according to my code, i would get the word "test" printed.
Quote:
It also should check previous values of my arguments. Doesn't it?

Yes, it should.
So why there is no any error????
It's really working too weirdly to say it is just the way it should work....


Anyway your solution is not working for me. Because the value of the max index is the variable "MaxLines" which is calculated in the first "if". So the previous value will stil be 0.

Is it a way i can check what is the previous value of the variable and if it is set or not?
Both in cross over and in cross under the previous values of arguments are checked. This is obligatory, otherwise how could we define the cross itself?

Please try the following condition which guarantees that the previous value has been already initialized.

Best Regards,
Katrin Yanenko

HummerH1
Posts: 66
Joined: 13 Sep 2011
Has thanked: 6 times
Been thanked: 1 time

Re: Bug using Dynamic array

Postby HummerH1 » 10 Jan 2012

Please try the following condition which guarantees that the previous value has been already initialized.
which following condition?

User avatar
Katrin Yanenko
Posts: 55
Joined: 28 Nov 2011
Has thanked: 18 times
Been thanked: 23 times

Re: Bug using Dynamic array

Postby Katrin Yanenko » 10 Jan 2012

This condition:

Code: Select all

if Counter>=1 and counter[1] >= 1 then
Best Regards,
Katrin Yanenko


Return to “MultiCharts”