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

Want to plot Cumulative Volume

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

    Want to plot Cumulative Volume

    Hello, How can I plot cumulative volume for day and at the start of each day , It calculates from 0.

    also If I can add an option of not resetting on new day.

    Thank you

    #2
    what do you call cumulative volume? session open or market open?
    WHere do you want to plot, on th chart or on a panel

    Comment


      #3
      Originally posted by ballboy11 View Post
      what do you call cumulative volume? Is session open or market open?
      WHere do you want to plot, on the chart or on a panel
      from market open - I found this from past posts,

      OnBarUpdate()

      if (currentbar < 1 )
      return;

      if(time[0].date != time[1].date)
      {
      volume = volume[0]
      }
      else
      {
      volume += volume[0];
      value.set(volume);
      }



      But this doesn't reset on a new day. plus I want to change scale into Millions Right now it shows into 2000k, 4000k like that want to turn into 20M, 40M easy for eyes. (Optional)

      just want to plot on the new panel.

      Comment


        #4
        Hello svadukia,

        Thanks for your posts.

        To reset on a new trading session, you would use Bars.IsFirstBarOfSession as the trigger to reset your accumulator.
        Reference: https://ninjatrader.com/support/help...rofsession.htm
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello svadukia,

          Thanks for your posts.

          To reset on a new trading session, you would use Bars.IsFirstBarOfSession as the trigger to reset your accumulator.
          Reference: https://ninjatrader.com/support/help...rofsession.htm
          Okay will do that and what can I do to change scale ??

          Comment


            #6
            protected override void OnBarUpdate()
            {
            if(CurrentBar < 1)
            {
            return;
            }

            if(Bars.IsFirstBarOfSession)
            {
            accum = 0;
            }

            if(Time[0].Date != Time[1].Date)
            {
            accum =Volume[0];
            }
            else
            {
            accum += Volume[0];
            Value[0] = accum;
            }
            }

            Did this but getting error that cannot apply indexing with[] to an expression of type " Method Group".

            Comment


              #7
              Hello svadukia,

              Thanks for your reply.

              Assuming you have declared accum as a double, your code should compile and execute. Are you certain the error message relates to the code you are working on?

              Please note that you are resetting the accumulate to zero on the first bar of the session and then later when the day changes you are resetting the accumulate again but to the current value of Volume on that bar.

              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_PaulH View Post
                Hello svadukia,

                Thanks for your reply.

                Assuming you have declared accum as a double, your code should compile and execute. Are you certain the error message relates to the code you are working on?

                Please note that you are resetting the accumulate to zero on the first bar of the session and then later when the day changes you are resetting the accumulate again but to the current value of Volume on that bar.
                yes I have declared it as a Double.

                Then Should I delete that day changes condition ??

                Yes error is in the code Line -- accum += Volume[0];

                thank you

                Comment


                  #9
                  Originally posted by NinjaTrader_PaulH View Post
                  Hello svadukia,

                  Thanks for your reply.

                  Assuming you have declared accum as a double, your code should compile and execute. Are you certain the error message relates to the code you are working on?

                  Please note that you are resetting the accumulate to zero on the first bar of the session and then later when the day changes you are resetting the accumulate again but to the current value of Volume on that bar.
                  Error is gone. It was from different indicator.

                  Now but I am getting volume value from few minutes after opening of market. Our market opens at 9:15 but it plots around 9:22.

                  if(Bars.IsFirstBarOfSession)
                  {
                  accum = 0; // changed to accum = Volume[0];
                  }


                  ------------------------------Current code------------------------------------

                  if(CurrentBar < 1)
                  {
                  return;
                  }

                  if(Bars.IsFirstBarOfSession)
                  {
                  accum = Volume[0];
                  }
                  else
                  {
                  accum += Volume[0];
                  Value[0] = accum;
                  }

                  Comment


                    #10
                    Hello svadukia,

                    Thanks for your replies.

                    I think your accum = Volume[0]; is a better approach!

                    Are you using Calculate.OnEachBar or Calculate.OnEachTick?
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_PaulH View Post
                      Hello svadukia,

                      Thanks for your replies.

                      I think your accum = Volume[0]; is a better approach!

                      Are you using Calculate.OnEachBar or Calculate.OnEachTick?
                      I am using OnEachTick


                      --------------Here is the full code -----------------------

                      public class cumuvol : Indicator
                      {
                      private double accum;

                      protected override void OnStateChange()
                      {
                      if (State == State.SetDefaults)
                      {
                      Description = @"Enter the description for your new custom Indicator here.";
                      Name = "cumuvol";
                      Calculate = Calculate.OnEachTick;
                      IsOverlay = false;
                      DisplayInDataBox = true;
                      DrawOnPricePanel = true;
                      DrawHorizontalGridLines = true;
                      DrawVerticalGridLines = true;
                      PaintPriceMarkers = true;
                      ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                      //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                      //See Help Guide for additional information.
                      IsSuspendedWhileInactive = true;
                      AddPlot(Brushes.Goldenrod, "MyPlot");
                      }
                      else if (State == State.Configure)
                      {
                      }
                      }

                      protected override void OnBarUpdate()
                      {
                      if(CurrentBar < 1)
                      {
                      return;
                      }

                      if(Bars.IsFirstBarOfSession)
                      {
                      accum = Volume[0];
                      }
                      else
                      {
                      accum += Volume[0];
                      Value[0] = accum;
                      }
                      }
                      }


                      Comment


                        #12
                        Hello svadukia,

                        Thanks for your reply.

                        I'm not sure why your plot would start after the start time. I recommend debugging using print statements to see what is happening there. Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm

                        Using Calculate.OnEachTick will present additional considerations for your code. For example, when using real-time data, this line: accum += Volume[0]; will incorrectly accumulate the volume because it is adding the accumulated volume of the bar, on each tick to the accumulated total of the previous bars. You would need to implement logic to obtain the volume differences of the bar from one tick to the next and then accumulate that difference to your total.
                        Paul H.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by mattbsea, Today, 05:44 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post mattbsea  
                        Started by RideMe, 04-07-2024, 04:54 PM
                        6 responses
                        31 views
                        0 likes
                        Last Post RideMe
                        by RideMe
                         
                        Started by tkaboris, Today, 05:13 PM
                        0 responses
                        2 views
                        0 likes
                        Last Post tkaboris  
                        Started by GussJ, 03-04-2020, 03:11 PM
                        16 responses
                        3,282 views
                        0 likes
                        Last Post Leafcutter  
                        Started by WHICKED, Today, 12:45 PM
                        2 responses
                        20 views
                        0 likes
                        Last Post WHICKED
                        by WHICKED
                         
                        Working...
                        X