Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading times for instrument

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

    Trading times for instrument

    How can I get the daily trading time of an instrument from within a c# script?

    #2
    Hello rafe0304,

    You are looking for the session template end and start times, is this correct?

    This can be found with Bars.Session.GetNextBeginEnd.

    Below is a link to the help guide which includes an example of how this works.
    http://ninjatrader.com/support/helpG...xtbeginend.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your quick response.

      To be more specific: I am using range bars, so the OnBarUpdate doesnt occur at regular intervals. Now I want to prevent entering the market if I got less than say 1 hour until closing time of the instruments exchange. So I need a way to determine within OnBarUpdate, how much time is left until closing time.

      How can I do that?

      Comment


        #4
        Hello rafe0304,

        To subtract a date from another date use DateTime.Subtract.

        https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

        For example:
        Code:
        Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);
        TimeSpan diff = sessionEnd.Subtract(Time[0]);
        Print(diff.ToString());
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          no idea why, but "Bars.FirstBarOfSession" is never true in my setting, not even the first time OnBarUpdate is called.

          Comment


            #6
            Hello rafe0304,

            This would only be true on the first bar after a session closes.

            This an example and would only be used if you are wanting to print than information on the first bar of a new session.

            Attached is an example strategy that prints the time any time this condition is true. Are you finding that this example does not print?
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            115 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            61 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            40 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            43 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            82 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X