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