Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

clarification on bar values in multi-instrument strategy

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

    clarification on bar values in multi-instrument strategy

    My brain is hung up on what I feel is an inconsistency in NT, possibly a serious bug. I'm hoping someone can clarify for me. As far as I understand it:
    1. The value Closes[x][0] is the value for data series X at the close of the last COMPLETED bar in the data series X (not the current value of the bar in progress).
    2. A bar is not completed until the NEXT bar opens for that instrument.

    So here's my problem. I have data series ABCD as my secondary data series. It includes the following sequential minute bars (only closing values shown below).

    8/4 15:58; 395.6500
    8/4 15:59; 395.6000
    8/5 02:00; 395.1000

    Now, according to rules 1 & 2 above, on 8/4 16:02 the value of Closes[1][0] should be 395.6500 since the last completed bar would be the 15:58 bar above. And indeed, that is the value for Closes[1][0] when I run a historical test up to 8/5. However, if I instead run the historical test to 8/6, the value of Closes[1][0] at 8/4 16:02 becomes 395.6000.

    The strategy analyzer seems to be inappropriately closing a bar prior to the open of the next bar. It does this when it sees a future bar in memory. This seems to be a serious issue, since in real-time it would not be able to see that future bar to close out the current bar. In the example above, the 15:59 bar should not close until 8/5 02:00.

    Please help me on this issue. Thank you.

    #2
    Here is a basic strategy to show you what I mean. I've also attached data for instrument ABCD.

    Code:
    public class Test2: Strategy
    	{
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Strategy here.";
    				Name										= "Test2";
    				Calculate									= Calculate.OnBarClose;
    				EntryHandling								= EntryHandling.AllEntries;
    				IsExitOnSessionCloseStrategy				= true;
    				
    			}
    			
    			else if (State == State.Configure)
                {
    				AddDataSeries("ABCD",BarsPeriodType.Minute, 1);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{		
    			Print(Time[0] + "     " + Closes[1][0] );
    		}
    	}
    Load ABCD as a stock, then run strategy analyzer with the following properties:
    Instrument: any that has ticks after 16:00, such as ES
    Trading hours: default 24/7
    Break at EOD: yes
    Start Date: 08/01/2014

    Run #1 with END DATE= 08/05/2014
    output: 8/4/2014 4:02:00 PM 395.65
    Run #2 with END DATE= 08/06/2014
    output: 8/4/2014 4:02:00 PM 395.6
    Attached Files

    Comment


      #3
      Hello YD777,

      Thank you for your post.

      Originally posted by YD777 View Post
      However, if I instead run the historical test to 8/6, the value of Closes[1][0] at 8/4 16:02 becomes 395.6000.
      The Strategy Analyzer processes the data by bar. You state you are checking at 16:02 pm? How are you checking at this time? If this the PC clock time you are referring to?

      I look forward to your response.

      Comment


        #4
        Originally posted by NinjaTrader_PatrickH View Post
        Hello YD777,

        Thank you for your post.


        The Strategy Analyzer processes the data by bar. You state you are checking at 16:02 pm? How are you checking at this time? If this the PC clock time you are referring to?

        I look forward to your response.
        Please see the post above, I already posted the code. Not using PC clock, there are 2 instruments in the strategy and I use:

        Print(Time[0] + " " + Closes[1][0] );

        That line gets run when OnBarUpdate is called by the primary bars closing.

        Comment


          #5
          Hello YD777,

          Thank you for your response.

          I am asking how you are verifying the time at 16:02. Your data does not go to 16:02. Can you provide your Output that shows the time at 16:02?

          The Strategy Analyzer processes bar by bar and not by time.

          Please provide the full detail on how you verify the case at 16:02.

          Comment


            #6
            Originally posted by NinjaTrader_PatrickH View Post
            Hello YD777,

            Thank you for your response.

            I am asking how you are verifying the time at 16:02. Your data does not go to 16:02. Can you provide your Output that shows the time at 16:02?

            The Strategy Analyzer processes bar by bar and not by time.

            Please provide the full detail on how you verify the case at 16:02.
            OnBarUpdate gets called for all bars in a multi-instrument strategy. So if the primary bars have a bar at 16:02 (or 16:03, or 16:04, etc), the following line will run even if ABCD has no data:

            Print(Time[0] + " " + Closes[1][0] );

            Time[0] is the time of the current bar calling OnBarUpdate. So if the primary instrument is a liquid instrument like ES, you'll get a moment at 16:02 (and 16:03, and 16:04, etc).

            Closes[1][0] is the last close of the ABCD bar. Close[0][0] would be the close of ES (or any other instrument of your choice that has ticks at 16:02). I assume you guys have historical data on ES you can run as the primary instrument, but if not I can send you.

            Comment


              #7
              Hello YD777,

              Thank you for the additional information.

              I tested with ES and I see the Time bars updating past the bars for the ABCD but I do not see the behavior you detailed.

              Are you using a specific Trading Hours Template for the ES?

              Can you attach your historical ES data for the tested time period to your response? You can export data from the Tools > Historical Data window and the Load tab.

              I look forward to your response.

              Comment


                #8
                Originally posted by NinjaTrader_PatrickH View Post
                Hello YD777,

                Thank you for the additional information.

                I tested with ES and I see the Time bars updating past the bars for the ABCD but I do not see the behavior you detailed.

                Are you using a specific Trading Hours Template for the ES?

                Can you attach your historical ES data for the tested time period to your response? You can export data from the Tools > Historical Data window and the Load tab.

                I look forward to your response.
                I've attached my data for ES. But let me stress, it doesn't have to be ES, it can be any instrument that is liquid enough to have bars after 16:00, and doesn't depend on the trading template.

                What output do you get for ABCD at 16:02? Are you running it between 08/01/2014 and 08/05/2014 and comparing to 08/01/2014 - 08/06/2014?
                Attached Files

                Comment


                  #9
                  Hello YD777,

                  Thank you for your response.

                  What time was the ABCD historical data file exported with and what time zone was the ES ##-## historical data file exported with?

                  I want to make sure my data is matching in my test.

                  Comment


                    #10
                    All US Eastern Standard.

                    ABCD was imported as "beginning of bar Timestamps". And "Last"

                    Comment


                      #11
                      Hello YD777,

                      Thank you for your patience.

                      I was able to reproduce this exactly on my end. I will follow up with you when I have any details on the matter.

                      Comment


                        #12
                        Originally posted by NinjaTrader_PatrickH View Post
                        Hello YD777,

                        Thank you for your patience.

                        I was able to reproduce this exactly on my end. I will follow up with you when I have any details on the matter.
                        Hi Patrick,
                        Do you have updates on the bug?

                        Comment


                          #13
                          Hello YD777,

                          Thank you for your patience.

                          I am working with our development team on this matter and when I have details I will follow up here.

                          Comment


                            #14
                            Hello YD777,

                            Thank you for your patience.

                            I have received information on this case that I would like to share.

                            The behavior is considered expected. The historical processing of timestamps will be performed in ascending order and force this to occur where as you would not see this in real-time processing as there is no bar ahead of the current real-time bar.

                            Please let me know if you have any questions.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by space_trader, 11-26-2020, 05:06 AM
                            2 responses
                            164 views
                            1 like
                            Last Post klaus w
                            by klaus w
                             
                            Started by Kicks.Spin, Today, 07:46 AM
                            1 response
                            3 views
                            0 likes
                            Last Post NinjaTrader_PaulH  
                            Started by Renejm, Today, 06:17 AM
                            1 response
                            4 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Started by kazisl, Yesterday, 06:41 PM
                            2 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_PaulH  
                            Started by impactX, 05-04-2021, 01:07 AM
                            2 responses
                            11 views
                            0 likes
                            Last Post NinjaTrader_Melissa  
                            Working...
                            X