Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Best manner for detecting the precise beginning of a market session

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

    Best manner for detecting the precise beginning of a market session

    Hi all,

    While I'm not new to indicator development, I certainly am a bit green on NinjaScript and C#.

    I'm looking for the best way to detect the precise beginning of a market session, such as an event handler. Is there such a handler that can be hooked to within the context of an indicator?

    I am aware that there are methods and properties that would allow for the detection of the first bar of a new session, i.e. Bars.FirstBarOfSession. However, this is related to the timeframe, and obviously will remain true for whatever price movements occur within that first bar, causing issues for indicators that need to refresh at exact market open (i.e. VWAP).

    I've also considered hardcoding the session times, but this poses an obvious issue when moving between asset classes or exchanges and for 'odd cases' like holidays or other exceptions.

    Is there a clean way, using the API, to have a method invoke only once at the very beginning of a new market session to do bookkeeping and housecleaning for session-based indicators?

    TIA,
    nukespace
    Last edited by nukespace; 11-23-2021, 06:24 PM.

    #2
    Hello nukespace,

    Thanks for your post.

    You could use Bars.IsFirstBarOfSession to reset variables when there is a new session.

    Something you could consider is checking Bars.IsFirstBarOfSession along with using Calculate.OnPriceChange and IsFirstTickOfBar, which would be the first tick of the new session.

    See the help guide documentation below for more information.

    Bars.IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.htm
    Calculate: https://ninjatrader.com/support/help.../calculate.htm
    IsFirstTickOfBar: https://ninjatrader.com/support/help...firsttickofbar

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    579 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
    554 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