Find highest value

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #171673 quote
    mats6270
    Participant
    Junior

    Hello,

    In ProRealCode, how can  I find the highest, the second highest, 3rd highest value etc from any given number of values?

    /Mats

    #171676 quote
    robertogozzi
    Moderator
    Master

    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
     .
     .
     .
    
    #171677 quote
    robertogozzi
    Moderator
    Master

    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!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Find highest value


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
mats6270 @mats6270 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 8 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 06/13/2021
Status: Active
Attachments: No files
Logo Logo
Loading...