Hello,
In ProRealCode, how can I find the highest, the second highest, 3rd highest value etc from any given number of values?
/Mats
It’s not straightforward and a bit time consuming (the more positions you want to know, the slower it is).
This example shows how to find out the Highest, the second highest and the third highest price within the last 100 periods:
N = 100
Max1 = highest[N](high) //Highest value
// now find the second highest value
Max2 = 0
FOR i = 0 TO (N - 1)
IF high[i] < Max1 THEN
Max2 = max(Max2,high[i]) //second highest value
ENDIF
NEXT
// now find the third highest value
Max3 = 0
FOR i = 0 TO (N - 1)
IF high[i] < Max2 THEN
Max3 = max(Max3,high[i]) //third highest value
ENDIF
NEXT
.
.
.
One of the new instructions in the pipe is rumored to be ARRAY sorting, This would make the above code useless in most cases.
Until then… it’s better than nothing!