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

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 pibrew, Today, 06:10 PM
          0 responses
          4 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by pibrew, 04-28-2024, 06:37 AM
          2 responses
          17 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by Philippe56140, 04-27-2024, 02:35 PM
          7 responses
          56 views
          0 likes
          Last Post kevinenergy  
          Started by arunkumar3, 08-25-2023, 12:40 PM
          3 responses
          169 views
          0 likes
          Last Post Trader2024!  
          Started by DJ888, 04-26-2024, 10:57 PM
          2 responses
          19 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Working...
          X