Interesting. I've often wondered how to do that.
I have created a function that can be called based on this code. I have
quickly
checked the results and think it works as intended.
It is 1 based - not zero based. To calculate the 4th Highest Close - pass C to
array etc.
functionNextHiRank ( array, Lookback, element )
// to get 4th Highest High in last 10 periods call NextHiRank (H,10,4)
{
element = Min(Lookback, element)-1;
bi = BarIndex();
a = LastValue( bi );
b = a - Lookback;
z = IIf( bi >= b, array, Null);
for( i = b;i <= a;i++ )
{
for( j = i + 1;j <= a;j++ )
{
if( z[i] < z[j] )
{
temp = z[i];
z[i] = z[j];
z[j] = temp;
}
}
}
returnz[b + element];
}
Based on the same logic - here is the NextLoRank function.
functionNextLoRank ( array, Lookback, element )
{
element = Min(Lookback, element)-1;
bi = BarIndex();
a = LastValue( bi );
b = a - Lookback;
z = IIf( bi >= b, array, Null);
for( i = b;i <= a;i++ )
{
for( j = i + 1;j <= a;j++ )
{
if( z[i] > z[j] )
{
temp = z[i];
z[i] = z[j];
z[j] = temp;
}
}
}
returnz[b + element];
}
Thanks to Inquisitive Voyager for a great idea.
Best Regards
Rick Osborn
________________________________
From: Inquisitive Voyager <[email protected]>
To: [email protected]
Sent: Fri, August 6, 2010 10:54:13 AM
Subject: Re: [amibroker] Multiple Higher Highs in Amibroker? [1 Attachment]
[Attachment(s) from Inquisitive Voyager included below]
(1) find the attachment
(2) this code works in commentary window only.
(3)copy paste the code.dont overlay.
On Thu, Aug 5, 2010 at 7:29 PM, n7wyw <dennisljohnston@ hotmail.com> wrote:
>I want to find out the three highest highs for the past 100 periods. Highest
>give only the top value, how can I get the next highest value and the next?
>
>Thanks,
>
>Dennis
>
>