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

Mismatch Between Volume Bars and Volume Based on Tick Bars

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

    Mismatch Between Volume Bars and Volume Based on Tick Bars

    Hi,

    I have run into a somewhat unusual situation, and would appreciate some insight and understanding. Thank you.

    The situation is as follows:
    1. I create a volume chart, 10V chart. This is my primary bar chart.
    2. I create a 1 tick chart.
    3. At every first tick of the primary bar series I begin to add up the volume from the 1 tick chart.

    So I expected the bar volume total based off of the 1 tick chart to add up to 10 for every primary series bar but the actual volume sum based on the 1 tick chart varies-sometimes its 8, sometimes 10 and sometimes it is 9.

    This is strange behaviour and likely an error on my part. (I am working on a multiseries indicator.) I am, however, not sure what I am missing here. Any suggestions would be greatly appreciated. Thank you.

    #2
    Hello Zeos6,

    Thank you for your post.

    Are you making the comparison through a custom script?

    Are you setting any specific Bars To Load for the secondary series (1 Tick)?

    I look forward to your response.

    Comment


      #3
      Hi PatrickH,

      Yes, the comparison is being made via a custom script.

      I am not sure what you mean by your second question, however, in
      State == State.Configure I use

      Code:
      // Add a 1 tick bar series of the primary instrument
      AddDataSeries(BarsPeriodType.Tick, 1);
      I wonder if this issue is related in any way to the 1 bar lag due to the way secondary bar series are processed (i.e. after the primary bar series) in NT.

      Comment


        #4
        Originally posted by Zeos6 View Post
        I wonder if this issue is related in any way to the 1 bar lag due to the way secondary bar series are processed (i.e. after the primary bar series) in NT.
        Hello Zeos6,

        Thank you for your response.

        This could be the case. Can you provide the full code in OnBarUpdate() used for the Print()s to the Output window?

        I look forward to your response.

        Comment


          #5
          Hi PatrickH

          Still trying to decipher this. The code is below:

          Code:
          protected override void OnBarUpdate()
          {
               if (CurrentBars[0] < 0 || CurrentBars[1] < 0)
                   return;
               if (CurrentBars[0] > 4) return;
               Print("------------------------------");
               Print("Primary Time = "+Times[0][0]);
               Print("CurrentBars[0] = "+CurrentBars[0]);
          
               // Check if OnBarUpdate() is called from an update on the primary instrument data
               if (BarsInProgress == 0)
               {
                   if (sessionIterator.IsNewSession(DateTime.Now, true) && Bars.IsFirstBarOfSession && IsFirstTickOfBar)
                       this.lastPrice    = 0.0;
                   else if (IsFirstTickOfBar)
                   {
                       Print("===================================");
                       this.tickVolume    = 0.0;
                       this.upTicks    = 0.0;
                       this.downTicks    = 0.0;
                       this.ticks        = 0.0;
                       this.upVolume    = 0.0;
                       this.downVolume    = 0.0;
                       this.barVolume    = 0.0;
                   }
          
                   Print("--- Primary Bars Series ---");
                   Print("upTicks = "+upTicks);
                   Print("downTicks = "+downTicks);
                   Print("ticks = "+ticks);
                   Print("upVolume = "+upVolume);
                   Print("downVolume = "+downVolume);
                   Print("barVolume = "+barVolume);
               }
                      
               if (BarsInProgress == 1)
               {
                   Print("--- 1 Tick Bars Series ---");
                   Print("1 Tick Time = "+Times[1][0]);
                   Print("CurrentBars[1] = "+CurrentBars[1]);
                   Print("Closes[1][0] = "+Closes[1][0]);
                   Print("Volumes[1][0] = "+Volumes[1][0]);
                   Print("this.lastPrice = "+this.lastPrice);
                   this.tickVolume = Volumes[1][0];
          
                          if (this.lastPrice > 0.0)
                              UpdateTickInformation(Closes[1][0], Volumes[1][0]);
                          
                          this.lastPrice = Closes[1][0];
                          this.ticks++;
                          this.barVolume += this.tickVolume;
          
                          Print("upTicks = "+upTicks);
                          Print("downTicks = "+downTicks);
                          Print("ticks = "+ticks);
                          Print("upVolume = "+upVolume);
                          Print("downVolume = "+downVolume);
                          Print("barVolume = "+barVolume);
               }
          }
          Last edited by Zeos6; 07-12-2017, 06:54 PM.

          Comment


            #6
            Hi PatrickH,

            So I have been digging a bit more into this issue and things are getting really weird. I have put up a 10V chart, a 1 tick chart and a 1V chart for the custom date range July 5 to July 12 using 24/7 trading hours.

            I have used up triangles to show the first six bars from the 10V chart on the 1 tick and the 1V chart.

            If you look at the 1V chart the first bar shows a vol of 9, bar 2 a volume of 10, bar 3 a volume of 10, bar 4 a volume of 8, and bar 5 a volume of 13. I expected all volume values to be 10.

            Incidentally, these volumes match the volumes calculated from the 1 tick chart.

            Now what in the world is happening here? Any insight would be greatly appreciated. I have attached a pic.

            Attached Files

            Comment


              #7
              Hello Zeos6,

              Thank you for your patience.

              Can you send me the full indicator code at platformsupport[at]ninjatrader[dot]com with 'ATTN: Patrick H' in the subject line and a reference to this thread in the body of the email?

              You can export your indicator by going to Tools > Export > NinjaScript Add On > Add > select your indicator > OK > Export > name the file 'NTsupport' > Save.

              The file will be located under Documents\NinjaTrader 8\bin\Custom\ExportNinjaScript. Please attach the file to your response.

              I look forward to your response.

              Comment


                #8
                Will do Patrick. Thank you.

                Comment


                  #9
                  Hello Zeos6,

                  Thank you for your patience.

                  The Ticks can come in with varying volume. This volume can exceed the 10 Volume bar type you are using or be well under the 10 Volume.

                  There is no guarantee that you would get the volume needed from the 1 Tick bars before the 10 Volume bar closed. It may exceed the Volume or the closing tick for the 10 Volume would the next tick of the 1 Tick bar series.

                  Essentially there is no means to ensure that the 1 Tick series will always match the 10 Volume bar chart on the close of the 10 Volume (or any interval) bar.

                  Please let me know if you have any questions.

                  Comment


                    #10
                    Hello,
                    I have found the same problem for example in bars of 30 seconds and 1 tick. (There is no problem of matching ticks and volume bars here, since it is a temporary timeframe).

                    Sometimes the cumulative volume of the 1-tick bars coincides with the bar volume of 30 seconds, and sometimes not.

                    If two or more DataSeries coincide in the same time to close their currentbar, which one executes your OnBarUpdate before ?. Is there a guaranteed order? (Eg first primary timeframe, then secondary, then tertiary, etc.).

                    (I am forced to work with Calculate = OnBarClose.)

                    Attach the code and a snapshot (FDAX 09-17 30-sec). With historical works fine, the issue is only in real time.

                    Thanks in advance
                    Attached Files

                    Comment


                      #11
                      Hello cls71,

                      Thank you for your response.

                      The Primary Bar should process first for the timestamp that matches the Secondary Bar. I would recommend printing out the Times[0][0] and Times[1][0] to see why this is occurring.

                      Please let me know if you have any questions.

                      Comment


                        #12
                        Thanks Patrick,

                        But then, why does this happen ? (The secondary timeframe 30-sec is run before than primary timeframe 1-tick). Attach ninjascript.




                        In addition, in historical bars the behavior is different.




                        Thanks
                        Attached Files
                        Last edited by cls71; 08-01-2017, 12:34 AM. Reason: The comment into "historical" image had a wrong text (I have changed the time from 17:58:00.0 to 15:37:30.0)

                        Comment


                          #13
                          Hello cls71,

                          Thank you for your patience.

                          My colleague is following up with you on this on the following thread: http://ninjatrader.com/support/forum...85&postcount=3

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by MarianApalaghiei, Today, 10:49 PM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by love2code2trade, Yesterday, 01:45 PM
                          4 responses
                          28 views
                          0 likes
                          Last Post love2code2trade  
                          Started by funk10101, Today, 09:43 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post funk10101  
                          Started by pkefal, 04-11-2024, 07:39 AM
                          11 responses
                          37 views
                          0 likes
                          Last Post jeronymite  
                          Started by bill2023, Yesterday, 08:51 AM
                          8 responses
                          46 views
                          0 likes
                          Last Post bill2023  
                          Working...
                          X