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

High and Low of specific times

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

    High and Low of specific times

    Hi, how would I find the high and low for a specific timeframe?

    In particular, I'm looking for the high and low prices between 9:30 and 9:45.

    My strategy uses three timeframes:
    0 = daily for this stock
    1 = minute for this stock
    2 = minute for symbol DIA

    I have a habit of starting and stopping the strategies multiple times during the day, so I can't just capture the high- and low-water marks during the desired timeframe.

    #2
    Hello,

    Thanks for the forum post.

    You would need to use a time condition on the 1 minute series to get this time if its past this time already for the current day using this method that is sampled below.




    Let me know if any questions.

    Comment


      #3
      Hi Brett,

      Thanks, but that's not exactly what I'm looking for. What I'm looking for is the highest price reached between 9:30 and 9:45, and the lowest price between 9:30 and 9:45 today. And, as an added complication, it's possible that I enabled the strategy at 11:00, so the strategy wasn't active during the timeframe I'm requesting.

      A possible solution might be to add yet another timeframe for 15-minute bars. If that was part of the solution, how would I reference the high and low of the first bar today?

      Comment


        #4
        Here is the best setup I can think of currently.

        Reset a flag every new day to look for this price during this time.

        Use http://www.ninjatrader.com/support/h...rofsession.htm to do this.

        Then if the flag is true then use the sample I showed you to so some action based on time.

        Use the end time if (ToTime(Time[0]) > 95000 && doOnce = true)) then do do the following command



        Max(High, 15)[0];
        Min(Low, 15)[0];

        Set the doOnce flag back to false so it doesn't run again.

        This will give you the highest value and lowest value for the past 15 bars which on a 1 minute chart is 15 minutes back.

        Let me know if any questions.

        Comment


          #5
          Hi Brett,

          I agree that will work if I have the strategy running all day long, but I regularly disable and re-enable my strategies during the day.

          Since I have a one-minute timeframe running, is it possible to access the first 15 trading minutes of today so I can derive the highs and lows of those bars?

          Comment


            #6
            Hello,

            This method below works in historical and live no matter when you enabled.What you will want to do is save the value to a variable and then access that at anytime for the remainder of the day. It will recalculate that value on restart of the strategy as well.

            -Brett

            Comment


              #7
              Hello,

              Could you maybe provide how exactly to write the code for this action? Not really sure how to reset a flag each day, and im not sure about null reference explanation on help site, what does it mean?
              Also, my local time is different than Eastern time, will that effect the first bar determination or not?

              Thanks

              Comment


                #8
                Hi Bagzi,

                Here's the code I used to calculate the opening range highs and lows. "Opening range" is the first 15 minutes of the trading session, 9:30-9:45 New York time. I live in Central time zone, and you'll need to make one adjustment for your timezone:

                barsThisSession = Math.Min(Math.Max(1,Bars.BarsSinceSession),390);
                // This is overkill, but I do a lot of calcs with bars since session and I don't want it
                // messed up with after-hours bars and I don't want it to ever be zero.
                if (openRangeHigh == 0 || ToTime(currentTime) < ToTime(8, 50, 0))
                // I don't want to keep recalculating this in the middle of the day, but if I had
                // just restarted NT at noon I do want to calculate it. I do want to keep
                // recalculating it for the first few minutes of the session.
                // This is the one line you will need to change for your timezone. I'm in Texas
                // so 8:50 is 20 minutes after the open (9:50 New York time).
                {
                openRangeHigh = MAX(Highs[0],15)[Math.Max(0,barsThisSession-15)];
                openRangeLow = MIN(Lows[0],15)[Math.Max(0,barsThisSession-15)];
                }

                That's it. barsThisSession is an Int, openRangeHigh and openRangeLow are doubles.

                Hope that helps. Feel free to respond with follow-up questions.

                Comment


                  #9
                  Also,

                  currentTime = DateTime.Now;

                  Comment


                    #10
                    Thanks a lot, im gona try and plug this in and if i have more questions ill post here.

                    Comment


                      #11
                      Ok, here is what i put as a code, and i tried to plot these things on chart, but it does not look right to me. It is dynamic and does not really reflect current day. Market opens at 15:30 here my time, and i wanted Hi/Lo for first 30 mins, so i changed some numbers. Would post a pic of the chart but not sure how to attach it here.

                      protected override void OnBarUpdate()
                      {
                      int barsThisSession = Math.Min(Math.Max(1,Bars.BarsSinceSession),390);
                      double openRangeHigh = MAX(Highs[0],30)[Math.Max(0,barsThisSession-30)];
                      double openRangeLow = MIN(Lows[0],30)[Math.Max(0,barsThisSession-30)];
                      DateTime currentTime = DateTime.Now;

                      if (openRangeHigh == 0 || ToTime(currentTime) < ToTime(16, 0, 0))

                      Plot0.Set(openRangeHigh);
                      Plot1.Set(openRangeLow);
                      }

                      Comment


                        #12
                        Originally posted by bagzi View Post
                        Ok, here is what i put as a code, and i tried to plot these things on chart, but it does not look right to me. It is dynamic and does not really reflect current day. Market opens at 15:30 here my time, and i wanted Hi/Lo for first 30 mins, so i changed some numbers. Would post a pic of the chart but not sure how to attach it here.

                        protected override void OnBarUpdate()
                        {
                        int barsThisSession = Math.Min(Math.Max(1,Bars.BarsSinceSession),390);
                        double openRangeHigh = MAX(Highs[0],30)[Math.Max(0,barsThisSession-30)];
                        double openRangeLow = MIN(Lows[0],30)[Math.Max(0,barsThisSession-30)];
                        DateTime currentTime = DateTime.Now;

                        if (openRangeHigh == 0 || ToTime(Time[0]) < ToTime(16, 0, 0))

                        Plot0.Set(openRangeHigh);
                        Plot1.Set(openRangeLow);
                        }
                        Correct your code, as shown in red.

                        Comment


                          #13
                          Thanks koganam,

                          i did that, and i try to plot this on the chart, but the image still does not look right. I'll try to enclose the pic. It seems that the value is sometimes taken from prior day, sometime for the MIN and sometime for the MAX, while other side looks correct but im not seeing they are simultaneously correct for both MIN and MAX. Im not sure why... Any idea?

                          Comment


                            #14
                            Your Time filter is setting only one Plot. If you want the Time filter to set both plots (you do), you must enclose those Plot.Set() statements into a block so that the filter applies to them both.

                            Comment


                              #15
                              Any suggestion on how to do that? I currently have:

                              Plot0.Set(openRangeHigh);
                              Plot1.Set(openRangeLow);

                              But i guess something here is not right.

                              Also, the lines are not correct for some days, it takes the hi from previous day data, or sometimes low. What could be causing this?

                              Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Vietanhnguyen2hotmailcom, Yesterday, 10:29 AM
                              4 responses
                              23 views
                              0 likes
                              Last Post Vietanhnguyen2hotmailcom  
                              Started by PhillT, 04-19-2024, 02:16 PM
                              4 responses
                              35 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Started by ageeholdings, 05-01-2024, 05:22 AM
                              5 responses
                              37 views
                              0 likes
                              Last Post ageeholdings  
                              Started by reynoldsn, Today, 02:34 PM
                              0 responses
                              14 views
                              0 likes
                              Last Post reynoldsn  
                              Started by nightstalker, Today, 02:05 PM
                              0 responses
                              23 views
                              0 likes
                              Last Post nightstalker  
                              Working...
                              X