Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to find the min & max values of 8 computed variables

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

    How to find the min & max values of 8 computed variables

    What is the easiest way to find the min & max values for 8 values calculated during OnBarUpdate? I created an array with 8 elements, i think. How can the calculated values be put into the array? Below is what I have so far.

    public class Strengthindi : Indicator
    {
    private Series<double> [ ]StrengthArray; // declare an array to hold series double values
    }
    else if (State == State.Configure)
    {
    StrengthArray = new Series<double>[8]; // set array size at 8 elements

    }
    protected override void OnBarUpdate()
    {
    calc1[0] = bla1; calc2[0] = bla2 //and so forth for 8 Series<double> variables
    how to get these values as elements into [ ]StrengthArray ?
    }

    #2
    Hello Kicks.Spin,

    Thank you for your post.

    To clarify, you are wanting to save an array to a series for each bar, and then get the Min and Max values of the array for each bar, is that correct? Or are you simply wanting to store each of the 8 calculated values to a series and get the min/max of those series over a specific lookback period? If you can clarify the use case I am happy to point you in the correct direction.

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hi NinjaTrader_Kate:

      Correct. Goal is to save an array to a series for each bar, and then get the Min and Max values of the array for each bar. Thank you.

      Comment


        #4
        Hello Kicks.Spin,

        Thank you for your reply.

        This prior post from our forums goes over creating a series of arrays (this particular example uses an array of ints, but you could easily change that to doubles):



        The final post on that thread has a working example.

        Once you have your values assigned to the array, you can find the highest and lowest values with .Min and .Max. This publicly available link goes over how to use that:



        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Thanks Kate:

          It worked awesome setting up the array like that. But the following line results in a runtime error.
          MaxRSI[0] = RSIArray.Max()[0]; // MaxRSI is a Series double RSIArray has Series double slots
          "Indicator 'forex28': Error on calling 'OnBarUpdate' method on bar 248: At least one object must implement IComparable."
          What does that error rmean?

          I found the max & min this way. It also exposes the max & min index number which is useful
          MaxRSI[0] = RSIArray[0][0]; MinRSI[0] = RSIArray[0][0];
          for (int index = 1; index <=7; index++)
          {
          if (RSIArray[index][0] > MaxRSI[0] ) {MaxRSI[0] = RSIArray[index][0]; maxindex = index;} // this also exposes the maxindex also
          if (RSIArray[index][0] < MinRSI[0] ) {MinRSI[0] = RSIArray[index][0]; minindex = index;} // this also exposes the minindex
          }

          Although we solved the problem i would like to know what i did wrong. its cool to use less lines of code

          Comment


            #6
            Hello Kicks.Spin,

            Thank you for your reply.

            RSIArray is a series and each series slot holds an array, is that correct?

            It should be MaxRSI[0] = RSIArray[0].Max(); then to get the max value of the array held in the current RSIArray slot.

            Thanks in advance; I look forward to assisting you further.

            Comment


              #7
              Thanks for your response Kate:

              The syntax you suggested produces 2 error messages:
              1. Series<double> does not contain definition for 'Max' and best extension method overload has some invalid arguments
              2. argument cannot convert from Series<double> to system collections generic IEnumerable<int>

              RSIArray = new Series<double>[8]; // this is an array with 8 slots for each bar (that how i understand the data structure) initialized upon state == State.DataLoaded

              I appreciate your thoughts on this. but don't spend too much time on it as i have a workaround

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              579 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 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
              554 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X