Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Detecting Last Bar of Day

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

    Detecting Last Bar of Day

    I'm using "CME FX Futures RTH" on a chart of the 6E contract. In back testing my strategy, the back tester appears to close any open trades at the end of the day. Is there any whay to detect the last bar of RTH programmatically on historical data so that I can access the OHLC?
    Thanks,
    AutoTraderDev

    #2
    Hello,

    Thanks for the forum post.

    Yes:

    Bars.LastBarOfSession

    This will be true on the last bar of the session.

    Also, the position closes at the end of the day since when you ran the backtest you have in the backtest parameters Exit On Close = True.

    Let me know if I can be of further assistance.

    BrettNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Brett View Post
      Hello,

      Thanks for the forum post.

      Yes:

      Bars.LastBarOfSession

      This will be true on the last bar of the session.

      Also, the position closes at the end of the day since when you ran the backtest you have in the backtest parameters Exit On Close = True.

      Let me know if I can be of further assistance.

      A follow up of this question. How do you detect if you are 5 (x) bars from the last bar of a session?

      Comment


        #4
        Hello,

        This would be a little more complex.

        There is no NinjaScript function for this but what you can do is take the bar count of how many bars are in a day and then subtract 5 from it and then add this when you start a new session to find out what bar number this would be. This would require using the following:



        Then track CurrentBar on that bar to do your calcs.

        Let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 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