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

Highest Close of the Last n bars

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

    Highest Close of the Last n bars

    Is there a command like Highest (close, nbars)?

    How would I go about finding the "Highest Close" of the last "n" bars in C#?

    Thanks

    #2
    Originally posted by randl View Post
    Is there a command like Highest (close, nbars)?

    How would I go about finding the "Highest Close" of the last "n" bars in C#?

    Thanks
    Look at the MAX() class.

    ref: http://www.ninjatrader.com/support/h...aximum_max.htm

    Comment


      #3
      Hello randl,

      Thank you for your post.

      You can also use High[HighestBar(High, nbars)]. For information on HighestBar() please visit the following link: http://www.ninjatrader.com/support/h...highestbar.htm

      Please let me know if I may be of further assistance.

      Comment


        #4
        Thanks Patrick, can you tell me if this statement will plot correctly for the original question I asked and the data you gave me?

        Plot0.Set((HighestBar(Close, Bars.BarsSinceSession - 22).ToString()- Low)/ ((HighestBar(Close, Bars.BarsSinceSession - 22).ToString()))* 100

        Comment


          #5
          Hello randl,

          Thank you for your response.

          The HighestBar() is an int, so if the intent behind your Plot.Set() is for a y value representing price you will need to call the HighestBar() as the barsAgo index for the High:
          Code:
          Plot.Set(((High[HighestBar(Close, Bars.BarsSinceSession - 22)] - Low[0])/(High[HighestBar(Close, Bars.BarsSinceSession - 22)])) * 100);

          Comment


            #6
            Thanks Patrick, I ran the string you suggested and got the following error message. I am missing something else.

            Indicator\WVF.cs 'NinjaTrader.Indicator.IndicatorBase.Plot(System.D rawing.Graphics, System.Drawing.Rectangle, double, double)' is a 'method', which is not valid in the given context CS0119 - click for info Row 46 Column 13

            Comment


              #7
              I also tried this and got these error messages:

              NinjaScript --> File --> Error --> Code --> Line --> Column
              Indicator\WVF.cs Cannot assign to 'WVF' because it is a 'method group' CS1656 - click for info 46 4
              Indicator\WVF.cs 'NinjaTrader.Indicator.IndicatorBase.Plot(System.D rawing.Graphics, System.Drawing.Rectangle, double, double)' is a 'method', which is not valid in the given context CS0119 - click for info 47 13

              Any ideas what I defined wrong?
              Thanks

              Comment


                #8
                Hello randl,

                Thank you for your response.

                If there is one Plot try using Value.Set() rather than Plot.Set(). If there are multiple plots you will need to call the correct name for each plot or use Values.

                For information on Value and Values please visit the following links:
                For a tutorial on plots in NinjaScript please visit the following link: http://www.ninjatrader.com/support/h...ot_colors_.htm

                Please let me know if I may be of further assistance.

                Comment


                  #9
                  thanks Patrick, I saw the example give but I did not understand it well enough to use it. what is it checking?
                  Thanks

                  Comment


                    #10
                    Hello randl,

                    Thank you for your response.

                    The Tutorial shows how to change plots based on the ROC above or below the zero line.

                    Comment


                      #11
                      Sorry Patrick I don't know what ROC is.

                      There is no above or below the zero line in my case. All I want is to do is to continually check for the highest close of the last 22 bars and subtract the current low from it, then divide it by the highest close of the last 22 bars and multiply it by 100.

                      Comment


                        #12
                        Hello randl,

                        Thank you for your response.

                        The tutorial also serves as an example of setting up Plots. How many plots do you have in your code?

                        Comment


                          #13
                          One - just the plot generated by the equation.
                          Thanks for getting back to me.

                          Comment


                            #14
                            Originally posted by randl View Post
                            Sorry Patrick I don't know what ROC is.

                            There is no above or below the zero line in my case. All I want is to do is to continually check for the highest close of the last 22 bars and subtract the current low from it, then divide it by the highest close of the last 22 bars and multiply it by 100.
                            If you had followed my advice to look at the MAX() class, you would have seen that you can do that in one line, thus:
                            Code:
                            Plot0.Set(100 * (MAX(High, 22)[0] - Low[0]) / MAX(Close, 22)[0]);

                            If your "last" does not include the CurrentBar, then you would index the MAX() terms to [1] instead of [0].
                            Last edited by koganam; 11-04-2013, 01:51 PM.

                            Comment


                              #15
                              Thanks Koganam, that worked.

                              Sorry, I must have missed your post over the weekend.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              2 responses
                              20 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by adeelshahzad, Today, 03:54 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by stafe, 04-15-2024, 08:34 PM
                              7 responses
                              32 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by merzo, 06-25-2023, 02:19 AM
                              10 responses
                              823 views
                              1 like
                              Last Post NinjaTrader_ChristopherJ  
                              Started by frankthearm, Today, 09:08 AM
                              5 responses
                              22 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X