Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsFirstBarOfSessionByIndex() returns true for different k bars

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

    IsFirstBarOfSessionByIndex() returns true for different k bars

    Hello,

    Good morning at your side.

    I want to count the # of times the market breaks the high or low hence use IsFirstBarOfSessionByIndex() in below piece of codes, which is called in OnBarUpdate(); but it turns out the function returns true at different candles, as in the attached picture. Shed some lights? Grateful.

    Regards,
    Steven Meng


    protected int TodaysFirstBar() {
    int barPointer;

    for (barPointer= CurrentBar; barPointer > 0; barPointer--) {
    if (Bars.IsFirstBarOfSessionByIndex(barPointer))
    break;
    }
    return barPointer;

    }


    Click image for larger version

Name:	image.png
Views:	98
Size:	231.4 KB
ID:	1277379



    #2
    Hello Steven,

    If you want the bar index of the first bar of the session use (CurrentBar - Bars.BarsSinceNewTradingDay).


    If you want to know if the current bar is the first bar of the current session use Bars.IsFirstBarOfSession.


    The Bars.IsFirstBarOfSessionByIndex() will provide true, if the absolute bar index supplied is the first bar of a session. (This could be the first bar of the current session, previous session, session prior, etc).

    In your loop, the value will change to the absolute bar index of the new session, one a new session starts.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Noted. Thank you, Chelsea.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      90 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      137 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      120 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      72 views
      0 likes
      Last Post PaulMohn  
      Working...
      X