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

BarsInSession vs CurrentBar

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

    BarsInSession vs CurrentBar

    OnBarUpdate() I get

    BarsInSession == 0
    CurrentBar == 0
    Time[0] == .. // verified as 15:31 (SessionStart is set to 15:30)
    but
    Bars.DayBreak == false

    The thing I'm stubmling across is that DayBreak and BarsInSession seem not to be aligned???

    tx
    tb

    #2
    (Removed some posts, since I got confused)

    Bars.DayBreak is not NinjaScript nor documented. It's your own risk if you see value in using non-documented features. However, we don't provide support for that.

    Comment


      #3
      Well - sorry, I inherited that code ...

      Besides, Intellisync does show it (on VS I admit)...


      So BarsSinceSession seems to be the proper (documented) identification for a session start and that one is in sync with

      bool SessionStart == Bars.FirstBarOfSession or (Bars.BarsSinceSession==0)


      ok? just to make sure..

      tb

      Comment


        #4
        Yes. I would use FirstBarOfSession.
        RayNinjaTrader Customer Service

        Comment


          #5
          Thanks Ray and Dierk!
          tb

          Comment


            #6
            I tried a bit further and still it seems it is possibly that FirstBarOfSession is false while BarsInSession==0, a contradiction ?
            My conclusion would be that BarsInSession==0 is the only reliable indicaton of where we stand OnBarUpdate()-wise.
            All that seems at the left edge of a chart if the database has an incomplete session (starting mid day e.g.).
            tb

            Comment


              #7
              Why do you see it as a contradiction? FirstBarOfSession should be true when BarsSinceSession = 1. BarsSinceSession = 0 means there is nothing there so there is no first bar yet.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Josh, thanks - not sure you're right here, I keep getting FirstBarOfSession==true while BarsSinceSession==0.

                Sometimes however - I guess depending on the tick database - I have seen FirstBarOfSession==false while CurrentBar==0 and BarsSinceSession==0,
                thats where my Problem was.

                Now the doc states
                CurrentBar is starting from 0 - so here the index starts at 0
                and on
                BarsInSession it says "BarsElapsed" - so 0 Bars elapsed would mean no Bar is elapsed - we're either in building the 1st Bar (tick chart) or latest at the finish of the 1st bar (CalculateOnBarClose==true). So yes, we have no other Bars in session - but first occurence of BarsSinceSession==0 should be identical with FirstBarInSession.

                Further details:

                I have the following coming in on a minute chart:

                //first OnBarUpdate event
                CurrentBar==0
                Bars.BarsSinceSession==0
                FirstTickOfBar==true
                Bars.FirstBarOfSession==true /*sometimes - it seems depending on the bars database - this can be false too - apparently (at least my conclusion) only if the timestamp of the 1st bar is at session start per primary chart property, FirstBarOfSession would be true. Not sure though.*/

                //subsequent OnBarUpdate events where BarsSinceSession==0
                CurrentBar==count
                Bars.BarsSinceSession==0
                FirstTickOfBar==true
                Bars.FirstBarOfSession==true
                //each next OnBarUpdate event after BarsSinceSession==0
                CurrentBar==count+1
                Bars.BarsSinceSession==1
                FirstTickOfBar==true
                Bars.FirstBarOfSession==false

                -----

                Why bother?

                I need to start computing asap. regardless if SessionBreak or mid day.
                So I took FirstBarOfSession - which seemingly was inadequate at the left edge
                So now I take
                BarsInSession==0 - that seems to work properly at the left edge and at the beginning of any subsequent new session.

                Please correct me if I'm wrong..

                tb

                Comment


                  #9
                  Sorry for the confusion. I was thinking about something else.

                  On a blank chart. You have 0 bars. This is a "0" beyond the 0 on BarsSinceSession. This is flat out nothing so Bars.___ won't return any values.

                  On a chart with data. The very first bar corresponds with BarsSinceSession = 0. This is the case because during this bar there have been no prior bars therefore bars since this session - none. On this bar you get FirstBarOfSession = true.

                  FirstBarOfSession is true whenever it is actually the first bar. It doesn't matter what your chart property for session start time is. If you have session start time at 4AM, but your first bar is timestamped at 4:05AM it will still come out true on that bar.

                  FirstBarOfSession should always be proper at the start of each new session. If you find otherwise please outline exact settings and such so we can try to reproduce.

                  Code:
                  6/23/2008 4:12:00 AM CurrentBar: 0 BarsSinceSession: [COLOR=Red]0[/COLOR] FirstBarOfSession: True
                  6/23/2008 4:14:00 AM CurrentBar: 1 BarsSinceSession: 1 FirstBarOfSession: False
                  6/23/2008 4:30:00 AM CurrentBar: 2 BarsSinceSession: 2 FirstBarOfSession: False
                  6/23/2008 4:31:00 AM CurrentBar: 3 BarsSinceSession: 3 FirstBarOfSession: False
                  ...
                  6/23/2008 4:58:00 PM CurrentBar: 561 BarsSinceSession: 561 FirstBarOfSession: False
                  6/23/2008 4:59:00 PM CurrentBar: 562 BarsSinceSession: 562 FirstBarOfSession: False
                  6/23/2008 5:00:00 PM CurrentBar: 563 BarsSinceSession: 563 FirstBarOfSession: False
                  6/24/2008 4:03:00 AM CurrentBar: 564 BarsSinceSession: [COLOR=Red]0[/COLOR] FirstBarOfSession: True
                  6/24/2008 4:04:00 AM CurrentBar: 565 BarsSinceSession: 1 FirstBarOfSession: False
                  6/24/2008 4:20:00 AM CurrentBar: 566 BarsSinceSession: 2 FirstBarOfSession: False
                  6/24/2008 4:21:00 AM CurrentBar: 567 BarsSinceSession: 3 FirstBarOfSession: False
                  There is no discrepancy as far as I can tell. FirstBarOfSession is true when it is suppose to be and BarsSinceSession is 0 as expected. BarsInSession is not supported so you are on your own if you want to use that.
                  Last edited by NinjaTrader_JoshP; 07-07-2008, 04:52 AM.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Josh,
                    presently I can not verify this any more - I'll keep a lookout.
                    I am positively sure I had the boolean be false on the first tick - consistently - while the count was 0 correctly (all VS debug reads), so you might want to have a look at your side of the code if you like.
                    Thanks anyways!
                    tb

                    PS: The only thing I had modified at system level was a delete of a default workspace gone bad, not sure thats relevant...

                    Comment


                      #11
                      Hi again!

                      Today on ES 09-08 (IB) database I can repeatedly trace that when starting NT the first OnBarUpdate() I am receiving is CurrentBar==1 - instead of an expected 0 (which the code I got uses - as there are redraws starting without an Initialize() and we need to find session start).

                      FirstTickOfBar is true
                      Bars.BarsSinceSession is 1 (also - instead of 0)
                      CalculateOnBarClose is false.
                      The chart is set to 1 min bars.

                      One observation: ChartControl.SessionBegin is 01.01.0001 00:00 - and the first tick I get carries the 09.07.2008 00:02:00 timestamp.

                      Once I set the session start to e.g. 09:30 for the symbol, that first tick is coming in with CurrentBar==0 - but regardless of that the first Bar I get with NT start seems always CurrentBar==1 (but 0 after pressing F5 to reload).

                      So what's the safest to determine session start at the left side of a chart?

                      Thanks ahead!

                      tb

                      Comment


                        #12
                        tb,

                        I am unable to reproduce your behavior on my end. Please attach a simple as possible reference that demonstrates what you are experiencing.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Josh,
                          thanks. I think I have the culprit.
                          Can I can send you some code sample offline?
                          Thanks
                          tb

                          Comment


                            #14
                            Please mail Josh a simple as possible strategy/scenario to josh AT ninjatrader DOT com. Thanks

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by rocketman7, Today, 01:00 AM
                            0 responses
                            1 view
                            0 likes
                            Last Post rocketman7  
                            Started by wzgy0920, 04-20-2024, 06:09 PM
                            2 responses
                            27 views
                            0 likes
                            Last Post wzgy0920  
                            Started by wzgy0920, 02-22-2024, 01:11 AM
                            5 responses
                            32 views
                            0 likes
                            Last Post wzgy0920  
                            Started by wzgy0920, 04-23-2024, 09:53 PM
                            2 responses
                            74 views
                            0 likes
                            Last Post wzgy0920  
                            Started by Kensonprib, 04-28-2021, 10:11 AM
                            5 responses
                            193 views
                            0 likes
                            Last Post Hasadafa  
                            Working...
                            X