Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can have Volume[0]+Volume[1] indicator for each TICK?

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

    Can have Volume[0]+Volume[1] indicator for each TICK?

    Hi, I`d like to modify VOL indicator. I want it to show:

    PHP Code:
    Value.Set(Volume[0] + Volume[1]); 
    
    instead of just:

    PHP Code:
    Value.Set(Volume[0]); 
    
    for EACH tick.

    Is it possible?

    How?

    Thank you very much for your help.

    #2
    Hello,

    Please go to the Control Center>Tools>Edit NinjaScript>Indicator and select the Vol indicator. Right click on the indicator code> Save As and name it VolCustom or whatever you’d like.

    Under protected override void OnBarUpdate() replace,

    Value.Set(Volume[0]);

    With,

    if (CurrentBar < 1 ) return ;
    Value.Set(Volume[0] + Volume[1]);

    This indicator is now available for use.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you very much AlanP, your response makes me wonder two other issues:

      1.- Why "if (CurrentBar < 1 ) return ;"? Why can't you just code "Value.Set(Volume[0] + Volume[1]);"?

      2.- If I add other condition, e.g.:
      if (Close[0] == Close[1]) return ;
      Value.Set(Volume[0] + Volume[1]);
      ¿Why doesn't work?

      Thank you

      Comment


        #4
        Hello,

        The statement (CurrentBar < 1 ) return; checks to make sure there is at least 1 bar of data before continuing. Because bars process from left to right, if there is no prior bar data, you'll get an error.

        CurrentBar section of our helpguide:



        The statement requiring Close[0] be equal to close[1], lacks the CurrentBar greater than 1 setting/check.

        You should write it as,

        if (CurrentBar < 1 || Close[0] == Close[1]) return ;
        Value.Set(Volume[0] + Volume[1]);

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thank you very much AlanP.

          I´m now trying to plot accumulated volume until a condition is reached, e.g. I want accumulated volume until 13:00 PM, Can it be done this way?? (I assumed not because does not plot anything). I use VOL indicator to rename and edit.

          Code:
          		protected override void OnBarUpdate()
          		{
          			if (CurrentBar < 1 || Close[0] == Close[1]) return ; 
          			myDataSeries.Set(Volume[0] + Volume[1]);
          			if (CurrentBar >= 1 || Close[0] == Close[1] || ToTime(Time[0]) == 130000) return ; 
          			myDataSeries.Set(Volume[0] + myDataSeries[1]);
                         }
          I also add "myDataSeries = new DataSeries(this);" in Initialized and also "#region Variables" not sure why, just read it and did it.

          Code:
          	public class VOL3 : Indicator
          	{
          		/// <summary>
          		/// This method is used to configure the indicator and is called once before any bar data is loaded.
          		/// </summary>
          #region Variables
          private DataSeries myDataSeries; // Define a DataSeries variable
          #endregion
          		/// 
          		protected override void Initialize()
          		{
          			Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Bar, "Volume"));
          			Add(new Line(Color.DarkGray, 0, "Zero line"));
          			myDataSeries = new DataSeries(this); // "this" refers to the indicator, or strategy
                                                  // itself. This syncs the DataSeries object
                                                  // to historical data bars
          		}
          Compiles fine but does nothing. I just want the indicator to show me how much volumen has been traded at 13:00 so I need somehow keep volume count increasing and ask for it when needed.

          Comment


            #6
            Hello,

            Thank you for your note.

            Under Region Variables I would swap out your myDataSeries variable for,

            Private double cVol;

            Under OnBarUpdate I would use the following code,

            if (CurrentBar < 1 ) return ;
            if(ToTime(Time[0]) > 130000)
            {
            cVol=Volume[0];
            }
            else
            {
            cVol+=Volume[0];
            Value.Set(cVol);
            }


            This code will first check to make sure we have more than 1 bar, if not it will return. Otherwise if time is less than 130000, it will set the cVol variable equal to accumulated volume.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Thanks a lot.

              How did you find "cVol"? Is a part of Data Series? I was searching through NT Help Guide and forums and never found nothing about it.

              Thank you again

              Comment


                #8
                Ok, forget last reply. cVol is a variable.

                cVol += Volume[0] is equal to cVol= cVol + Volume[0]

                Does that mean that for every bar update?:

                Bar1: cVol = Vol[0]
                Bar2: cVol = Vol[0]+ Vol[1]
                Bar3: cVol = Vol[2] + Vol [1] + Vol [0]
                .....

                Seems to be that.

                I would never had imagine this solution. I´m a super beginner. It´s going to be a long walk...

                How can I learn those things? Any book? Just coding and asking? Reading anything?

                Thank youuuuu AlanP!!

                Comment


                  #9
                  Hello Tomaslolo,

                  cVol += Volume[0] is going to add volume of this bar to the variable cVol, which on the next bar will include the volume of the that bar plus whatever cVol was. The bar after that will include volume at that time plus the running total of cVol.

                  I’ve included a link to our helpguide which includes a lot of examples and great information,


                  NinjaScript Tip Youtube:


                  Strategy Wizard Youtube:


                  Reference Code Examples, great place to dig through others code for solutions:


                  Please let us know if you need further assistance.
                  Alan P.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  599 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  345 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  103 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  558 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  558 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X