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

% Change in Average Volume

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

    % Change in Average Volume

    I am trying to create an indicator which will plot the % difference in 30 day average volume... I created an Vol SMA and then created this code

    double myValue = (Volume[0] - VSMA(30)[0]) / (VSMA(30)[0]) * (100);

    Plot0.Set(myValue);

    It plots but I am not getting the correct values...

    Basically I want the days current volume to be compared to the 30 day average of volume in a % form so that if the 30 day average is 1 million and today it is trading on 2 million the indicator reads +100. I need this for a market analyzer scan.

    perhaps instead of calling the Vol SMA I need to script it all in the same script? Not sure, very new at coding...

    If anyone can help I really would appreciate it or if this code is out there already I really need it... Part of me thinks my problems may be coming from "OnBarUpdate"

    Thanks for any help!
    R.T.

    #2
    Hello RT,

    Most likely you need to change the parentheses so calculations are made in desired order. You're multiplying 30 day average by 100 before doing the ratio calculation. You can also create this from only one line:

    Plot0.Set(((Volume[0] - SMA(Volume, 30)[0]) / SMA(Volume, 30)[0]) * 100);
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks Ryan,

      Looks better, I am still not getting the correct numbers though... I think I need the indicator to use the Volume SMA from the prior day, not including todays volume into the SMA...

      I try to change the SMA to (30)[1] but then it does not plot at all....

      Thanks for any help!

      Comment


        #4
        Yes, using the 1 index should work to match the code with your description.

        Plot0.Set(((Volume[0] - SMA(Volume, 30)[1]) / SMA(Volume, 30)[1]) * 100);

        If it's not plotting anything after this change, then you're likely running into this issue here.

        To verify, check log tab of control center for index out of range error messages.

        You can resolve by adding current bar check.

        if (CurrentBar < 1)
        return;
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks for all the help Ryan, i pretty much got it....

          Is there a way to separate the volume from the timeframe? In other words for the 30 minute chart I want the total volume on the day to be able and be compared to say the VolSMA on the 30 timeframe instead of the volume starting over on each 30 minute bar.

          Thanks again,
          R.T.

          Comment


            #6
            Yes, you can work with multiple series. There's a sample available by clicking tools > Edit NinjaScript > Strategy > SampleMultiTimeFrame. Documentation is available here:

            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              ahh, okay thanks, so I want to define the daily time period for the volume then and that will override any timeframe I set the indicator into for volume? this will work in market analyzer?

              Comment


                #8
                Yes, you add a secondary time frame, and can then make calculations by referencing this time frame in your indicator calculations. Yes, this works in market analyzer as well.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Ryan,

                  Got close I think but can't get it to compile... if you see a simple fix please let me know...

                  protected override void Initialize()
                  {
                  Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                  Overlay = false;
                  Add(PeriodType.Day, 1);
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>

                  protected override void OnBarUpdate()
                  {
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  if (CurrentBar < 1)
                  return;

                  Plot0.Set(((Volume(BarsArray[1])[0]) - SMA(Volume, 390)[0]) / SMA(Volume, 390)[0]) * 100);

                  Thanks!

                  Comment


                    #10
                    You need to work with Volumes to get the volume for a secondary series.

                    Example:
                    Plot0.Set(((Volumes[1][0] - SMA(Volumes[1], 30)[1]) / SMA(Volumes[1], 30)[1]) * 100);

                    This example uses the secondary series volume for all calculations. You may need to change it to fit the calculations you're going for compared to the primary series.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Okay, awesome... Got it! Thanks!

                      Can you point me in the right direction for how to divide up the bars of regular trading hours and add to them? Such as how to call each of the thirteen 30 bars?

                      Thanks again!

                      Comment


                        #12
                        I'm not sure exactly what you're looking for. You might find these properties and methods useful:

                        You can use Sum() to add a series value over the specified lookback period.

                        BarsSinceSession gives you the total number of bars that have elapsed since start of a session.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          ha, i'm not sure anymore either

                          Basically I am looking to split the day into 13 30 minute bars and be able to continue and add volume to it for a grand total at the end... for on "on pace volume" filter... so I need to be able to say something like

                          If bar 9:00 to 9:30 Volume > 100000
                          If bar 9:30 to 10:00 volume > 200000
                          and so on

                          Thanks for any help again, I appreciate it as I have been trying to get this MA scan set for a few months...

                          Comment


                            #14
                            Something like this should work for summing the volume per session:
                            double sessionVolume = SUM(Volume, Bars.BarsSinceSession + 1)[0];
                            Last edited by NinjaTrader_RyanM1; 12-28-2010, 03:49 PM.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Hey Ryan,

                              Thanks for all the help! What do you think the best (really easiest) method for creating on on going volume requirement filter in market analyzer would be?

                              Thanks again

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, 04-19-2024, 09:40 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post alifarahani  
                              Started by mmckinnm, Today, 01:34 PM
                              2 responses
                              4 views
                              0 likes
                              Last Post mmckinnm  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              3 responses
                              60 views
                              0 likes
                              Last Post NinjaTrader_SeanH  
                              Started by f.saeidi, Today, 01:32 PM
                              1 response
                              2 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by traderqz, Today, 12:06 AM
                              9 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X