Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Get close() of last bar in previous session

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

    Get close() of last bar in previous session

    OVERVIEW
    If IsFirstBarOfSession == true && IsFirstTickOfBar == true and calc = OnPriceChange, how do I get close() of last bar of previous session?

    SPECIFICS
    It's 6pm eastern and new ETH session has just opened. I need to know the close() of the last bar of the previous session (5pm bar close). What code might I use to get that?

    Please and thank you,
    Clint

    #2
    Hello Clint,

    Thank you for your post.

    You can use IsFirstBarOfSession to get this information. If the current bar (0 bars ago) is the first bar of the session, then the previous bar (1 bar ago) would be the last bar of the previous session.

    Code:
    if (Bars.IsFirstBarOfSession)
    ​{
    double lastClose = Close[1];
    }
    https://ninjatrader.com/support/help...rofsession.htm​​

    Comment


      #3
      This doesn't seem to be working for me. I get "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart." Am I doing something wrong here?

      Comment


        #4
        what does your code look like? You need to make sure you have enough bars for what you are doing. For example, if you want to look at the previous bar, you need to wait at least 1 candle, because the first one will error out...well, like the message you're receiving. You can also put print statements, to see if the values you are assigning get assigned properly. You can also use print statements with unique statements at points in code to narrow down which line is crashing on you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        87 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        132 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        65 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        118 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        67 views
        0 likes
        Last Post PaulMohn  
        Working...
        X