Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Searching for a second (lower) High

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Searching for a second (lower) High

    Hi all!

    I need to develop an indicator to seek for the second highest swing (it helps to discard unusual high points).

    Was trying this (it works), but don't know if is an efficient way to do this.

    Code:
    if (CurrentBar < hT + 2)
    return;
    p1= -99999;
    p2= -99999;
    v1= 99999;
    v2= 99999;
                for (int x = 0; x < hT  + 1; x++)
                {
                    {if (myIndicator[x] < myIndicator[x + 1]
                    && myIndicator[x + 2] < myIndicator[x + 1])
                        {if (myIndicator[x + 1] > p1)
                            {
                                p2=p1;
                                p1=myIndicator[x + 1];
                            }
                          else if (myIndicator[x + 1] > p2)
                            {
                                p2=myIndicator[x + 1];
                            } 
                        }
                    }
                }
                a = p2;
    In the lookback period (hT), first I check if a swing has ocurred, then I compare with stored values (p1 is the highest and p2 the second highest). If it finds a new high, it stores the value in p1 and the former high stored in p1 is now the second and is stored in p2. If the new high found is below p1 and above p2, it replaces the stored value in p2.

    Using Swing will be better? Can it be programmed to check for (user input) different highs (the third for example)? Perhaps I'm working in something already exists?

    Thanks in advance,

    Sergio

    #2
    sercava,

    Are you only looking for a method by which to identify the second highest number? You could simply use a list to store your swings, then sort them each time a new one is found. The second element in the list would be the right one. In order to avoid running out of memory you will probably want to remove the last element from the list each time you go over some set number of elements in size.

    Here is some information on lists : http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Before I try with list, I want to use Swing, but don't know how to get the bar where the swing occurs and its value. I have checked the help, but it only say:

      "You can access methods within this indicator to determine the number of bars ago a swing point occurred or the current swing value"

      Any help?

      Thanks in advance,

      Sergio

      Comment


        #4
        Hello,

        Please see example below and let me know if you have any questions.

        // Prints the bar value of the last Swing high
        Print("The bar count of the swing high bar is " + High[Math.Max(0, Swing(5).SwingHighBar(0, 1, 10))]);


        // Prints the value of the last Swing high
        Print("The high of the swing bar is " + Swing(5).SwingHigh[0]));


        let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        620 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        359 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        562 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        566 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X