Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get value for first bar of the trading session

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

    How to get value for first bar of the trading session

    I'm using 5 mins bar. I want to know what is the delta between the current bar close and the first bar close. I could use previous day close but it's not accurate due to gap at the open.

    In addition, I'm using this:
    double maxClose = MAX(Close, 10)[0];

    How can I use only the bars from today, not yesterday if it's early in the session like the first 15 mins of the session ? Thanks.

    #2
    Hello,

    Thanks for your note and welcome to the NinjaTrader forums!

    If you run this on the same type of chart you can count the number of bars back that would be everyday and use Open[x] in your code would be the simple way. But then you have to change this variable if you change the chart your running this on, not ideal in this case.



    Or you use FirstBarOfSession, Run a check for FirstBarOfSession, if it is the first bar of session then set a temporary variable to the Open[0] price. Then you can reference this price later in your code.

    You can also use the FirstBarOfSession to restart a counter variable to 0. Then for your maxClose variable check to see if this counter variable is equal to 10, If it is then run the MAX code. Then in each OnBarUpdate() you would iterate this counter + 1 each time or counter++.

    Theres always multiple ways to do something in coding this is simply what I may do in this situation.

    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
    576 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    334 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    553 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    551 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X