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 love2code2trade, Yesterday, 01:45 PM
          4 responses
          28 views
          0 likes
          Last Post love2code2trade  
          Started by funk10101, Today, 09:43 PM
          0 responses
          7 views
          0 likes
          Last Post funk10101  
          Started by pkefal, 04-11-2024, 07:39 AM
          11 responses
          37 views
          0 likes
          Last Post jeronymite  
          Started by bill2023, Yesterday, 08:51 AM
          8 responses
          45 views
          0 likes
          Last Post bill2023  
          Started by yertle, Today, 08:38 AM
          6 responses
          26 views
          0 likes
          Last Post ryjoga
          by ryjoga
           
          Working...
          X