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

Does finding the MAX and MIN require a series value??? Please help

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

    Does finding the MAX and MIN require a series value??? Please help

    Hello I would be grateful for a push in the right direction finding the Min and Max of a double value returned by a method...
    I am aware the MAX and MIN functions which only return a iSeries value such as price.

    I need to return the Highest of a double Value that is calculated by a method above the OnBarUpdate function for a range of say n bars ago...

    I have found several old methods for other software platforms and old methods that might have worked on NinjaTrader7.
    I think we would all be extremely disappointed if Ninja Trader 8 can only return the greatest of least of Prices and Volume So I am very hopeful that I have just been trying the wrong techniques that apply only to other languages.

    I am very tired but will check back in thank you so much for reading this.

    #2
    So to simplify let us suppose I am finding how much a new Puppy in the window might cost...

    Code:
        private double puppy(double price)
    {
    return $
    }
    protected override void OnBarUpdate()
    {
    
    // Let us pretend a Samoyed ($$$$) was sold 3 days ago and all other dogs were mutts ($) we wish to consider the last n = 10 dogs ago... What logic should I do to return the Price of the most expensive Puppy sold n bars ago?
    
    
    // I have found I can find the total price of the dogs sold with a operation like the following:
    double TOTALpriceAllPuppies    = 0;
            for (int i=0; i< n; i++)
            {
                TOTALpriceAllPuppies += puppy(price);
            }
     
    
    }
    // Please note I am NOT talking about High[0] or Close[0] or Volume or any of the iSeries values I am talking about PUPPIES: )
    I am certain there must be a way to retrieve the Greatest double value for a Method but the last several hours I have been stuck in a circle.

    I would be extremely grateful for any indicator or solution I can observe which does this. There is no way that C# can only handle the iSeries terms.

    Thank you so much for your time reading about puppies.
    Last edited by DynamicTest; 03-25-2024, 11:20 PM.

    Comment


      #3
      Hello DynamicTest,

      You could save whichever is largest the value stored by the variable or the value returned from the method call.

      highestValue = Math.Max(highestValue, MyCustomMethod());

      Below is a link to sample logic that uses a loop over a series, but could be used for any collection.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello DynamicTest,

        You could save whichever is largest the value stored by the variable or the value returned from the method call.

        highestValue = Math.Max(highestValue, MyCustomMethod());

        Below is a link to sample logic that uses a loop over a series, but could be used for any collection.
        https://ninjatrader.com/support/foru...96#post1113896


        I understand you are saying that NinjaScript does allow working with values returned by a Method.
        I do not understand from your example how to return the greatest method value withing n=30 bars.

        In the example you attached you use a loop that could be restricted to Period=30 "bars" and then you which of those last period bars where the Highest High occurred.
        You then fetch the High that occured at the number of bars ago...

        However I am uncertain how to do that for the Method value which is only a double value and NOT an ISeries<double>

        Comment


          #5
          For instance working with the custom value I calculate how Puppy a Puppy is...
          Code:
           private double puppy(double price)
          {
          return $
          }​
          Now that I know with verified certainty how Puppy a Puppy is on every single bar, we go to the main coding section where I need to retrieve the Most Puppy that happened within the last Period=30 bars...

          Code:
          protected override void OnBarUpdate()
          {
          highestValue = Math.Max(highestValue, MyCustomMethod());
          }

          highestValue = Math.Max(highestValue, MyCustomMethod());
          But how is the highestValue to be restricted to the Period of 30 bars???
          Shouldn't highestValue be set a double value elsewhere in the code??? Or something else???

          Thank you very much for this guidance into using the custom values. I am able to do this sam caclulation on other programs and platforms but I am just getting used to NinjaScript which seems to be very similar to C# which is great.

          Comment


            #6
            Hello DynamicTest,

            You would need to save the values to a collection, such as a Series<double> or an array or list, if you want to get a range.
            If this is meant to be values for specific bars, then a Series<double> should be used.


            HighestBar() and LowestBar() returns the bar number of the bar with the highest value or lowest value from the current bar to a specific bar ago (not a custom range).


            The HighestBarInRangeExample shows getting the highest bar in a specific range of bars.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Also a Happy national Puppy day from this past Saturday...

              Comment


                #8
                Thank you ChelseaB I had imagined there would be some way to use values returned by a Method. It would be shocking if Method values were unusable.

                Comment


                  #9
                  A Method is just a subroutine that can be called anytime. You still need some code inside the Method, could be your loop, so the Method can return your answer. You would still need to store stuff in some kind of list or series so the loop inside the Method can retrieve the answer.
                  Last edited by eDanny; 03-26-2024, 11:12 AM.
                  eDanny
                  NinjaTrader Ecosystem Vendor - Integrity Traders

                  Comment


                    #10
                    Hello DynamicTest,

                    The HighestBarInRangeExample does return the value from a method.
                    May I confirm you have reviewed this script?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I will look at this when I get back from work thanks again.


                      I have solved some of the other problems I was doing to ask about just with blind luck trial and error and the system is reasonably consistent with C#

                      Are there any other examples or even default indicators on Ninjatrader where Method Values are used ??? I am certain I am not the first user who needs to code with Values from Methods

                      Comment


                        #12
                        Hello DynamicTest,

                        Understanding methods would fall under general C# education, which is a prerequisite for starting NinjaScript.


                        Below is a link to another script that declares a method.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Populating arrays might not be very efficient or elegant. I know C# likes strucs to stay as simple as possible.

                          Lastly would it be possible to do some sort of loop for the past Period=30 bars where if the current Puppy is more Puppy than the last puppy we use the current puppy else we stick to using the last puppy???

                          Code:
                            
                          
                          double PuppiestPuppy= 0;
                          
                           for (int i=0; i< Period; i++)
                                      {
                                      if (Puppy[0] > Puppy[1])
                                        {
                                      PuppiestPuppy = Puppy[0]
                                        }
                                      else
                                       {
                                        PuppiestPuppy = Puppy[1]
                                       }
                                      }​
                          This seems like a straightforward way if ISeries<double> values are not commonly used with Method Values ????

                          Comment


                            #14
                            Hello DynamicTest,

                            You can use any logic you prefer for your custom code.

                            The example I provided does use a series in a method.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_ChelseaB View Post
                              Hello DynamicTest,

                              You can use any logic you prefer for your custom code.

                              The example I provided does use a series in a method.
                              Very well let me try some of the various possibilities after work. I might want to leave an actual example that cvan be seen easily in a search. I don't think I am the first person to have the confusion I do.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Haiasi, 04-25-2024, 06:53 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post Massinisa  
                              Started by Creamers, Today, 05:32 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post Creamers  
                              Started by Segwin, 05-07-2018, 02:15 PM
                              12 responses
                              1,786 views
                              0 likes
                              Last Post Leafcutter  
                              Started by poplagelu, Today, 05:00 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post poplagelu  
                              Started by fx.practic, 10-15-2013, 12:53 AM
                              5 responses
                              5,407 views
                              0 likes
                              Last Post Bidder
                              by Bidder
                               
                              Working...
                              X