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

10 minute Rolling Volume

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

    10 minute Rolling Volume

    I would like to code and indicator that calculates the last 10 minute Avg. Volume at close of bar, using UniRenko Bars. So it would be a Rolling 10 minute average (Using Calculate.OnIncomingTick). Can anybody lead me in the right direction with code, without using a MTF indicator.

    Any guidance would be helpful. Thanks.

    #2
    Hello woodyfox,

    Thanks for your post.

    As you are using non time based bars your concept literally would be hit or miss regarding a 10 minute moving average without using another data series.

    One approach would be to get the current bars close time and compare that to previous bars until you are equal (not likely) to 10 minutes or just over (most likely). Then using those bars between the current and the +10 minutes ago find the average volume over the number of bars between the current bar and the +10 minute ago bar. The issue here is if you have a bar that is like 9 minute and 30 seconds ago you would then use the next bar back but if that bar has a duration of 6 minutes, for example, your averaging would then be of a 15+ minute period. If you are using a large reversal bar setting the times could be even more skewed.

    We can also keep this thread open for any forum members who would like to contribute other ideas or approaches.

    To be clear, In the support department at NinjaTrader we do not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients.

    If you would like this coded for you, we can provide reference links to 3rd party coders who can provide coding services.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      So the MTF approach would be more accurate?

      Something like this...

      else if (State == State.Configure)
      {
      AddDataSeries(Data.BarsPeriodType.Minute, 1);
      }
      protected override void OnBarUpdate()
      {

      if (CurrentBars[0] < BarsRequiredToPlot)
      return;

      EV[0]= ((VOLMA(BarsArray[1], 10)[0])*10);
      }

      Thanks, Woody.

      Comment


        #4
        Hello woodyfox,

        Thanks for your reply.

        That would be an easier and more consistent way of getting 10 minute data.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Paul, Thanks for your advice!

          Comment


            #6
            Paul,
            Is it possible to use the BarsArray in Bars.GetVolume(barIndex);

            This doesn't seem to work?

            else if (State == State.Configure)
            {
            AddDataSeries(Data.BarsPeriodType.Minute, 10);
            }

            protected override void OnBarUpdate()
            {
            if (CurrentBars[0] < 0)
            return;

            EVA[0]= Bars.GetVolume(BarsArray[1],144);
            }
            Thanks, Woody.

            Comment


              #7
              Paul,

              This doesn't seem to work either?

              else if (State == State.Configure)
              {
              AddDataSeries(Data.BarsPeriodType.Minute, 10);
              }

              protected override void OnBarUpdate()
              {
              if (CurrentBars[0] < 0)
              return;

              if (BarsInProgress == 1)
              {
              EVA[0]= Bars.GetVolume(144);
              }
              }
              Thanks, Woody.

              Comment


                #8
                Hello woodyfox,

                Thanks for your replies.

                Bars.GetVolume() would only provide the volume from the chart bars and not from the added dataseries.

                In addition, you are not checking for an appropriate number of bars to have been processed before checking for the 144th bar of the added data series.

                I'm not certain what you are trying to do in your last two posts but you may want to use the VOL() volume indicator set to the added data series. If you need the volume of a specific 10-minute bar, you can calculate the bars ago value or use VOL()[0] for the current 10 minute bar volume. reference: https://ninjatrader.com/support/help...us/?volume.htm
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Paul View Post
                  Hello woodyfox,

                  Thanks for your replies.

                  Bars.GetVolume() would only provide the volume from the chart bars and not from the added dataseries.

                  In addition, you are not checking for an appropriate number of bars to have been processed before checking for the 144th bar of the added data series.

                  I'm not certain what you are trying to do in your last two posts but you may want to use the VOL() volume indicator set to the added data series. If you need the volume of a specific 10-minute bar, you can calculate the bars ago value or use VOL()[0] for the current 10 minute bar volume. reference: https://ninjatrader.com/support/help...us/?volume.htm
                  Ok, Thanks. I will use the VOL()[0] for the current 10 minute bar volume, but how check the appropriate number of bars to have been processed before checking for the 144th bar of the added data series.
                  if (CurrentBars[0] < ?) Not Sure?
                  Thanks in advance, Woody.

                  Comment


                    #10
                    Hello woodyfox,

                    Thanks for your reply.

                    The conditional statement: if (CurrentBars[0] < 0) is checking to see if the chart bars (BarsArray[0]) are less than zero. In your previous posts, you wanted to check the 144th bar of the added data series. The added data series is BarsArray[1], so you would need to ensure that CurrentBars[1] is at least at bar 143. However, if you are only checking the current bar Volume then you would not need to check for 143 bars but would need to check for at least 1 bar.

                    Reference: https://ninjatrader.com/support/help...urrentbars.htm
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Paul View Post
                      Hello woodyfox,

                      Thanks for your reply.

                      The conditional statement: if (CurrentBars[0] < 0) is checking to see if the chart bars (BarsArray[0]) are less than zero. In your previous posts, you wanted to check the 144th bar of the added data series. The added data series is BarsArray[1], so you would need to ensure that CurrentBars[1] is at least at bar 143. However, if you are only checking the current bar Volume then you would not need to check for 143 bars but would need to check for at least 1 bar.

                      Reference: https://ninjatrader.com/support/help...urrentbars.htm
                      What I'm trying to accomplish is finding the average 10 minute volume of the last few days at each 10 minute bar and then plot on a unirenko chart.

                      Since there are 144 10 minute bars in a day.
                      I tried...

                      AddPlot(new Stroke(Brushes.Blue, 1), PlotStyle.Line, "EVA");
                      }
                      else if (State == State.Configure)
                      {
                      AddDataSeries(Data.BarsPeriodType.Minute, 10);
                      }
                      }

                      protected override void OnBarUpdate()
                      {
                      if (CurrentBars[1] > 1)
                      return;

                      if (BarsInProgress == 1)
                      {
                      EVA[0]= (VOL()[144] + VOL()[288])/2;
                      }
                      }
                      Any suggestions would be helpful? Thanks, Woody.

                      Comment


                        #12
                        Hello woodyfox,

                        Thanks for your reply.

                        Thanks for clarifying the ultimate goal here.

                        What I would suggest is using a simple moving average (SMA) of the Volume of the 10 minute bars. You can specify the average period you wish to use.

                        I've created an example and added it as a picture for your review. Please note that as you are plotting, you need to plot on BarsInProgress =0 and In the VOL() indicator I am pointing to BarsArray[1] (the 10 minute bars). I am using a 10 period SMA of the volume and this is why I am doing a CurrentBars[1] check against < 10 bars.
                        Attached Files
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Paul View Post
                          Hello woodyfox,

                          Thanks for your reply.

                          Thanks for clarifying the ultimate goal here.

                          What I would suggest is using a simple moving average (SMA) of the Volume of the 10 minute bars. You can specify the average period you wish to use.

                          I've created an example and added it as a picture for your review. Please note that as you are plotting, you need to plot on BarsInProgress =0 and In the VOL() indicator I am pointing to BarsArray[1] (the 10 minute bars). I am using a 10 period SMA of the volume and this is why I am doing a CurrentBars[1] check against < 10 bars.
                          Thanks Paul, Let me clarify. I have already accomplished the rolling average for the ten minute bars. I broke this down here by the second to smooth it....
                          else if (State == State.Configure)
                          {
                          AddDataSeries(Data.BarsPeriodType.Second, 1);
                          }
                          }

                          protected override void OnRender(ChartControl chartControl, ChartScale
                          chartScale)
                          {
                          base.OnRender(chartControl, chartScale);

                          foreach (Plot plot in Plots)
                          {
                          // make the plots width match the chart style bar width
                          plot.Width = (float) 1.25*(chartControl.GetBarPaintWidth(ChartBars));
                          }
                          }

                          protected override void OnBarUpdate()
                          {
                          ///if (State==State.Historical) { return;}
                          if (CurrentBars[0] < BarsRequiredToPlot)
                          return;

                          EV[0]= ((VOLMA(BarsArray[1], 600)[0])*600);

                          Now what I'm trying to accomplish is getting the average for the past n days for each certain ten minute plot. So 12:00 to 12:10 today, 12:00 to 12:10 yesterday, etc....

                          AddPlot(new Stroke(Brushes.Blue, 1), PlotStyle.Line, "EVA");
                          }
                          else if (State == State.Configure)
                          {
                          AddDataSeries(Data.BarsPeriodType.Minute, 10);
                          }
                          }

                          protected override void OnBarUpdate()
                          {
                          ///if (State==State.Historical) { return;}
                          if (CurrentBars[1] > 1)
                          return;

                          if (BarsInProgress == 1)
                          {
                          EVA[0]= (VOL()[144] + VOL()[288])/2;
                          }
                          }
                          I could then plot the two values on the chart. This would help me see if the rolling 10 minute volume is exceeding expectations at that certain 10 minute period.
                          Any suggestions, Thanks, Woody.

                          Comment


                            #14
                            Hello woodyfox,

                            Thanks for your reply.

                            You might look at GetBar() where you specify the time and it returns the absolute bar number which you can then calculate the bars ago by subtracting the absolute bar number returned by GetBar() from the CurrentBar (as the example in the helpguide shows).

                            Reference: https://ninjatrader.com/support/help...us/?getbar.htm
                            Paul H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by techgetgame, Yesterday, 11:42 PM
                            0 responses
                            8 views
                            0 likes
                            Last Post techgetgame  
                            Started by sephichapdson, Yesterday, 11:36 PM
                            0 responses
                            2 views
                            0 likes
                            Last Post sephichapdson  
                            Started by bortz, 11-06-2023, 08:04 AM
                            47 responses
                            1,613 views
                            0 likes
                            Last Post aligator  
                            Started by jaybedreamin, Yesterday, 05:56 PM
                            0 responses
                            10 views
                            0 likes
                            Last Post jaybedreamin  
                            Started by DJ888, 04-16-2024, 06:09 PM
                            6 responses
                            20 views
                            0 likes
                            Last Post DJ888
                            by DJ888
                             
                            Working...
                            X