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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X