Price at given bar Number

Hello all. I know this is something I should have learnt by now but alas, I forget too early.
I need to find the price at a given bar number. Say 10 bars from the last bar number.
I need some help
Thanks Guys

You could just Ref() it.
price10 = Ref( C, -10); Assuming price means Close array.

Another Array function ValueWhen() based on an expression
https://www.amibroker.com/guide/afl/valuewhen.html

If not looking for Array but a number, some arguments in AFL functions require a Number.
then

price10 = LastValue( Ref( C, -10) );

OR use Array subscript
Just mentioned this because it is a way, but it isn't for the AB average Joe. Use LastValue() instead.

bc = BarCount - 1;
ago = 10;         // bars ago
price = C;        // price or O H L
price10 = 0;
if ( bc > ago ) {
    price10 = price[ bc - ago ];
}

But then your question implies that you have to read the manual from the start.

3 Likes