Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Discrepancy between DataSeries

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

    Discrepancy between DataSeries

    Hi there. I am looking to add some granularity to my back tests and I have come across some odd behavior. I am using size 30 range bars as my primary data series. I am then adding a 1 tick second data series to add the granularity to my back tests.

    I entered a few trades where gave the 2nd data series as the parameter in the EnterLong/EnterShort methods. However all of the trade logic is done at end-on-bar for the primary data series (the range bars).

    Looking back over my results, I saw that the executions were not being done at the end of the bar, but in the middle of the bar. Thus, I added the following 2 print statements:

    Code:
             Print("TradeLogicEndOfBar called at " + Time[0] + " with Close[0] = " + Close[0]);
             Print("Closes[1][0] is: " + Closes[1][0]);
    Which gave the following output:

    TradeLogicEndOfBar called at 1/4/2013 8:30:06 AM with Close[0] = 867.2
    Closes[1][0] is: 868.4

    That's a huge difference in prices. Based on the help guide regrading multi-time frames, since the 2 are being called right together, they should be the same price as this is being called at OnBarUpdate when BarsInProgress == 0.

    Data is from DTN.

    I've attached a couple of screenshots showing details.

    Thanks so much for your time.

    Shane
    Attached Files

    #2
    Posting another screenshot. Similar issue with the ES with Kinetick data.

    Comment


      #3
      Originally posted by tickleboy View Post
      Hi there. I am looking to add some granularity to my back tests and I have come across some odd behavior. I am using size 30 range bars as my primary data series. I am then adding a 1 tick second data series to add the granularity to my back tests.

      I entered a few trades where gave the 2nd data series as the parameter in the EnterLong/EnterShort methods. However all of the trade logic is done at end-on-bar for the primary data series (the range bars).

      Looking back over my results, I saw that the executions were not being done at the end of the bar, but in the middle of the bar. Thus, I added the following 2 print statements:

      Code:
               Print("TradeLogicEndOfBar called at " + Time[0] + " with Close[0] = " + Close[0]);
               Print("Closes[1][0] is: " + Closes[1][0]);
      Which gave the following output:

      TradeLogicEndOfBar called at 1/4/2013 8:30:06 AM with Close[0] = 867.2
      Closes[1][0] is: 868.4

      That's a huge difference in prices. Based on the help guide regrading multi-time frames, since the 2 are being called right together, they should be the same price as this is being called at OnBarUpdate when BarsInProgress == 0.

      Data is from DTN.

      I've attached a couple of screenshots showing details.

      Thanks so much for your time.

      Shane
      Why would you expect that Close[0] would necessarily be identical to Close[1][0]? They are completely different barSeries. While they can be identical, they actually will only be so on the exact tick that matches the actual end of bar time on the time-based barSeries.
      Last edited by koganam; 07-21-2013, 04:37 PM. Reason: Corrected grammar.

      Comment


        #4
        Originally posted by koganam View Post
        Why would you expect that Close[0] would necessarily be identical to Close[1][0]? They are completely different barSeries. While they can be identical, they actual will only be on the exact tick that matches the actual end of bar time on the time-based barSeries.
        Perhaps I am not understanding this correctly, but given the page in the help guide on Multi-Data Series, a 5 tick range bar and a 1 tick bar of the same instrument would be called in the following manner:

        Tick at 100
        -First tick of range bar
        -Closes[1][0] = 100 and thus OnBarUpdate called with BarsInProgress == 1

        Tick at 101
        -Range bar still in progress of being built, now at a size of 2 ticks
        -Closes[1][0] = 101 and thus OnBarUpdate called with BarsInProgress == 1

        Tick at 102
        -Range bar still in progress of being built, now at a size of 3 ticks
        -Closes[1][0] = 102 and thus OnBarUpdate called with BarsInProgress == 1


        Tick at 103
        -Range bar still in progress of being built, now at a size of 4 ticks
        -Closes[1][0] = 103 and thus OnBarUpdate called with BarsInProgress == 1


        Tick at 104
        -Range bar still in progress of being built, now at a size of 4 ticks
        -Closes[1][0] = 104 and thus OnBarUpdate called with BarsInProgress == 1

        Tick at 105
        -New Range bar now started and thus OnBarUpdate Called with BarsInProgress == 0
        -Closes[1][0] = 105 and thus OnBarUpdate called with BarsInProgress == 1

        This would be logical to me since both of the bars are being built from the same instrument tick data.

        I don't quite understand where time comes into play here as building these bars would follow similar logic to the above to build them.

        Comment


          #5
          Shane, would you mind posting the full sample script that you run? I cannot reproduce on my DTN Data here, when I print both Close[0] and Closes[1] on the BIP Range bar updates, I see nearly identical prints for the prices - the way I would expect.

          (BIP, Timestamp primary bar, Close[0], Closes[1][0])

          0 3/15/2013 9:39:47 AM 947.3 947.3
          0 3/15/2013 10:00:00 AM 945.6 945.6
          0 3/15/2013 10:42:32 AM 948.1 948.1
          0 3/15/2013 12:35:00 PM 949.9 949.9
          0 3/15/2013 2:35:50 PM 948 948
          0 3/15/2013 5:59:58 PM 948.7 948.7
          0 3/17/2013 6:00:15 PM 941 941.1
          0 3/17/2013 6:00:51 PM 938.3 939
          0 3/17/2013 6:01:01 PM 939.3 938.1
          0 3/17/2013 6:05:35 PM 940.5 940
          0 3/17/2013 6:15:43 PM 938 938
          0 3/17/2013 9:12:23 PM 936.7 936.7
          0 3/18/2013 1:13:50 AM 934.1 934.1
          0 3/18/2013 3:11:19 AM 936.5 936.6
          0 3/18/2013 5:29:12 AM 938.5 938.5
          0 3/18/2013 6:28:17 AM 937.2 937.3
          0 3/18/2013 7:57:46 AM 939 939
          0 3/18/2013 9:20:32 AM 938 938
          0 3/18/2013 9:36:06 AM 940.8 940.8
          0 3/18/2013 9:56:47 AM 943.8 943.8
          0 3/18/2013 10:09:42 AM 941.2 941.2
          0 3/18/2013 10:26:55 AM 943.4 943.3
          0 3/18/2013 11:11:22 AM 944.3 944.3
          0 3/18/2013 12:00:52 PM 946.5 946.5
          0 3/18/2013 3:00:51 PM 944.5 944.5
          0 3/18/2013 3:36:07 PM 942.5 942.5
          0 3/18/2013 4:01:15 PM 944.4 944.4
          0 3/18/2013 5:59:29 PM 945.1 945.2
          0 3/19/2013 8:05:01 AM 946.4 946.3
          0 3/19/2013 10:01:10 AM 947.9 947.8
          0 3/19/2013 10:24:52 AM 945.4 945.4
          0 3/19/2013 10:49:52 AM 942.5 942.5
          0 3/19/2013 11:30:18 AM 944.6 944.6
          0 3/19/2013 11:43:23 AM 942.5 942.5
          0 3/19/2013 11:51:08 AM 940.2 940.2
          0 3/19/2013 11:58:40 AM 937.4 937.5
          0 3/19/2013 12:15:16 PM 936.2 936.3
          0 3/19/2013 12:27:22 PM 938.9 938.9
          0 3/19/2013 12:56:03 PM 937.4 937.3
          0 3/19/2013 1:19:39 PM 934.7 934.7
          0 3/19/2013 1:37:38 PM 932.6 933
          0 3/19/2013 1:57:12 PM 934.6 934.5
          0 3/19/2013 2:31:12 PM 937.7 937.7
          0 3/19/2013 3:14:11 PM 939 938.8
          0 3/19/2013 3:21:05 PM 937.9 937.9
          0 3/19/2013 4:02:34 PM 940 940
          0 3/19/2013 5:15:00 PM 937.8 937.9
          0 3/19/2013 5:59:58 PM 937.4 937.4
          0 3/20/2013 2:41:20 AM 939.3 939.3
          0 3/20/2013 4:01:22 AM 941.9 941.9
          0 3/20/2013 8:07:17 AM 944.4 944.4
          0 3/20/2013 9:38:57 AM 946.6 946.5
          0 3/20/2013 9:48:55 AM 944.9 944.9
          0 3/20/2013 11:58:43 AM 943.9 943.9

          Comment


            #6
            Hi Bertrand. I can't post the entire strategy due to an NDA I've signed, but you probably couldn't run it anyway as it requires some 3rd party indicators installed.

            However, what I did was create a very simple multi-data series strategy that simulates what we do in our strategy, minus the entry calculations, and ran it. The code for the simple one is:

            Code:
                  
            protected override void Initialize()
                  {
                     Add(PeriodType.Tick, 1);
                     CalculateOnBarClose = true;
                  }
            
                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                     if (BarsInProgress == 0)
                     {
                        Print("TradeLogicEndOfBar called at " + Time[0] + " with Close[0] = " + Close[0]);
                        Print("Closes[1][0] at " + Times[1][0] + " with Closes[1][0] = " + Closes[1][0]);
                     }
                  }
            Now when I run this strategy on the same data and same chart (30 Range bars), the data is very close as shown in the attached screenshot.

            So the issue appears to be in our strategy. My initial question would be "Are Data Series in Ninja Trader multi-threaded?" As our strategy does a lot of calculations when OnBarUpdate is called when BarsInProgress == 0, does OnBarUpdate continue to be called with BarsInProgress == 1 at the same time BarsInProgress ==0 thread is running?

            If not, then I am curious why there is such a large discrepancy between the 2 strategies.

            Thanks again for your time Bertrand!
            Attached Files

            Comment


              #7
              Another screenshot of a log file. This time I put in a print statements at the start of OnBarUpdate of our strategy (Not the simple one from last post). Basically it does:
              Code:
              OnBarUpdate()
              {
              if(BarsInProgress == 0) // 30 Range Bars
              {
                       PrintToLowLog("TradeLogicEndOfBar called at " + Time[0] + " with Close[0] = " + Close[0]);
                       PrintToLowLog("TradeLogicEndOfBar called at " + Times[1][0] + " with Closes[1][0] = " + Closes[1][0]);
              
              }
              else if (BarsInProgress == 1) // 1 tick Data Series
              {
              PrintToLowLog("OnBarUpdate(1) called at " + Times[1][0] + " with Closes[1][0] = " + Closes[1][0]);
              
              // Rest of strategy logic
              }
              }
              I've also attached a screenshot of Historical Data Manager. The 1 tick Data Series seems to be correct.... but why is the Range bar close so far off?
              Attached Files

              Comment


                #8
                Shane, thanks for the reply. The different bars update calls would not be multi-threaded, so if you have complex calcuation logic I would suggest commenting / simplyfing the scripts contents out until you would get the prints reported you would expect. Also could the 8:30 time you cited be potentially a news event unfolding? Are you reporting this in EST?

                Comment


                  #9
                  Hi Bertrand.

                  Yes, the time is EST.

                  News was an idea I had, but looking at the Historical Data Manager screenshot in my first post, the trades are not that bad compared with other days that I have seen.

                  If the data series is not multi-threaded, I can't understand what would cause the discrepancy. Even if the calculation logic is complex, the next OnBarUpdate shouldn't get called until after the initial one is complete. However I will comment out some of the code to try and track it down.

                  Comment


                    #10
                    As long as you're strictly using supported NS code, it should not be mulit-threaded, however if you're developing custom classes/methods, it's possible you have some multi-threading concepts implemented which could throw off the calculation logic.

                    Please let us know what you find.
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      Hi Matthew. Thanks for the reply.

                      Actually, I went back and realized I was looking at the wrong DateTime in my bare-bones strategy. The issue exists in both Strategies so the Strategy isn't the cause. Any other ideas what may cause this discrepancy?

                      Code for the bare bones strategy is in post #6.

                      A screenshot of the output window is attached.
                      Attached Files

                      Comment


                        #12
                        Reviewing your HDM screen shot, there was a wide range of trades that occurred at the 8:30:06

                        It's not possible for us to know in what order those ticks came in as there is no sub-second time stamping at this time. At this time under this framework, you're looking at a range of prices occurring within the same second and the order is going to be lost.

                        The next major release of NinjaTrader will include the timestamps of a much higher granularity and will help keep these ticks in order.
                        MatthewNinjaTrader Product Management

                        Comment


                          #13
                          Ok. I guess I thought it would build it by going through the Historical Data Manager sequentially as it is listed, but perhaps that isn't the case.

                          Thank you so much for your time in this matter. Am looking forward to the next version!

                          Shane

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          663 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          376 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          110 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          575 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          580 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X