Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars.BarsSinceNewTradingDay

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

    Bars.BarsSinceNewTradingDay

    I want to use a standard deviation with a period that gets larger as the day goes on. For example, first bar of session will be period 1, when we get to bar 20 the period will be 20, etc.

    Is it possible to use:

    int period = Bars.BarsSinceNewTradingDay;

    so StdDev(period) will get progressively larger as the day goes on?

    If so, could you give me the correct syntax for this to work?

    Thank you.

    #2
    Hello imalil,

    Thanks for your post.

    Yes, you can do that, however, the first bar will be 0 (zero) so use:

    int period = Bars.BarsSinceNewTradingDay +1;

    Note: if you are ever unsure of something you can always print out values to test for example, in this case: Print ("Time: "+Time[0]+" BSNTD: "+Bars.BarsSinceNewTradingDay);

    Comment


      #3
      Thanks for that. Before I experiment with this, does

      int period = Bars.BarsSinceNewTradingDay +1;

      need to be in OnBarUpdate to update every bar? Meaning it won't work if it's in the variable or state section. Do I have that right?

      Thank you.

      Comment


        #4
        Hello imalil,

        Thanks for your reply.

        Yes, that would need to be in the OnBarUpdate() method.

        You could also use it this way: StdDev(Bars.BarsSinceNewTradingDay + 1)

        Comment


          #5
          Thanks, things are working. One thing I'm having trouble doing:
          If:
          if (Bars.IsFirstBarOfSession)
          is true, how do I make sure
          Bars.BarsSinceNewTradingDay + 1
          is equal to 1? Else it will increase by 1 with each new bar.

          I hope this is clear.
          Thank you.

          Comment


            #6
            Hello imalil,

            Thanks for your reply.

            Bars.IsFirstBarOfSession is a bool that is true on the first bar of the session, otherwise false.
            Bars.BarsSinceNewTradingDay is an int that starts at 0 on the first bar.

            When Bars.IsFirstBarOfSession is true, Bars.BarsSinceNewTradingDay would = 0.

            The idea of +1 is to prevent trying to get a standard deviation value of 0. You wanted a way of dynamically changing the period on each bar which is why I suggested StdDev(Bars.BarsSinceNewTradingDay + 1).

            To help you clarify, I recommend that you use print statements to see when Bars.IsFirstBarOfSession is true and what the value of Bars.BarsSinceNewTradingDay is.

            Comment


              #7
              I figured this part out, thanks. I have one more simple question:

              Instead of checking for Bars.IsFirstBarOfSession, I would like to check for a bar that starts at a specific time of day, how would I do that?

              Thank you.

              Comment


                #8
                Hello imalil,

                Thanks for your post.

                To check the close time of a bar you can use ToTime(Time[0]).

                if (ToTime(Time[0]) == 93000)
                {
                // do something specifically at 9:30 AM
                }


                Note that this may or may not work on non time based bars such as renko or range. For those bars type it would be better to look for a bar close in a range of time such as if (ToTime(Time[0]) >= 93000 && ToTime(Time[0]) <= 093500)

                Reference: http://ninjatrader.com/support/helpG...us/?totime.htm

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                603 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                349 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                104 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                560 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                560 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X