Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting last bar / First bar of session

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

    Getting last bar / First bar of session

    I have a strategy that runs on 60 min bars, however at the end of every session I wish to exit my position at market, save all my current orders and then after the reopen, reenter my position and reenter all my orders. The issue is that with 60 min chart, this can be a lot of missed price action, so I wanted to add a 5 min data series. However it seems I am having issues as currently I have a check

    if(this.BarsArray[1].LastBarOfSession)
    {

    and this is where I exit my position, however for 6E product, this is exiting at 6:00pm? Also, is this the best way to get that I am on the second bar of the new session (I don't wanna submit my orders on first bar as market will just be opening and want it to establish itself for 5 min):

    if((this.BarsArray[1].BarsSinceSession == 1)

    Thanks,

    Mark

    #2
    Hi Mark,

    LastBarOfSession property is not currently supported.

    Best is to work with time objects. Time[0] is the time stamp of bars, so you could check this for any added series in your strategy. For the time stamp of added series, there is Times[0][0].

    This reference sample can help you create a time filter:


    There is also property ExitOnClose, which closes your position at the end of the session as defined by your session template. This property does not prevent new submissions though, so you would still need to add some time filters if you don't want to accept further entries past a specified time.

    Yes, Bars.BarsSinceSession == 1 is the second bar of the session.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan,

      Thanks, so what value with Times[1][0] return? Can I use ToTime() on this value? Is there not a similar way to retrieve the last bar of a session in a reliable way as there is to get the 2nd bar of the session?

      Thanks,

      Mark

      Comment


        #4
        Times[1][0] will be the current time stamp of the secondary series. It's a standard C# DateTime object. You can use ToTime on this to take out the time and convert into integer.

        There is unfortunately not a supported property for LastBarOfSession available.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X