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

How to tag highs/lows for later comparision

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

    How to tag highs/lows for later comparision

    Hello,
    By using Print() I'm able to see the CurrentBar # and High/Low price for a certain period.
    For example:
    Code:
    Print(Time[0] + " Lowest Low = " +  lowest_low);//gets most recent low
    Print(Time[0] + " Lowest Low Bar # is " + lowLine);//gets bar # at most recent low
    Print(Time[0] + " CurrentBar # is " + CurrentBar);//current bar when condition is met
    I would now like to compare those numbers and prices. For instance bar 558 had a high of 49.12 and bar 591 had a high of 50.33, and bar 850 had a high of 50.55. Just using a lookback period isn't working. A loop might work, but I'm not sure how to do it. Can someone give me some help with this please?

    #2
    Hello CaptainAmericaXX,

    Thanks for your post.

    Not entirely certain what your goal is but you can use the MAX and MIN methods to find the high and low over a period of time.

    MAX(High, 20)[0] will produce the highest value in the previous 20 bars looking at each bars High value.
    MIN (Low, 20)[0] will produce the lowest value in the last 20 bars looking at each bars Low value.


    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,
      Thanks for your reply. Sorry for being unspecific. The Max/Min won't work in this case as the barsAgo will never be a specific period. The highs (for example) could be 10 bars apart or 100. I'll never know until the market does it's thing. I can however tag those high's and print the specific bar number associated with that specific high. My question is: Is there a way to say, "High's were made on bars 550, 571, and 900. Which of those was highest?" Is there a way to make a specific variable for each high and then compare the prices associated with those variables?

      Comment


        #4
        Hello CaptainAmericaXX,

        Thanks for your reply.

        There are a number of ways that this can be done. It almost sounds like you might want to consider using the Swing indicator as that will identify the swing high/low points and allow you to go back and get them. Please see the helpguide here: http://ninjatrader.com/support/helpG...nt7/?swing.htm

        Alternatively if you can define an algorithm for determining what point you want to keep and what to not keep, you could keep a simple array. Example where lastSavedHigh is the previous high.

        if (High[0] > lastSavedHigh) highArray[2] = High[0] (or highArray[2] = CurrentBar)

        Or if you do a double array you can save price and bar

        if (High[0] > lastSavedHigh) highArray[2])
        {
        highArray[2,0] = High[0];
        highArray[2,1] CurrentBar;
        }

        Here is a C# reference to arrays: https://msdn.microsoft.com/en-us/library/9b9dty7d.aspx
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Paul,
          Thank you for the idea on arrays. I believe that the double array is the answer to my issue. However I have never understood arrays. I did study the msdn reference info you directed me to and I'm still lost. I know you guys aren't there to teach basic programming BUT could you throw me a few more bones? I'm unsure of how to declare this array and then how to use the array after the condition. I have the algorithm worked out, just need to understand the array.
          Thanks

          Comment


            #6
            Hello CaptainAmericaXX,

            Thanks for your reply.

            In the region variables:

            private double [ , ] nameofyourarray;

            Initialize section:

            nameofyourarray - new double [9,1]; // where 9 and 1 are real integer values to specify the size of each side. As this is zero based, 9 x1 is really 10 x 2. You can of course use whatever numbers you wish. You could specify it as a [10,2] understanding that it is really 11 x 3 but then you can use the numbers 1 -10 and 1-2 as needed.

            In the onbarupdate() section (using the zero based array)

            nameofyourarray[0,0] = ...... Price of first high
            nameofyourarray[0,1] = ...... Bar of first high

            nameofyourarray[1,0] = ...... Price of second high
            nameofyourarray[1,1] = ...... Bar of second high

            nameofyourarray[2,0] = ...... Price of third high
            nameofyourarray[2,1] = ...... bar of third high
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              How to tag highs/lows for later comparison

              Hello Paul,
              I have been searching for a way to tag double values, thank you. However, I do not understand the meaning of your statement;-
              nameofyourarray - new double [9,1]; // where 9 and 1 are real integer values to specify the size of each side
              What does the 1st index refer to and what does the 2nd index refer to?

              I am looking at two double values in FX trades, ( High + 'x' pips and Low - 'y' pips) to provide price values for Entry and Exit Stop Orders. For Long trade, I want to keep the first EnterLongStop value to remain active, even if higher values occur before the Order is Executed.
              Then to exit a Long order, I want the highest value to be used in the ExitLongStop order, even if more and lower values are found, before the Exit order is executed.
              My attempt is shown below:-
              private double [ , ] bGa;
              private double [ , ] iSLa;

              bGa = new double [2,2];
              iSLa = new double [2,2]; I don't know if the [2,2] is correct

              These occur on the same candle
              bGa[0,0] = (High[0] + FxBG * TickSize);
              bGa[0,1] = CurrentBar;
              iSLa[0,0] = (Low[0] - FxISL * TickSize);
              iSLa[0,0] = CurrentBar;

              To say that I do not know what I am doing is an understatement, so any help would be much appreciated.
              Thank you from oldhiker

              Comment


                #8
                Hello oldhiker,

                Thanks for your post.

                The statement nameofyourarray - new double [9,1]; contains a typo and should be nameofyourarray = new double [9,1]; What it is doing is to declare a new 2 dimensional array. It may be easier to suggest that the 2 dimensional array is like a spreadsheet, so one number is how many rows and the other is how many columns. So in the example there are 10 rows numbered 0 - 9 and 2 columns numbered 0 & 1.

                In your example:
                bGa[0,0] = (High[0] + FxBG * TickSize);
                bGa[0,1] = CurrentBar;
                iSLa[0,0] = (Low[0] - FxISL * TickSize);
                iSLa[0,0] = CurrentBar;

                I think your last one is overwriting the previously placed low value with the currentbar number. The index should be iSLa[0,1] = CurrentBar;

                This link may be of some help: http://www.tutorialspoint.com/csharp...nal_arrays.htm
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  How to tag highs/lows for later comparison

                  Hello Paul, your description and the link to the C# tute was most enlightening. Now I have an understanding, using the spreadsheet reference.

                  Comment


                    #10
                    How to tag highs/lows for later comparison

                    Paul, your specific reference is a gold mine for information on may other aspects of C#, that will allow me to get a better understanding of the coding in NinjaTrader.
                    A late Christmas present that will be very useful in future.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,607 views
                    0 likes
                    Last Post aligator  
                    Started by jaybedreamin, Today, 05:56 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post jaybedreamin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    6 responses
                    19 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by Jon17, Today, 04:33 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Jon17
                    by Jon17
                     
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    15 views
                    0 likes
                    Last Post Javierw.ok  
                    Working...
                    X