GP,
I believe this is because you define i = j; outside of the j loop. This is not
what I do in my code. i=j is defines within the brackets of the loop.
So if you adjust your code for that our results are the same, see below
rgds, Ed
waitPeriod = 5;
Setup2 = ExRemSpan(1, waitPeriod-1);
Setup = 1;
for (i = 0; i < BarCount - waitPeriod; i++) {
if (Setup[ i ]) {
for (j = i + 1; j < i + waitPeriod; j++) {
Setup[ j ] = 0;
if (j == i + waitPeriod) {
i = j;
}
}
//i = j;
}
}
for (i = 0; i < BarCount; i++)
_TRACE(StrFormat("%1.0f - %1.0f", Setup[i], Setup2[i]))
----- Original Message -----
From: gp_sydney
To: [email protected]
Sent: Friday, June 15, 2007 2:15 PM
Subject: [amibroker] Re: Looping - our previous discussion
Ed,
Thanks for the info about attachments. I've only just started using
this forum.
Without seeing where you've put the trace statements for i & j, it's a
bit hard to comment on your test.
However, if I run the following code, using a wait period of 5 to make
it shorter:
waitPeriod = 5;
Setup2 = ExRemSpan(1, waitPeriod-1);
Setup = 1;
for (i = 0; i < BarCount - waitPeriod; i++) {
if (Setup[ i ]) {
for (j = i + 1; j < i + waitPeriod; j++) {
Setup[ j ] = 0;
}
i = j;
}
}
for (i = 0; i < BarCount; i++)
_TRACE(StrFormat("%1.0f - %1.0f", Setup[i], Setup2[i]));
The loop code is the same as Bernard posted from your original
message, I've just added the ExRemSpan alternative as a comparison
then traced the output.
The results start off like this:
1 - 1
0 - 0
0 - 0
0 - 0
0 - 0
1 - 1
1 - 0
0 - 0
0 - 0
0 - 0
0 - 1
1 - 0
1 - 0
0 - 0
0 - 0
0 - 1
0 - 0
1 - 0
1 - 0
0 - 0
The ExRemSpan function correctly (by my interpretation of the
requirement) gives a one followed by four zeroes repeated throughout
the array. However, the loop code skips one bar, giving two ones at
the end of each block of four zeros, make the repeat length six rather
than five.
Also, the end of the array looks like this:
0 - 1
0 - 0
0 - 0
1 - 0
1 - 0
0 - 1
0 - 0
0 - 0
0 - 0
1 - 0
1 - 1
1 - 0
1 - 0
1 - 0
The loop code hasn't continued right to the end of the array. The
changes I suggested fix both issues, making the loop identical to the
ExRemSpan function.
The potential overflow of the j loop is only if the code is changed to
the correction I mentioned. It won't happen with the original code.
Regards,
GP