Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I determine the first 10 minutes of trading session w/o hardcoding the time?

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

    How can I determine the first 10 minutes of trading session w/o hardcoding the time?

    Hi,
    I'm looking to run some code during the first 10 minutes of the session and run different code after the first 10 minutes.

    How can I determine this time frame without hardcoding the time (i.e. without writing specifically 9:30-9:40) and regardless of bar period size?

    I was thinking of using the FirstBarOfSession, but Time[0] gives me the current time. How can I tell when FirstBarOfSession started?

    Thanks.

    #2
    Hello Benharper,

    Thank you for your note.

    That is exactly what you wanna use.

    DateTime startingTime;

    if(Bars.FirstBarOfSession)
    startingTime = Time[0];

    This will be the time of the bar at the first bar of the session.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Just to clarify. Time[0] gives the time the bar ends. I'm looking for the start of the session. I can get it by using something like that:

      if (Bars.FirstBarOfSession)
      _start_session = Time[0].AddMinutes( - Bars.Period.Value);

      But that will work only if the strategy is running on time period of minutes. Is there a more generic way of doing that (without nesting all the Bars.Period options)?

      Thanks.

      Comment


        #4
        Originally posted by benharper View Post
        Just to clarify. Time[0] gives the time the bar ends. I'm looking for the start of the session. I can get it by using something like that:

        if (Bars.FirstBarOfSession)
        _start_session = Time[0].AddMinutes( - Bars.Period.Value);

        But that will work only if the strategy is running on time period of minutes. Is there a more generic way of doing that (without nesting all the Bars.Period options)?

        Thanks.
        The start of bar 0 is the same as the end of bar 1. Use Time[1].

        Comment


          #5
          Thanks, that's a good idea.

          Comment

          Latest Posts

          Collapse

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