PureBytes Links
Trading Reference Links
|
Ed,
That code I posted for the loop was taken from your post #108133 on
the topic of Hold & ValueWhen Functions, being the same as what
Bernard quoted back.
And while your change of adding the "if (j == i + waitPeriod)"
statement appears to make it work correctly, except for the end of the
array still, it's actually superfluous and will work without that bit
of code altogether (in fact that statement will never be true since
the j loop will have already terminated by then). Ultimately it's just
the removing of the later i=j that fixes it. You can get exactly the
same results with just this:
for (i = 0; i < BarCount - waitPeriod; i++) {
if (Setup[ i ]) {
for (j = i + 1; j < i + waitPeriod; j++)
Setup[ j ] = 0;
}
}
The only difference with this, and the last change of yours, is that
it's slightly less efficient in that i will run through all values
instead of skipping the ones used by j.
Regards,
GP
--- In amibroker@xxxxxxxxxxxxxxx, "Edward Pottasch" <empottasch@xxx>
wrote:
>
> 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: amibroker@xxxxxxxxxxxxxxx
> 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
>
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|