Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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:	46
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 fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      7 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X