Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Find out if last trade was made during current session

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

    Find out if last trade was made during current session

    Hi I'm trying to find out if the last trade was made during the current session, I tried getting the start time of the session by:

    DateTime dtStartOfSession = Bars.GetTime(Bars.Count - Bars.BarsSinceSession);

    But it looks like when backtesting this returns the wrong date, because Bars has the entire data collection, not just what's current.

    Is there a simple call somewhere that gets this information?

    Jeremy
    Jeremytang
    NinjaTrader Ecosystem Vendor - Shark Indicators

    #2
    Jeremytang, you can get the start of the session with:
    Code:
    DateTime startOfSession = Bars.Session.NextBeginTime;
    AustinNinjaTrader Customer Service

    Comment


      #3
      Oh... I figured that would get the upcoming next session start time, not the current one.

      I'm looking for the start of the current session, for example, if a trade was made 1/1/2010 at 12:00, I'd like to know if it was made before 1/1/2010 7:30am...
      Jeremytang
      NinjaTrader Ecosystem Vendor - Shark Indicators

      Comment


        #4
        In order to get the previous start time, you could check the date of the NextBeginTime and subtract a day with:
        Code:
        startOfSession = Bars.Session.NextBeginTime.AddDays(-1);
        AustinNinjaTrader Customer Service

        Comment


          #5
          That looks like it would except for the cases where you had different start times for different days. For example if you had a session template like:

          Sun->StartTime: 10:00am
          Mon->StartTime: 7:30am

          If it was Sun, and the time you're looking for is 10:00am, Bars.Session.NextBeginTime would return Monday 7:30am, and subtracting 1 day from that would yield Sunday 7:30am, which is not the correct session time.

          Can SessionsOfDay or GetSessionDate be used? I can't seem to find documentation on those two.
          Jeremytang
          NinjaTrader Ecosystem Vendor - Shark Indicators

          Comment


            #6
            Jeremy, I just ran the the first codes I gave you in an indicator on an ES chart with regular trading hours session applied. The property NextBeginTime returned a value of 6/30/10 7:30AM, which is the proper opening time for my timezone for regular trading hours.

            I am not sure why it is called NextBeginTime, because it returns the current session's begin time.
            AustinNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            86 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            48 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            29 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            32 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            67 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X