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

Getting the highest historical value of an indicator

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

    Getting the highest historical value of an indicator

    Hi there,

    I recently figured out that the way I coded one of my inquiries has an error. I'm attempting to get the highest figure of ADX in the past 30 bars. Here's what I have right now:

    Code:
    adx_highest = Math.Round((ADX(9)[HighestBar(ADX(9), 30)]),2);
    Unfortunately, this just returns the ADX value of the past 30 bars where the value of the bar was considered, and not the highest ADX value.

    How can I re-write this line of code to correctly obtain the highest value of ADX in the past 30 bars?

    Thanks in advance!

    #2
    Hello Spiderbird,

    Thanks for writing in.

    I would recommend using the MAX method for finding the Maximum value over a period.

    adx_highest = MAX(ADX(9), 30)[0]; // Current the current maximum of ADX(9) over last 30 bars

    Helpguide reference: http://www.ninjatrader.com/support/h...aximum_max.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Bugger all! I forgot to add the bracketed number you featured in your solution. I had tried MAX previously but didn't put it in the right way.

      Thanks for your help!

      Comment


        #4
        Along the same lines, is it possible to obtain the Max (or Min) for the entire data dataseries or indicator? How would that be done? Thank you!

        Comment


          #5
          Hello cb4gusto22,

          Thanks for your post.

          To look over an entire dataseries, I would tend to use:

          if (CurrentBar == 0)
          {
          hHigh = Low[0]; .// seed values on 1st bar, also assumes lowest/highest does not occur on first bar!
          lLow = High[0]; // seed values on 1st bar
          return;
          }

          if (High[0] > hHigh) hHigh = High[0]; // If current High is higher, save the value
          if (Low[0] < lLow) lLow = Low[0]; // if the current low is lower, save the value.

          // You could also save the bar number of when the highest high or lowest low was found as well, if you were in need of a reference point

          When the ninjascript is loaded it will process bar by bar to the right edge covering the entire dataseries.

          Please let me know if I can be of further assistance.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thanks Paul.

            Another related question: is there a way to determine how many values are in a dataseries (i.e. the length) without using CurrentBar or anything like that? I'm using a dataseries and it is being populated in OnPositionUpdate, not OnBarUpdate. That is why CurrentBar wouldn't work. Thanks for the help!

            Comment


              #7
              Hello cb4gusto22,

              Thanks for your reply.

              For the dataseries you can add .Count to the dataseries name to obtain the size of the dataseries.
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                hmmm. Using ".Count" actually gives me the number of price bars, not the expected number of values in the dataseries that is being populated in OnPositionUpdate. This leads me to believe that the dataseries class necessarily accesses OnBarUpdate automatically. Is this correct? Is there a way to either (1) use a dataseries in OnPositionUpdate so that it only stores real values and no dummy OnBarUpdate values OR (2) or, if (1) is not possible, extract out the real values (both the actual value and count)? Thank you!

                Comment


                  #9
                  Originally posted by cb4gusto22 View Post
                  hmmm. Using ".Count" actually gives me the number of price bars, not the expected number of values in the dataseries that is being populated in OnPositionUpdate. This leads me to believe that the dataseries class necessarily accesses OnBarUpdate automatically. Is this correct? Is there a way to either (1) use a dataseries in OnPositionUpdate so that it only stores real values and no dummy OnBarUpdate values OR (2) or, if (1) is not possible, extract out the real values (both the actual value and count)? Thank you!
                  Use a List<T>.

                  Comment


                    #10
                    Hello cb4gusto22,

                    Thanks for your reply

                    The dataseries would be synced.

                    As koganam has suggested a List<T> would better suit your needs. Here is a link to further information about List<T>: https://msdn.microsoft.com/en-us/lib...(v=vs.90).aspx
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Guys, was able to use List<T> to make a solution.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by algospoke, Yesterday, 06:40 PM
                      2 responses
                      24 views
                      0 likes
                      Last Post algospoke  
                      Started by ghoul, Today, 06:02 PM
                      3 responses
                      15 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by jeronymite, 04-12-2024, 04:26 PM
                      3 responses
                      46 views
                      0 likes
                      Last Post jeronymite  
                      Started by Barry Milan, Yesterday, 10:35 PM
                      7 responses
                      23 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Started by AttiM, 02-14-2024, 05:20 PM
                      10 responses
                      181 views
                      0 likes
                      Last Post jeronymite  
                      Working...
                      X