Australian (ASX) Stock Market Forum

Amibroker - For loops backwards

Joined
16 January 2008
Posts
111
Reactions
0
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 = C;
}

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
 
Re: For loops backwards

Hi Skinner - not sure what you are asking here, is this post in the right area?
 
Re: 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 = C;
}

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.
 
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
 
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.
 
Perhaps one of the mods can amend the title inc Amibroker, so thread get the AmiBroker Attention.
 
Top