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

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.
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mmenigma, Today, 02:22 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by frankthearm, Today, 09:08 AM
    9 responses
    35 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by NRITV, Today, 01:15 PM
    2 responses
    9 views
    0 likes
    Last Post NRITV
    by NRITV
     
    Started by maybeimnotrader, Yesterday, 05:46 PM
    5 responses
    28 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by quantismo, Yesterday, 05:13 PM
    2 responses
    21 views
    0 likes
    Last Post quantismo  
    Working...
    X