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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        60 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        145 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        284 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X