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

    #16
    Hello DynamicTest,

    Just to confirm, you are saying the HighestBarInRangeExample is not an actual example?
    This example returns the highest bar from a method. Can you clarify why this would be an insufficient example?

    Note, even for other users, this would be general C# which you will need to learn first before learning the properties and methods of NinjaScript.

    Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services. This is so that we can maintain a high level of service for all of our clients as well as our associates.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.​
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Chelsea, here is your example applied to a Method where instead of using a High Iseries<double> directly I make a little function that doubles the value of the highs of every single bar
      This function agrees with your example however it uses a Method Value as requested.

      So this is might be a possible work around.
      Please note I only want help with the documentation of Ninjascript...

      Thank you and have a great day.
      Attached Files

      Comment


        #18
        Originally posted by eDanny View Post
        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.
        Thank you Danny there might be some opportunity working in that direction.
        I am currently only using the return at the end of the Method which I placed above the OnBarUpdate section.
        Originally I thought the Best Practices was to perform as many of the calculations as possible inside of the OnBarUpdate section but I am open to trying some things so long as it doesn't stray very far from Best Practices in C# and Ninjascript.

        Comment


          #19
          Hello DynamicTest,

          Unfortunately, I am not understanding.

          The example does use a method. Its defined on lines 54 to 69.

          Are you stating that the HighestBarAgoInRange method defined on line 54 is not a method? (It is a method)

          I'm not understanding, because you say you want the logic in a method, and its already in a method. This not making sense.

          "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..."

          This is your goal, correct?
          A double is a single value. There is no max or min of a single value.
          Save the values to a series which has a value for each bar on the chart.
          The method in the example returns the bar with the highest value.

          "I think we would all be extremely disappointed if Ninja Trader 8 can only return the greatest of least of Prices and Volume"
          The method will return the bar with the largest value for a Series<double> that uses a number. This doesn't have to a price or a volume, but can be any numbers. (Numbers are the only things we can compare to be greater or less than)

          "Chelsea, here is your example applied to a Method where instead of using a High Iseries<double> directly I make a little function that doubles the value of the highs of every single bar"

          I've not understood that your inquiry is about doubling a value on every new bar and there is no mention of this in your first post. That would be completely different logic that we haven't discussed.
          I am assisting with finding the bar with largest (or smallest) value in a range of bars.
          If you want to double the value on each bar, you can do this when assigning the series a value for that bar. (This would have nothing to do with finding the bar with the largest value)
          mySeries[0] = mySeries[1] * 2;

          "Originally I thought the Best Practices was to perform as many of the calculations as possible inside of the OnBarUpdate section"

          The HighestBarAgoInRange() method is called from OnBarUpdate() and runs from OnBarUpdate().
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Chelsea, I only doubled the High as an opportunity to use a value from a Method as the input instead of the default Iseries<double> values.

            I do agree that private int HighestBarAgoInRange(ISeries<double> inputSeries, int period, int barsAgo) is a method however no one has provided me with proof that it can be used on any value from a method.

            While it is an interesting snippet it might be possible it cannot work with a value that came from a Method.

            Comment


              #21
              For example here is the main bopdy of the example ChelseaB provided

              On the line int highestBarAgo = HighestBarAgoInRange(High, 10, 0); ChelseaB finds the Bar with the highest High of a range of 10 Periods...

              Perfectly cool.

              She then feeds this information to a Method which does successfully interpret that... Okay Cool
              I may do stupid things but I am absolutely 100% okay with this and I did review this the first time it was shared with me.

              Code:
                   protected override void OnBarUpdate()
                      {
                          if (State == State.Historical && CurrentBar == Count - 2)
                          {
                              int highestBarAgo = HighestBarAgoInRange(High, 10, 0);
                              Print(Time[highestBarAgo]);
                          }
                      }
                      
                      // must be called from a data driven method or used with TriggerCustomEvent
                      private int HighestBarAgoInRange(ISeries<double> inputSeries, int period, int barsAgo)
                      {
                          // check that maximumbarslookback is infinite?
                          // if (period + barsAgo > 256)            
                          
                          int startBarsAgo    = ((period + barsAgo - 1) < CurrentBar) ? (period + barsAgo - 1) : CurrentBar;
                          int returnVal        = startBarsAgo;
                          double currentHigh    = inputSeries[startBarsAgo];
              
                          //for (int index = CurrentBar - barsAgo; index < CurrentBar - period - barsAgo; ++index)
                          for (int index = startBarsAgo - 1; index >= barsAgo; --index)
                              if (inputSeries[index] > inputSeries[returnVal])
                                  returnVal = index;
              
                          return returnVal;
                      }​​

              Comment


                #22
                Hello DynamicTest,

                "no one has provided me with proof that it can be used on any value from a method."

                It compares numbers. If you are setting number values to a series (from any source, including from another completely unrelated method if this is what you want) it will work.

                "While it is an interesting snippet it might be possible it cannot work with a value that came from a Method."

                I completely disagree. It can work with any numbers saved to a series.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  In the example I shared back with ChelseaB you may see for yourself that this line of code
                  highestBarAgo = HighestBarAgoInRange(High, 10, 0);

                  will not receive a value from a method.

                  For example suppose I did as follows to output a value from a method. It will NOT compile as we discussed previously.
                  Perhaps I am not seeing something in the documentation of Ninjascript that would prevent this error as this doesn't seem universal to C#

                  Code:
                  public double doubleHigh(double High)
                              
                  {
                      return 2 * High;
                  }
                      
                          
                          protected override void OnBarUpdate()
                          {
                              
                              
                              double Highx2 = doubleHigh(High[0]);
                              
                              
                              if (State == State.Historical && CurrentBar == Count - 2)
                              {
                                  int highestBarAgo = HighestBarAgoInRange(doubleHigh, 10, 0);
                                  Print(Time[highestBarAgo]);
                              }
                          }​
                  Please consider this portion of the code. Later on you do use a method on Line 54 and it is very good but is irrelevant.

                  Comment


                    #24
                    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 of course open to any solution that allows me to find the MAX of a Method value within a certain number of n bars.
                    I am surprised the NinjaScript documentation does not have some solution to do something along the lines of what you are suggesting.

                    highestBarAgo = HighestBarAgoInRange(MyCustomMethod(), 10, 0); ?????????????????

                    Comment


                      #25
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello DynamicTest,

                      "no one has provided me with proof that it can be used on any value from a method."

                      It compares numbers. If you are setting number values to a series (from any source, including from another completely unrelated method if this is what you want) it will work.

                      "While it is an interesting snippet it might be possible it cannot work with a value that came from a Method."

                      I completely disagree. It can work with any numbers saved to a series.
                      Very well ChelseaB, yes I am familiar with using Series in C# and so I will look at how to apply that in Ninjascript.
                      I think you do understand the issue I am running into where the earlier suggestions about calling methods and the example you shared will not accept the Values directly from a Method. So I must store values in a list or array.

                      If we make the final solution presentable it could be useful for others in the future who will undoubtedly want to use values from Methods.
                      Thank you
                      Last edited by DynamicTest; 03-26-2024, 02:24 PM.

                      Comment


                        #26
                        Hello DynamicTest,

                        The example is showing example logic.

                        Save the values to a custom series, supply the series as the series parameter to the method call.
                        It can use values that come from another method as long as these are stored in a series.

                        MySeries[0] = MyCustomMethod();

                        Print( HighestBarAgoInRange(MySeries, 10, 0);

                        A double is a single value. There is no high or low, its just that one value.
                        A series is a value for every bar on the chart.

                        You could even change the method to use an array or list, which also holds multiple values. (The indexes would be reversed)

                        "I am surprised the NinjaScript documentation does not have some solution to do something along the lines of what you are suggesting."

                        The help guide documentation documents NinjaScript properties and methods and what they do.
                        The help guide documentation does not provide custom logic. You have to design the custom logic yourself.

                        I highly recommend a formal class on C#. Once you have learned to code in C#, this will likely make much more sense.

                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hello DynamicTest,

                          The example is showing example logic.

                          Save the values to a custom series, supply the series as the series parameter to the method call.
                          It can use values that come from another method as long as these are stored in a series.

                          MySeries[0] = MyCustomMethod();

                          Print( HighestBarAgoInRange(MySeries, 10, 0);

                          A double is a single value. There is no high or low, its just that one value.
                          A series is a value for every bar on the chart.

                          You could even change the method to use an array or list, which also holds multiple values. (The indexes would be reversed)

                          "I am surprised the NinjaScript documentation does not have some solution to do something along the lines of what you are suggesting."

                          The help guide documentation documents NinjaScript properties and methods and what they do.
                          The help guide documentation does not provide custom logic. You have to design the custom logic yourself.

                          I highly recommend a formal class on C#. Once you have learned to code in C#, this will likely make much more sense.
                          Thank you very much for the nudge in the correct direction ChelseaB, I was trying to avoid using more series than I already was but I see now there is no trouble doing so.
                          I agree I could always use more C# training. I really like Oreilly Head First C#


                          Thank you again for your patience. I modified you example to work in the way we discussed.

                          Your other examples are very insightful as well.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Haiasi, 04-25-2024, 06:53 PM
                          2 responses
                          17 views
                          0 likes
                          Last Post Massinisa  
                          Started by Creamers, Today, 05:32 AM
                          0 responses
                          5 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,408 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Working...
                          X