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

Multi-time frame volume

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

    Multi-time frame volume

    As an exercise I am writing an indicator that will construct volume on a 5 minute chart from a second series of 1 minute bars.

    I have
    Code:
    CalculateOnBarClose = false;
    I'm not quite grasping why this (which does not give a correct result):
    Code:
    LTFvolume.Set(SUM(Volumes[1],5)[0])
    differs from this (which does match the 5 minute parent volume):
    Code:
    if (Times[1][0] == Times[0][0])
    LTFvolume.Set(SUM(Volumes[1],5)[0])
    at least on historical data, haven't checked it live.

    Maybe there's a simpler or better approach logically than using SUM. I would eventually like to apply this to display the volume from one instrument on a different instrument's chart and not necessarily using time frames that are easily divisible as in my example.

    #2
    Hello DrMartell,

    Thank you for your post.

    This will have to do with how the bar data is referenced with both historical and live.
    Take a look at the link below on Multi-Timeframes and Instruments at the section for How Bar Data is Referenced
    http://www.ninjatrader.com/support/h...nstruments.htm

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

    Comment


      #3
      Thank you,

      Just to clarify, with respect to historical data processing, Would it be accurate to say that Figure 1. on the link you provided would also apply if CalculateOnBarClose == false?

      In other words the CalculateOnBarClose property has no effect on the processing of historical data whether multi-time frame or not because it always is treated as if true?

      Comment


        #4
        Drmartell,

        Correct, historical data is always treated with CalculateOnBarClose set to true. This is because only the OHLCV data is known for that bar and no intrabar data.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          OK, so I am working on just getting this right with historical data.

          For some reason the code gives the correct results if I add a 1 minute dataseries (to a 5 minute chart of ES 09-14). However if I change the 1 minute dataseries to a 30 second dataseries, it no longer matches the 5 minute parent volume.

          Code:
          private double constructedVolume = 0;
          private DateTime timeCrossed;
          private int cumulateFrom;
          private int barsInBar = 1;
          private int cumulativeVol = 0;
          		
                  protected override void Initialize()
                  {
          			Add(PeriodType.Minute, 1);
          			//Add(PeriodType.Second,30);
          			Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Bar, "LTFvolume"));
          			Overlay			= false;
          			CalculateOnBarClose = false;
                  }
          
                  protected override void OnBarUpdate()
                  {
          			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
          				return;
          			
          			if (Historical)
          			{
          				if (Times[0][1] != timeCrossed && Times[1][0] > Times[0][1])
          				{
          					LTFvolume.Set(SUM(Volumes[1],barsInBar)[0]);
          					timeCrossed = Times[0][1];
          					constructedVolume = Volumes[1][0];
          					cumulateFrom = CurrentBars[1];
          				}
          				else
          				{
          					barsInBar = CurrentBars[1] - cumulateFrom + 1;
          					constructedVolume = SUM(Volumes[1],barsInBar)[0];
          				}	
          			}
                  }

          Comment


            #6
            Hello drmartell,

            I wanted to demonstrate a straight forward test as the code you have may be doing multiple things. Also the Time[1][0] == Time[0][1] is a bit confusing to me.

            I have created an indicator that accumulates volume on the 30 second series and then prints and resets when the bar time of the 30 second series matches the minute series.

            This indicator prints to the output window. What I am finding is that with any minute interval the cumulated volume and minute bar volume are matching.

            Because you are using the SUM indicator method, I have added this as well using a bar count to show this also returns the same.

            Do you find this also returns the same for you?
            Attached Files
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks for doing this ChelseaB,

              I don't seem to be having as much luck as you with the code provided.

              I ran it on my ES 09-14 chart, with a 24 hour session, times are in MST.

              Most of the outputs match as intended, but many of them don't. Consider this series which is among the first few prints I see:

              6/16/2014 10:40:00 PM -- Cumulated 30 second volume: 300 - 5 Minute volume: 300
              6/16/2014 10:40:00 PM -- SUM volume with volume of 30 second series using barcounter: 300

              6/16/2014 11:00:00 PM -- Cumulated 30 second volume: 339 - 5 Minute volume: 246
              6/16/2014 11:00:00 PM -- SUM volume with volume of 30 second series using barcounter: 339

              6/16/2014 11:05:00 PM -- Cumulated 30 second volume: 492 - 5 Minute volume: 492
              6/16/2014 11:05:00 PM -- SUM volume with volume of 30 second series using barcounter: 492

              6/16/2014 11:10:00 PM -- Cumulated 30 second volume: 488 - 5 Minute volume: 488
              6/16/2014 11:10:00 PM -- SUM volume with volume of 30 second series using barcounter: 488

              6/16/2014 11:25:00 PM -- Cumulated 30 second volume: 549 - 5 Minute volume: 128
              6/16/2014 11:25:00 PM -- SUM volume with volume of 30 second series using barcounter: 549
              As you can see, in 2 out of the 5, all 3 numbers fail to match.

              Comment


                #8
                Hi drmartell,

                Looks like we were running into an order of operations issue.

                The minute bars were resetting the volume before the volume of that 30 second bar could be added in.

                To correct this, I have added the 30 second series as bip 1, a 1 minute series as bip 2, and a 5 minute series as bip 3.

                The series chosen on the chart will not be used.

                This does appear to correct the issue.
                Attached Files
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Chelsea, I agree this seems to have corrected the issue within the Output window.

                  For some reason I'm having trouble translating this to the original intention, which is to display 5 minute volume constructed from one minute volume on a 5 minute chart. I've tried to simply take the code you sent and add a plot of cumulatedVolume and that doesn't seems to work.

                  It ends up looking like this (blue is native VOL and orange is cumulated):

                  Comment


                    #10
                    Hi drmartell,

                    This does work for me on a 5 minute chart.

                    The cumulation is the same, but i've commented out the prints. Now it plots the values.
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok, I'm not sure what I was doing wrong, but what you posted seems like it is doing what I was aiming for. Thank you and hopefully it is helpful to others.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by funk10101, Today, 12:02 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_LuisH  
                      Started by GLFX005, Today, 03:23 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Erick  
                      Started by nandhumca, Yesterday, 03:41 PM
                      1 response
                      12 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by The_Sec, Yesterday, 03:37 PM
                      1 response
                      11 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by vecnopus, Today, 06:15 AM
                      0 responses
                      1 view
                      0 likes
                      Last Post vecnopus  
                      Working...
                      X