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 way to isolate close of bar, first bar of session?

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

    Best way to isolate close of bar, first bar of session?

    Hi all,
    Can someone advise what is the best way to code for determining a new session and specifically, at the close of that first bar for the new session?

    I had assumed I should use:

    If (Bars.SessionBreak)
    { reset daily variables here}

    However, it appears that SessionBreak is calling my code like a tick bar even though I have this indicator set to only update on close.

    Specifically, getting High[0] during that event, which should be the high of the first days bar, is actually being set to the close of the first bar, implying it is calling SessionBreak like a tick situation where the last tick would be both the close and the "high".

    I also tried some other time stuff with no luck...

    Anyway, could someone please post the basic code for trapping the first bar of the day, at the close of that bar?

    Thanks

    #2
    Well, rebuilding from scratch seems to have cleared it up...Bars.SessionBreak now works as I would have expected...no idea why it was behaving like a tick chart earlier.

    Anyway, please let me know if there is a better way to do it, otherwise, it does seem that Bars.SessionBreak is working...though I don't know if this depends on the session time for the chart, or if its doing a date compare (i.e. at midnight)?

    thanks

    Comment


      #3
      Hello,

      Have you tried FirstBarOfSession?:
      DenNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Ben View Post
        Hello,

        Have you tried FirstBarOfSession?:
        http://www.ninjatrader-support.com/H...OfSession.html
        Yes, I did and it didn't work - I didn't investigate, but it definitely stopped my indicator from plotting anything.

        SessionBreak was the only one that worked for me (in terms of what I expected).

        I am not clear if FirstBarofSession failed because I had made a custom chart to only show the Day session, and perhaps it was triggered with the first bar of the night session (AM), which would have zero for all points (i.e. high of first bar)?

        Any tips on when to use FirstBarOfSession vs. SessionBreak would be appreciated

        thanks

        Comment


          #5
          SIFTrader, not sure I follow follow - in NinjaTrader 6.5 session definitions are entered for each chart in the chart properties (session begin, end times), so please doublecheck those when using those related methods.

          In NinjaTrader 7 as Session manager was added, so you could refer to predefined or custom templates - http://www.ninjatrader.com/webnew/NT7/NinjaTrader7.html
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thanks Bertrand, I am looking forward to Ninja7.

            My comments about having customized the session time on that chart were because I was not able to differentiate why SessionBreak did trap the first bar on the chart, but FirstBarOfSession did not.

            I was speculating that perhaps FirstBarofSession was hardwired to map to the Exchanges session time rather than chart time, meaning it would return invalid in my scenario since the true first bar of session in TF is the first bar of the evening open.

            Anyway, sounds like that is not why...

            If you could clarify when we should use SessionBreak vs. FirstBarofSession that would help me continue my porting from TS since I don't have access to NT7.

            It seems these bars are two different words for the same thing (first bar of your charts session) but I am sure there is some underlying distinction and I thus want to ensure I am using the right one at the right time to avoid any problems.

            Thanks!

            Comment


              #7
              Please use FirstBarOfSession along with FirstTickOfBar if you want the very very first OnBarUpdate() event. I believe SessionBreak is being deprecated in NT7.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Josh View Post
                Please use FirstBarOfSession along with FirstTickOfBar if you want the very very first OnBarUpdate() event. I believe SessionBreak is being deprecated in NT7.
                Great, thank you.

                Of interest - I was only able to make my indicator plot properly/work using FirstBarofSession if I prefaced it with a "if currentbar < 20 return" statement.

                That was not needed with SessionBreak for it to work.

                Anyway, just wanted to note it in case other hit it changing to FirstBarofSession.

                Otherwise, it is working as expected and thanks for the guidance.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by andrewtrades, Today, 04:57 PM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by chbruno, Today, 04:10 PM
                0 responses
                3 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                436 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                7 views
                0 likes
                Last Post FAQtrader  
                Started by rocketman7, Today, 09:41 AM
                5 responses
                19 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X