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 bmartz, 03-12-2024, 06:12 AM
          2 responses
          19 views
          0 likes
          Last Post bmartz
          by bmartz
           
          Started by funk10101, Today, 12:02 AM
          0 responses
          3 views
          0 likes
          Last Post funk10101  
          Started by gravdigaz6, Yesterday, 11:40 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by MarianApalaghiei, Yesterday, 10:49 PM
          3 responses
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by XXtrader, Yesterday, 11:30 PM
          0 responses
          4 views
          0 likes
          Last Post XXtrader  
          Working...
          X