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 andrewtrades, Today, 04:57 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by chbruno, Today, 04:10 PM
            0 responses
            6 views
            0 likes
            Last Post chbruno
            by chbruno
             
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            436 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            9 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            19 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Working...
            X