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

What is BarsSinceSession

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

    What is BarsSinceSession

    I've noticed that BarsSinceSession returns the same int asCurrentBar so what's the actual use of it?

    And what exactly is the meaning of 'Session'? is it the time of the current trading session? the time of opening a new chart? of loading the indicator?

    Thanks.

    #2
    Hello savekad,
    Bars since session returns how many bars has elapsed since the start of the session.


    Session is the session template you apply on the chart via the Data Series parameter dialog.
    Last edited by NinjaTrader_Joydeep; 08-23-2012, 03:45 AM.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      So it is the number of bars since the starting of the session according the to session template in use?

      That means that there could be a chart loaded with bars of two sessions, and the BarsSinceSession will return the number of bars for the current one, ignoring the previous one, correct?

      Comment


        #4
        I've checked. According to my test the answer is yes.

        Comment


          #5
          Hello savekad,
          Yes, if you have data for 2 sessions then the Bars.BarsSinceSession will return the bar number of the latest/current session.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            Hello, I have a question.

            When I am using Bars.BarsSinceSession >= 2 , it works perfectly in the morning session, there will be no trades until the third bar. However during the afternoon session, trading starts from the first bar. I am using the ose session template.

            Thanks in advance.

            Comment


              #7
              Confusion between session and trading day

              This is one of the well known NinjaTrader bugs. For many NinjaScript methods there is a confusion about the concept of a trading session and a trading day, as originally, when the software was designed, the difference between "trading day" and "session" was not understood.

              The method Bars.BarsSinceSession returns the bar number since the start of the trading day. The first bar of the trading day is counted as zero.The counting does not reset at the beginning of the afternoon session. NinjaTrader here calls the trading day a session.

              There are quite a few other problems resulting from this confusion. For example in a strategy all orders GTD (good till day), will be cancelled at the end of the session instead at the end of the trading day. For that reason I am now partly coming back to the use of single session trading days, when running automated strategies. NinjaTrader here calls the session a trading day, which is the reverse problem to the one encountered above.

              Please make sure that this confusion is being sorted out for NinjaTrader 8!
              Attached Files

              Comment


                #8
                Hello beierde888,

                What Harry said is correct. Basically, if there are multiple Sessions within one calendar day NinjaTrader will not reset the BarsSinceSession until the next calendar day (based on your Local PC).

                I believe it is more of a design limitation but either way that is something on our Enhancement list for NT8 NinjaScript.

                Let me know if you have any questions.
                Last edited by NinjaTrader_JC; 07-24-2013, 07:06 AM.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  But it is easy to calculate the number of bars since the session start. Here is the code

                  Code:
                  [COLOR=Blue]# region[/COLOR] Variables
                  [COLOR=Blue]private int [/COLOR]count = 0;
                  ........
                  [COLOR=Blue]#endregion[/COLOR]
                  
                  [COLOR=Blue]protected override void[/COLOR] OnBarUpdate()
                  {
                      [COLOR=Blue] if[/COLOR] (FirstTickOfBar)
                       {
                           [COLOR=Blue]if[/COLOR] (Bars.FirstBarOfSession)
                               count = 0;
                           [COLOR=Blue]else[/COLOR]
                               count = count + 1;
                       }    
                  .......
                  }
                  Now you just need to access count for your purpose.

                  Comment


                    #10
                    Thanks for the code Harry, that helped a lot!

                    Comment


                      #11
                      Is BarsSinceSession correct when Historical is true or is it only valid for the last bar of the chart?

                      Is that the same for FirstBarOfSession too?

                      Comment


                        #12
                        Originally posted by adamus View Post
                        Is BarsSinceSession correct when Historical is true or is it only valid for the last bar of the chart?

                        Is that the same for FirstBarOfSession too?
                        Both Bars.FirstBarOfSession and Bars.BarsSinceSession can be accessed for both historical and real-time data. Bars.FirstBarOfSession is a Boolean, which holds the value "true" for the first bar of each session and which holds the value "false" for all other bars. Bars.BarsSinceSession returns an integer which holds the value of the number of bars elapsed since the session start.
                        Last edited by Harry; 01-24-2015, 06:56 AM.

                        Comment


                          #13
                          OK thanks.

                          Do you know whether FirstBarOfSession is true only for the bar at the time of the session start, or if I am missing a bar of data at the start, will the next bar be true instead?

                          Comment


                            #14
                            Hello adamus,

                            Bars.FirstBarOfSession will be true on the first Bar of the new session even if it is 5 mintues after the session has started if there is no data to generate a bar.

                            Let us know if we can be of any further assistance.
                            JCNinjaTrader Customer Service

                            Comment


                              #15
                              More Confusion between session and trading day

                              First of all: I'm a noob re: NT7, but have quite some programming experience in my previous life, however I'm at a loss regarding this Bars.BarsSinceSession thing ...

                              1. I want to find the High/Low for a certain range of time, let's say: What's the High/Low from 00:00:00h until 15:29h?

                              2. I want to find the bar within that timeframe which has the highest amount of volume tied to it (e.g. at 09:07 the volume was the highest at 4501 contracts traded that minute)

                              I spent the whole day digging up various sources, but I'm at a loss, so hopefully some of you nice people can point me in the right direction. Thanks much in advance.

                              - ABC

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by BarzTrading, Today, 07:25 AM
                              2 responses
                              15 views
                              1 like
                              Last Post BarzTrading  
                              Started by devatechnologies, 04-14-2024, 02:58 PM
                              3 responses
                              20 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by tkaboris, Today, 08:01 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post tkaboris  
                              Started by EB Worx, 04-04-2023, 02:34 AM
                              7 responses
                              162 views
                              0 likes
                              Last Post VFI26
                              by VFI26
                               
                              Started by Mizzouman1, Today, 07:35 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X