Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get price range over last 30 minutes

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

    How to get price range over last 30 minutes

    ... one caveat -- without using Multi-timeframe! :-) This is in a strategy, and it calculates per tick, and you cannot run a multi-series strategy in Strategy Analyzer tick by tick.

    So, with that out of the way, do you have any suggestions on how to calculate the price Range over the past 30 minutes on a chart without having a 1 minute bar series to do it? I thought about storing the price and time of every tick coming in and using a list or array to keep the prices in, but that seems like a pretty rough solution. There must be a more elegant data series or something in NT8 I can use instead.

    Thanks!
    Bryan
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Hello cassb,

    Thank you for your post.

    Use MAX and MIN, then compare the values. For example:
    Code:
    			double hi = MAX(High, 30)[0];
    			double lo = MIN(Low, 30)[0];
    			
    			Print("Price Range over last 30 bars is " + (hi-lo));
    For information on MAX and MIN please visit the following links:
    MAX: http://ninjatrader.com/support/helpG...aximum_max.htm
    MIN: http://ninjatrader.com/support/helpG...inimum_min.htm

    Comment


      #3
      NT8 Links:

      Comment


        #4
        What if the last 30 bars is 30 hours or 7.5 hours? I want the price range over the last 30 MINUTES, regardless of how many bars that is.

        Thanks!
        Bryan
        cassb
        NinjaTrader Ecosystem Vendor - Logical Forex

        Comment


          #5
          Hello Bryan,

          Thank you for your response.

          I missed the part on minutes rather than bars. In the case of 30 minutes no matter the bar type, go with Bars.GetBar(). For example:
          Code:
          			DateTime test = Time[0].AddMinutes(-30);
          			int barsAgo = Bars.GetBar(test) != null ? CurrentBar - Bars.GetBar(test): 0;
          			if (barsAgo == 0) return;
          			double hi = MAX(High, barsAgo)[0];
          			double lo = MIN(Low, barsAgo)[0];
          			
          			Print(hi-lo);
          For information on GetBar() please visit the following link: http://ninjatrader.com/support/helpG...-us/getbar.htm

          Comment


            #6
            Ah, OK that helps... I didn't know about GetBar(). Thanks!

            Bryan
            cassb
            NinjaTrader Ecosystem Vendor - Logical Forex

            Comment


              #7
              Sorry Patrick, but that method still doesn't work. If you create a 60 min bar chart and try the code, you'll see that it always sets barsAgo = 0.

              Here's my debug -- The bars all fall on the hour, so for this case at 10am, the test variable = 9:30.
              *** Time[0] = 6/30/2016 10:00:00 AM, test = 6/30/2016 9:30:00 AM

              So apparently, this code returns 0 every time because Bars.GetBar("6/30/2016 9:30:00 AM") is null:

              int barsAgo = Bars.GetBar(test) != null ? CurrentBar - Bars.GetBar(test): 0;
              cassb
              NinjaTrader Ecosystem Vendor - Logical Forex

              Comment


                #8
                So without the ability to add a minute-bar series to my strategy, am I stuck having to build my own bar series tick by tick then?

                Or, could I call an external indicator that exposes the price range on a minute by minute basis? Is there such a thing and would it work with NT8 backtest?

                Bryan
                cassb
                NinjaTrader Ecosystem Vendor - Logical Forex

                Comment


                  #9
                  Originally posted by cassb View Post
                  So without the ability to add a minute-bar series to my strategy, am I stuck having to build my own bar series tick by tick then?

                  Or, could I call an external indicator that exposes the price range on a minute by minute basis? Is there such a thing and would it work with NT8 backtest?

                  Bryan
                  If you do not want to use a multi-timeframe method, then you may want to use a Timer and a List to hold the data read by the timer.

                  Comment


                    #10
                    Thanks, buddy. C# is not my native language (mainframes mostly), so I'll see what a Timer does and maybe that will work.

                    Sometimes I get frustrated having to make up these workarounds for what should be something simple.
                    cassb
                    NinjaTrader Ecosystem Vendor - Logical Forex

                    Comment


                      #11
                      Originally posted by cassb View Post
                      Thanks, buddy. C# is not my native language (mainframes mostly), so I'll see what a Timer does and maybe that will work.

                      Sometimes I get frustrated having to make up these workarounds for what should be something simple.
                      Sorry for misleading you, but I just reread this and realize that you are talking about the Strategy Analyzer, not real time. A timer will be useless in the Strategy Analyzer.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by ETFVoyageur, Today, 02:04 PM
                      2 responses
                      15 views
                      0 likes
                      Last Post ETFVoyageur  
                      Started by mjbatts91, Today, 04:48 PM
                      0 responses
                      2 views
                      0 likes
                      Last Post mjbatts91  
                      Started by 1001111, Today, 09:45 AM
                      2 responses
                      21 views
                      0 likes
                      Last Post 1001111
                      by 1001111
                       
                      Started by cre8able, Today, 04:31 PM
                      0 responses
                      4 views
                      0 likes
                      Last Post cre8able  
                      Started by leojimenezp, Today, 04:04 PM
                      0 responses
                      7 views
                      0 likes
                      Last Post leojimenezp  
                      Working...
                      X