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

checking back over a varying number of bars

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

    checking back over a varying number of bars

    Hello-

    I've been using the MAX function to go back a fixed period of bars to compare the max to my current bar. This is not what I need to do. Let's say 10 bars ago my criteria was met. I need to keep going back and checking this bar to compare to the current bar, no matter how many bars back I have to go. When another bar meets my criteria I will go back to that bar, the first bar's forgotten, until a new bar meets my criteria, etc. Sorry if this sounds confusing, but I'm hoping someone there knows of a function that can help me do this.

    Thank you.

    #2
    Hello imalil,

    Are you wanting a bar number for the highest high in a series?

    If so, use HighestBar().
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea. The highestbar() looks to have a fixed period just like the MAX function. I need the period to change depending on what bar I want to look at. I'll try to make it clearer.
      Let's say one bar ago a value of 10 appeared. This is my own calculated value and is now the criteria I want to compare to every new bar. So the next bar I will compare to this 10, which is one bar back. The next bar I will compare two bars back to the 10, etc. Let's say I've been comparing for 50 bars. Now finally the new bar gives me an 11 value. I now want to compare every new bar to this 11 bar. I'll start all over again until a new bar shows me a new value that meets my criteria.

      I hope this is clearer. I want to put my chosen value into memory and check back to it no matter how far back I have to go.

      Thanks in advance for any help.

      Comment


        #4
        Hello imalil,

        The period parameter, defined in the help guide, controls the number of bars the highest bar will be found within. This is similar to the Period used for the SMA.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I clearly do not know how to explain what I'm after. I know this is possible because I look at a 3rd party indicator every day which I'm sure is doing what I'm trying to do.

          Is there any way to put a bar's value into some kind of memory so I can keep comparing this value to the current bar's value?

          'll try to think of a better way to explain this, but this is all I got right now.

          Thanks.



          Comment


            #6
            Hello imalil,

            Are you wanting a barsAgo offset?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Possibly. How can I learn about this?

              Comment


                #8
                Let me try it this way: if a bar gives me a value of 10, for example, I want to keep dividing this 10 into every new bar to see if I get a value of 2 or higher. This works differently than the MAX function which will only pick the highest value for me to divide into the current bar. I guess you could say I want the lowest value bar that meets my value of 2 criteria. Not sure if this helps.

                Comment


                  #9
                  Hello imalil,

                  A barsAgo value is used as a index for the number of bars ago a bar occurred.

                  For example:

                  Print(SMA(7)[3]);

                  This would print the value of the sma stored 3 bars ago using calculations from the previous 7 bars.



                  I'm not certain I am following.

                  You are wanting to get a bar number and do division the bar number?

                  Can you clarify this?


                  HighestBar() returns the bar number of the bar that has the highest value. This allows you to get any other information from that bar.

                  For example:

                  Print(Time[CurrentBar - HighestBar(High, CurrentBar)]);

                  This would print the time of the highest bar on the chart going all the way back to the first bar on the chart.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Let's try this: a bar gives me a volume of 2000. I want to be alerted the next time a bar has a volume of 2000 or higher. Doesn't matter if it's 5 minutes or 5 hours later. Is there a way to do this?

                    Thanks.

                    Comment


                      #11
                      Hello imalil,

                      Thanks for your reply.

                      "Let's try this: a bar gives me a volume of 2000. I want to be alerted the next time a bar has a volume of 2000 or higher. Doesn't matter if it's 5 minutes or 5 hours later. Is there a way to do this?"

                      Yes, you would need to store the level to check either in an input variable or a local variable and then it is a matter of comparing that variable to the current bar of the data series Volume[0].

                      if (Volume[0] > myAlertLevel)
                      {
                      Alert(....);
                      }


                      References:



                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hi ! I have added the following to my script "value7= Max(Typical, Cong1)[1];" but it is showing the following error - The name MAX does not exist in the current context. Please advice. My objective is to calcuate the max typical price over a span a bars.

                        Comment


                          #13
                          MAX needs to be capitalized. If it already is, then I don't know.

                          Comment


                            #14
                            Hello siniaglobal,

                            Thanks for your post.

                            As member imalil has advised, the method name is MAX, not Max as shown in your code.
                            Reference: https://ninjatrader.com/support/help...aximum_max.htm
                            Paul H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by f.saeidi, Today, 12:14 PM
                            4 responses
                            11 views
                            0 likes
                            Last Post f.saeidi  
                            Started by Russ Moreland, Today, 12:54 PM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_Erick  
                            Started by philmg, Today, 12:55 PM
                            1 response
                            7 views
                            0 likes
                            Last Post NinjaTrader_ChristopherJ  
                            Started by TradeForge, 04-19-2024, 02:09 AM
                            2 responses
                            32 views
                            0 likes
                            Last Post TradeForge  
                            Started by aprilfool, 12-03-2022, 03:01 PM
                            3 responses
                            329 views
                            0 likes
                            Last Post NinjaTrader_Adrian  
                            Working...
                            X