Announcement

Collapse
No announcement yet.

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

    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.

          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.

              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

                    Comment


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

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      571 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      330 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      101 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      548 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      549 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X