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 NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        68 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X