Amibroker - For loops backwards - Aussie Stock Forums

# Thread: Amibroker - For loops backwards

1. ## Amibroker - For loops backwards

The following code works if I iterate forward through the for loop but doesn't work as illustrated below, iterating backwards.

for( i = Barcount; i > 0; i-- )
{

a[i] = C[i];
}

Plot( a, "", 1,1);

I want to loop through the bars from newest to oldest, examining information from selected bars. Any idea how to do this?

Regards

john

2. ## Re: For loops backwards

Hi Skinner - not sure what you are asking here, is this post in the right area?

3. ## Re: For loops backwards

Originally Posted by skinner36
The following code works if I iterate forward through the for loop but doesn't work as illustrated below, iterating backwards.

for( i = Barcount; i > 0; i-- )
{

a[i] = C[i];
}

Plot( a, "", 1,1);

I want to loop through the bars from newest to oldest, examining information from selected bars. Any idea how to do this?

Regards

john

Skinner,

The latest bar is barcount-1, you cannot reference barcount or you will get a subscript out of range error.

4. ## Re: For loops backwards

Hi Skinner --

You wrote:
for( i = Barcount; i > 0; i-- )

It looks like this is AmiBroker code. If so, the index runs from 0 to BarCount-1. So the loop control statement should read:

for (i=BarCount-1; i=0; i--)

Thanks,
Howard

5. ## Re: For loops backwards

Now that was stupid of me. I forgot to say that it was amibroker code. Many thanks for your help guys.

6. ## Re: AmiBroker - For loops backwards

Perhaps one of the mods can amend the title inc Amibroker, so thread get the AmiBroker Attention.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Aussie Stock Forums