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