• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is BarsSinceSession

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

  • savekad
    started a topic What is BarsSinceSession

    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.

  • Harry
    replied
    Here is an indicator that collects the high and low of the pre-session and then calculates the opening range after the regular session has started. The indicator comes open source, so you can study how it works.

    Basically, you need to determine the start of the trading day in line with the session template. Then you compare the timestamp of the bar with the time that you have selected for the anchor point of your range. You let OnBarUpdate() loop through all the bars until the specified closing time of your range. With each loop you collect the bar high and low of each bar, and if needed update the high and low of the range.

    There is one problem, if you look at bars built from ticks. Usually tick bars do not align with the anchor and closing time of your range, but you will get two overlapping bars in the beginning and in the end of your range. Therefore it is a better solution to add a secondary bar series of 1-minute bars to your indicator and perform all calculations on 1-minute bars, as the 1-minute bars typically align with the anchor time and closing time of the range.

    You can find the indicator here:

    https://www.bigmiketrading.com/downl...load.html?view

    If you are not an elite member of that forum, please send me a private message with your e-mail, and I will send you the install file.
    Attached Files

    Leave a comment:


  • abctrader
    replied
    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

    Leave a comment:


  • NinjaTrader_JC
    replied
    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.

    Leave a comment:


  • adamus
    replied
    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?

    Leave a comment:


  • Harry
    replied
    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.

    Leave a comment:


  • adamus
    replied
    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?

    Leave a comment:


  • beierde888
    replied
    Thanks for the code Harry, that helped a lot!

    Leave a comment:


  • Harry
    replied
    But it is easy to calculate the number of bars since the session start. Here is the code

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

    Leave a comment:


  • NinjaTrader_JC
    replied
    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.

    Leave a comment:


  • Harry
    replied
    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

    Leave a comment:


  • beierde888
    replied
    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.

    Leave a comment:


  • NinjaTrader_Joydeep
    replied
    Hello savekad,
    Yes, if you have data for 2 sessions then the Bars.BarsSinceSession will return the bar number of the latest/current session.

    Leave a comment:


  • savekad
    replied
    I've checked. According to my test the answer is yes.

    Leave a comment:


  • savekad
    replied
    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?

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by johnnybegoode, Today, 11:35 AM
1 response
9 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by NickyD, Today, 09:07 AM
3 responses
14 views
0 likes
Last Post NickyD
by NickyD
 
Started by 7robert, Today, 06:46 AM
3 responses
62 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by ElMagoR, Today, 07:49 AM
4 responses
31 views
0 likes
Last Post NinjaTrader_ChrisL  
Started by Nabil, 09-13-2019, 11:44 AM
5 responses
35 views
0 likes
Last Post Nabil
by Nabil
 
Working...
X