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

Bars.FirstBarOfSession TWO BARS bug?

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

    Bars.FirstBarOfSession TWO BARS bug?

    Hi guys,

    I notice a strange occurrence back-testing a multitimeframe system.

    I am running the backtest on 1440min bars (i.e. 1 day) on ES 09-14
    And I've added a 1min time period within code, (which I place trades off)

    When I print out the Time[0] for first bar of session, I've been getting unusal values.
    I should see 23:01 (because in UK when the US mini S&P opens it is 23:00)

    But sometimes I also see 00:01 as the first bar, AND THEN an additional 'firstbarofsession' for the same session, but with the correct 23:01.

    THERE CAN ONLY BE ONE FIRST BAR OF SESSION RIGHT? Why are there sometimes two occasions in a day that set the FirstBarOfSession flag to true?

    Also sometimes days are missed out e.g. Sunday and Friday. I understand Friday as markets shut.. but why is Sunday sometimes missed out and sometimes it is there. Please see the code then a copy of my output:
    Ps I'm using latest version of NT 7...25 and use Rithmic connection but it uses NinjaTrader historical servers for data


    Day = Monday
    1st bar time = 01/02/2010 00:01:00

    Day = Monday
    1st bar time = 01/02/2010 23:01:00 Why are there two First bars for this session?

    Day = Tuesday
    1st bar time = 02/02/2010 23:01:00

    Day = Wednesday
    1st bar time = 03/02/2010 23:01:00

    Day = Thursday
    1st bar time = 04/02/2010 23:01:00

    Day = Monday
    1st bar time = 08/02/2010 00:01:00

    Day = Monday
    1st bar time = 08/02/2010 23:01:00
    and again why are there two first bars for this session?

    Day = Tuesday
    1st bar time = 09/02/2010 23:01:00

    Day = Wednesday
    1st bar time = 10/02/2010 23:01:00

    Day = Thursday
    1st bar time = 11/02/2010 23:01:00

    Day = Monday
    1st bar time = 15/02/2010 00:01:00

    Day = Tuesday
    1st bar time = 16/02/2010 00:01:00
    and again there are two First bars for this session?

    Day = Tuesday
    1st bar time = 16/02/2010 23:01:00

    Day = Wednesday
    1st bar time = 17/02/2010 23:01:00

    Day = Thursday
    1st bar time = 18/02/2010 23:01:00

    Day = Monday
    1st bar time = 22/02/2010 00:01:00

    Day = Monday
    1st bar time = 22/02/2010 23:02:00

    Ps where is Sunday or Friday? Sunday should appear


    And the guilty code is here:




    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    // **************************************
    // **** NOTE BACKTEST on 1440 min bars ****
    //*****************************************
    Print("NOTE: Remember to use 1440 min bars for backtest..");

    Add(PeriodType.Minute, 1); // Add intraday timeframe..
    ClearOutputWindow();
    CalculateOnBarClose = true;
    ExitOnClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {

    if (BarsInProgress == 1 // Intraday..
    && Bars.FirstBarOfSession == true)

    {

    Print("Day = " + Time[0].DayOfWeek.ToString());
    Print("1st bar time = " + Time[0]);
    Print("");
    }

    ...}


    Any help would be much appreciated
    Thanks guys!

    #2
    Hello regikeyz,

    Thank you for your post.

    What session template are you using for the back test?

    I tested this on my end using the default template and was getting the correct results for the FirstBarOfSession using the code you supplied
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Thank-you for trying this so quickly.

      My session template is <use instrument settings>

      When I go into instrument manager in 'Instrument Editor' for ES I see under session template:
      CME US Index Futures ETH


      Thank-you

      Comment


        #4
        regikeyz,

        There are two things here that I want you to test.

        First is to reset the instruments.
        To reset your instruments please: go to the Tools menu, select the Options menu item, select the Data tab, and then click on 'Reset Instruments'.

        Re-test the strategy. If you are still getting the prints then we need to look at the data
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Hi Cal, still exactly the same issue


          Day = Monday
          1st bar time = 21/06/2010 23:01:00

          Day = Tuesday
          1st bar time = 22/06/2010 23:01:00

          Day = Wednesday
          1st bar time = 23/06/2010 23:01:00

          Day = Thursday
          1st bar time = 24/06/2010 23:01:00

          Day = Monday
          1st bar time = 28/06/2010 07:06:00

          Day = Monday
          1st bar time = 28/06/2010 23:01:00

          Comment


            #6
            regikeyz,

            Thanks for the update.

            Can you please send me a request to support so we can setup a remote session time.

            Help -> Mail to Platform Support

            Put ATTN Cal in the subject and reference this thread in the body
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Just sent email, thank-you

              Comment


                #8
                regikeyz,

                Thank you for your time today.

                Per our findings we found that the double prints was due to missing data and the session starting at the 12:01 bar and causing it to look like two FirstBarOfSessions to appear.

                Additionally, there were a couple days where the day before was a major holiday, causing a late session start.

                Let me know if I can be of further assistance.
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  You were a great help Cal, thanks for confirming.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by bortz, 11-06-2023, 08:04 AM
                  47 responses
                  1,604 views
                  0 likes
                  Last Post aligator  
                  Started by jaybedreamin, Today, 05:56 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post jaybedreamin  
                  Started by DJ888, 04-16-2024, 06:09 PM
                  6 responses
                  18 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by Jon17, Today, 04:33 PM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jon17
                  by Jon17
                   
                  Started by Javierw.ok, Today, 04:12 PM
                  0 responses
                  13 views
                  0 likes
                  Last Post Javierw.ok  
                  Working...
                  X