Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar before last bar of session

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

    Bar before last bar of session

    Hello everyone, how can I get a bar before the last bar of the session?

    I need the condition run on a bar thah before the last bar of the session

    how to define it?

    #2
    Hello memonolog,

    Thanks for your post.

    There is the property Bars.IsLastBarOfSession that will work on Historical data and live bars if you are using Calculate.OnbarClose. https://ninjatrader.com/support/help...rofsession.htm

    If you are using Calculate.OnEachTick or Calculate.OnpriceChange, on live data, then you would need to use the session iterator according to this note: When running Calculate.OnEachTick / OnPriceChange, this property will always return true on the most current real-time bar since it is the last bar that is updating in the trading session. If you need to find a bar which coincides with the session end time, please use the SessionIterator.ActualSessionEnd.
    Reference: https://ninjatrader.com/support/help...sessionend.htm


    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello memonolog,

      Thanks for your post.

      There is the property Bars.IsLastBarOfSession that will work on Historical data and live bars if you are using Calculate.OnbarClose. https://ninjatrader.com/support/help...rofsession.htm

      If you are using Calculate.OnEachTick or Calculate.OnpriceChange, on live data, then you would need to use the session iterator according to this note: When running Calculate.OnEachTick / OnPriceChange, this property will always return true on the most current real-time bar since it is the last bar that is updating in the trading session. If you need to find a bar which coincides with the session end time, please use the SessionIterator.ActualSessionEnd.
      Reference: https://ninjatrader.com/support/help...sessionend.htm

      the question was about how to get the bar before the last bar of the session

      So will I get the bar before the last bar of the session?

      if(Bars.IsLastBarOfSession)

      {
      Close[1]
      }

      Comment


        #4
        Hello memonolog,

        Thanks for your reply.

        What type of bars and bar size are you using?

        What Calculate setting are you using on the indicator?

        Does the indicator have any added data series?

        Can you provide context about what you are wanting to do?

        Comment


          #5
          Not the original poster, but this would be helpful for me to know as well.

          For my own purposes, I am running a strategy on 5-minute bars and calculating OnBarClose. I would like to close out all trades at one bar prior to the close of the session, and not on the exact session close as the "Exit on Session Close" setting would do.

          Currently accomplishing this using an absolute time reference ("if(ToTime(Time[0]) >= 151000)"), however this is not a dynamic solution by any means and also introduces problems when there are days with abnormal trading hours.

          Any advice would be greatly appreciated.

          Comment


            #6
            Hello LVTrade,

            I would suggest using a time condition and the session iterator to get the end of session time for that use case. You could make a time condition that works with the bar type being used, for example finding the end time and then using 10 minutes before that so you have at least 1 bar close event during that period of time.

            Comment


              #7
              Jesse,

              Your suggestion worked very well, thank you!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              558 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X