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

Understanding Bars.IsFirstBarOfSession

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

    Understanding Bars.IsFirstBarOfSession



    Is Bars.IsFirstBarOfSession once per day, or only once at the start?


    I need to better understand the frequency of Bars.IsFirstBarOfSession. Say I'm trading the futures instrument YM, which trades o the "CME US Index Futures ETH" schedule, which goes Sunday through Friday, 5 PM to 4 PM central time (five days a week).

    Therefore, would Bars.IsFirstBarOfSession be true for five days, each day, at the session start of 5 PM Central time? Or, would Bars.IsFirstBarOfSession only be true once per week, on the Sunday at 5 PM central time?

    Thanks for your clarification.





    #2
    Hello timmbbo,

    Thank you for your post.

    This can be tested by adding a print statement in a script when Bars.IsFirstBarOfSession is true, such as the example from the help guide:
    Code:
    protected override void OnBarUpdate()
    {
      // Print the current bar number of the first bar processed for each session on a chart
      if (Bars.IsFirstBarOfSession)
        Print(string.Format("Bar number {0} was the first bar processed of the session at {1}.", CurrentBar, Time[0]));
    }​


    If you apply this to a chart using the CME US Index Futures ETH trading hours schedule, this print appears once per day at 5 PM Central time, not once per week.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by timmbbo View Post
      Is Bars.IsFirstBarOfSession once per day, or only once at the start?


      I need to better understand the frequency of Bars.IsFirstBarOfSession. Say I'm trading the futures instrument YM, which trades o the "CME US Index Futures ETH" schedule, which goes Sunday through Friday, 5 PM to 4 PM central time (five days a week).

      Therefore, would Bars.IsFirstBarOfSession be true for five days, each day, at the session start of 5 PM Central time? Or, would Bars.IsFirstBarOfSession only be true once per week, on the Sunday at 5 PM central time?
      When it's true, it's only true for one bar -- the next bar will be false.

      There is typically one session per day, which starts at 5pm CST,
      Sunday - Thursday.

      So, on the very first bar close after 5pm CST, that very first bar,
      and only that bar, IsFirstBarOfSession is true.

      Comment


        #4

        Emily, yep, it works the way you describe on a live market, but not in Replay Mode.

        I'm doing a replay, starting on Jan 1, 2020. I am printing out each time when Bars.IsFirstBarOfSession is true. As you can see, I only get one hit. Then, even though I run the simulation for over a week, Bars.IsFirstBarOfSession is never again true. I get this behavior on any futures instrument, such as YM, RTY, NQ, and GC.

        I can only speculate there's an issue on NT's end. Your thoughts? Thanks,



        bltdavid, thanks for your feedback. The problem I'm having is that I'm getting different behavior on Bars.IsFirstBarOfSession in a live market vs replay mode. So, of course, it becomes very difficult to accurately back test.
        Attached Files
        Last edited by timmbbo; 11-02-2023, 02:26 PM.

        Comment


          #5
          Hello timmbbo,

          Thank you for your reply.

          So I may accurately assist you, please answer all of the following questions:
          • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)
          • What instrument symbol (and expiry if applicable) have you selected? For example, ES 03-22, AAPL, EURUSD, etc.
          • (For a chart) what interval is selected? For example, 5 minute, 1 day, 2000 volume, 4 Renko, etc.
          • If you check the Control Center > Tools > Historical Data window and expand the Market Replay data section, do you have data for the instrument and dates you are playing back?
          Something that may be relevant here is that IsFirstBarOfSession is always true on the first bar processed; if you print the value for CurrentBar, is it 0? The first bar processed is not always the first bar according to the trading hours start time, so this is something to consider especially since you are only getting one print. This information may be found in the note on the help guide page here:


          I look forward to your reply.
          Emily C.NinjaTrader Customer Service

          Comment


            #6

            Emily, thanks for your prompt reply

            1) Am using 8.1.1.7 64 bit (Don't ask me to upgrade to the latest version. I'm running NT Playback connections on machines not connected to the network. Very irritatingly, the newest version of NT requires a network connection to authenticate. This will be a separate rant for another post.)

            2) I am testing on GC 12-23. As I mentioned, I can duplicate this issue on YM, RTY, NQ, and other future instruments, on any quarter.

            3) For interval, I am using volume. Just pick a number, and it'll show up. I've used 1500, 2500, 4500, 6800 volumes, and so on.

            4) Yes, I do have the data. I see the chart moving forward. Furthermore, my other strategies that rely upon IsFirstTickOfBar are active and trading.


            I'm betting this is an issue on NT's end, where Bars.IsFirstBarOfSession simply isn't being reset in playback mode.

            Thanks again

            Comment


              #7
              Hell timmbbo,

              Thank you for your reply.

              I was unable to reproduce this with the attached test script I created. I tested this on the Playback connection with ES 12-23 data from 10/23-10/27. I applied the indicator to a 1-minute chart and then also tested it on a 1000-volume chart successfully. Please test this indicator on your end and advise whether you are seeing prints when IsFirstBarOfSession is false as well or not. The indicator may be imported via Control Center > Tools > Import > NinjaScript AddOn. If you are seeing unexpected behavior for the dates in January of 2020, please also try downloading a few recent days of playback data and testing those as well.

              I look forward to hearing the results.
              Attached Files
              Emily C.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jonafare, 12-06-2012, 03:48 PM
              5 responses
              3,986 views
              0 likes
              Last Post rene69851  
              Started by Fitspressorest, Today, 01:38 PM
              0 responses
              2 views
              0 likes
              Last Post Fitspressorest  
              Started by Jonker, Today, 01:19 PM
              0 responses
              2 views
              0 likes
              Last Post Jonker
              by Jonker
               
              Started by futtrader, Today, 01:16 PM
              0 responses
              8 views
              0 likes
              Last Post futtrader  
              Started by Segwin, 05-07-2018, 02:15 PM
              14 responses
              1,792 views
              0 likes
              Last Post aligator  
              Working...
              X