Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        0 responses
        0 views
        0 likes
        Last Post helpwanted  
        Started by Brevo, Today, 01:45 AM
        0 responses
        6 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        384 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X