Page 1 of 1

Help with an Array bounds error

Posted: 10 Nov 2011
by Laurent
Ok I have simplified my code, here is the buggy part.

It's the code of a signal, when I want to optimize it (Length from 4 to 100), I got the following error: "Array bounds. Wrong index value: 51"
Inputs:

MAType ( 0 ),
Length ( 20 ),
ConfirmBars ( 1 );

Variables:
MAValue ( 0 ),
NBars ( 0 );

switch (MAType)
begin

// 0 - SMA - Simple Moving Average
case 0:
MAValue = AverageFC(C, Length);

// 1 - SmMA - Smoothed Moving Average
case 1:
MAValue = SmoothedAverage(C, Length);

// 2 - TMA - Triangular Moving Average
case 2:
MAValue = TriAverage(C, Length);

default:
MAValue = AverageFC(C, Length);
end;

condition1 = C > MAValue;
if condition1 then
NBars = NBars + 1
else
NBars = 0;

condition1 = currentBar > ConfirmBars and NBars = ConfirmBars;
if condition1 then
buy ( "LE-Price-Over-MA" ) next bar at market;
Why do I got this error?
(I have MC 7.2)

Re: Help with an Array bounds error

Posted: 10 Nov 2011
by TJ
Ok I have simplified my code, here is the buggy part.

It's the code of a signal, when I want to optimize it (Length from 4 to 100), I got the following error: "Array bounds. Wrong index value: 51"
Inputs:

MAType ( 0 ),
Length ( 20 ),
ConfirmBars ( 1 );

Variables:
MAValue ( 0 ),
NBars ( 0 );

switch (MAType)
begin

// 0 - SMA - Simple Moving Average
case 0:
MAValue = AverageFC(C, Length);

// 1 - SmMA - Smoothed Moving Average
case 1:
MAValue = SmoothedAverage(C, Length);

// 2 - TMA - Triangular Moving Average
case 2:
MAValue = TriAverage(C, Length);

default:
MAValue = AverageFC(C, Length);
end;

condition1 = C > MAValue;
if condition1 then
NBars = NBars + 1
else
NBars = 0;

condition1 = currentBar > ConfirmBars and NBars = ConfirmBars;
if condition1 then
buy ( "LE-Price-Over-MA" ) next bar at market;
Why do I got this error?
(I have MC 7.2)
have you tried not using AverageFC?

Re: Help with an Array bounds error

Posted: 10 Nov 2011
by Laurent
I have the bug with a lot of other function,

What I do not understand is that code works perfectly by removing the switch, and by using if/else if/else...

HMMM? Is it a bug or is it normal?
I really do not understand

Re: Help with an Array bounds error

Posted: 10 Nov 2011
by Laurent
Ok so,

here the results of my testing:

1.
No error with if/else if/else with AverageFC
Error with switch and AverageFC

2.
No error with if/else if/else with Average
No error with switch and Average

I do not understand why there is a difference for the first case.
Why the switch is interpreted differently of a if/else if/else??

Should I report it?

Re: Help with an Array bounds error

Posted: 10 Nov 2011
by TJ
Ok so,

here the results of my testing:

1.
No error with if/else if/else with AverageFC
Error with switch and AverageFC

2.
No error with if/else if/else with Average
No error with switch and Average

I do not understand why there is a difference for the first case.
Why the switch is interpreted differently of a if/else if/else??

Should I report it?
Is the problem with the switch?

Here is the key:

Error with switch and AverageFC
No error with switch and Average

Re: Help with an Array bounds error

Posted: 10 Nov 2011
by TJ
Ok so,

here the results of my testing:

1.
No error with if/else if/else with AverageFC
Error with switch and AverageFC

2.
No error with if/else if/else with Average
No error with switch and Average

I do not understand why there is a difference for the first case.
Why the switch is interpreted differently of a if/else if/else??

Should I report it?
have you compared the optimization results between:

1.
No error with if/else if/else with AverageFC

2.
No error with if/else if/else with Average

Re: Help with an Array bounds error

Posted: 11 Nov 2011
by Laurent
I have compared data between

"switch Average" and "if/else if/else Average", I have the same results.

So I do not understand, switch should work as if/else if/else by the interpreter/compiler.

Re: Help with an Array bounds error

Posted: 11 Nov 2011
by Laurent
Well, I have done some little functions to try to see where's the bug.

I have restarted my MC and retry... and no more bug.............!!!!!!!!!!!!!!!!!

I'm investigating... :)