Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical BuySell Volume Indicator

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

    Historical BuySell Volume Indicator

    Hi NT,

    I have heard that it is possible to plot historical BuySellVolume indicator in NT-7. Is there a working sample of this? I read several pages in the help about this new feature, but was not able to make this simple indicator work historically. I figure there are some good examples of this new powerful feature for NT-7.

    I know how to do it in NT-8 but want to stick to NT-7 for live trading for now.

    Thanks.

    #2
    Hello FIG690,

    The BuySellVolume indicator has a check for historical that prevents this from working historically. This is because the script is using GetCurrentAsk() and GetCurrentBid() which are not accurate historically.

    It may be possible to add a 1 tick ask and 1 tick bid series, re-code the indicator to use these, and have an accurate plot historically.

    I am not aware of an existing script that does this, however, this thread will remain open for any community members that are aware of an indicator like this or would like to assist.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm not sure this really works. As soon as I add these lines to the script nothing plots. This is why I was asking for a simple example of an already existing indicator.

      Add("ES 12-16", PeriodType.Tick, 1, MarketDataType.Last);
      Add(this.Instrument.FullName.ToString(), PeriodType.Tick, 1, MarketDataType.Bid);
      Add(this.Instrument.ToString(), PeriodType.Tick, 1, MarketDataType.Ask);

      I've attached the start of a BuySellVolume indicator below. Commenting out the above lines will just plot the close price. Adding these lines in or just one of them will cause the indicator to do nothing.
      Attached Files

      Comment


        #4
        Hello FIG690,

        The indicator you have posted is not the code of the buy and sell volume.
        (Which would need to be recoded to use the proper bars in progress for each data type)

        The current code you have plots the close price.

        The lines you have commented, out would add in those additional series. The tick series would try and set a value for the primary plot which doesn't have a bar yet, and that index wouldn't exist.

        Are you getting an error in the Log tab of the Control Center?

        Try adding a check that at least one primary bar exists.
        if (CurrentBars[0] < 1)
        return;
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          I do have:

          9/18/2016 11:00:45 PM Default Unable to unsubscribe from L2 data for instrument 'ES 12-16': no handle

          9/18/2016 11:02:25 PM Default Unable to subscribe to L2 data for instrument 'ES 12-16': no handle

          messages. Is this preventing the indicator from plotting once you un-comment the add() methods?

          Comment


            #6
            FIG690,

            No, this would not be the error I am expecting.
            Does this error occur each time you refresh the NinjaScripts on the chart?
            Or does this error occur when openining the chart?

            The error would indicate there is no real-time Level 2 data streaming (market depth).
            You may need to disconnect and reconnect to the connection to the brokerage or data feed you are connected to.

            The error I am expecting is an indexing error or a object not set to instance of an object error.

            Yes, the script does not run on my end after uncommenting the Add() calls due to an indexing error. Adding a check that the bars actually exist first was able to resolve this on my end.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Could you share how you "add a check that the bars actually exist first."

              Comment


                #8
                Hello FIG690,

                From post #4:
                Try adding a check that at least one primary bar exists.
                if (CurrentBars[0] < 1)
                return;
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  Thanks for the help earlier. I've attached an updated ninja script which seems to be plotting correctly now. The issue I have now is the volume seems to be off. It is much larger than the actual trade size. I'm using the "Volumes[1][0]" for example and this is a tick stream so I would guess this should work. Is it accumulating volume? For example new trades on offer are +1, +1, +2 so that at the end I have a volume of 4 not just the 2 lot trade? (If so, does the accumulation reset with new price levels?)

                  Thanks
                  Attached Files

                  Comment


                    #10
                    Hello FIG690,

                    What you are seeing here is due to the bars time stamps not being granular enough to completely interweave ticks. NT7 had similar behavior, but more exaggerated since time stamps only went down to a second. In NT8, the core technically supports down to the DateTime.Tick, but as a result of the data provider only providing milliseconds, you can see this behavior in circumstances where ticks share the same millisecond time stamp.
                    Last edited by NinjaTrader_ChelseaB; 09-21-2016, 07:50 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,

                      So is it that if the ticks are of the same second in NT7, and the trade flow for a second is something like:

                      +1, +1, +5

                      then I count the first trade and its volume is 1, then second trade occurs and I get a volume of 2 and then the third trade occurs and I get 7? And then if I ask or use Volumes[1][1] (assume [1] is a tick steam) I'm getting trades from one second back that also are summed like above?

                      Sorry, just don't fully understand this stream logic yet.

                      Thanks.

                      Comment


                        #12
                        Hello FIG690,

                        Thank you for your response.

                        This would not be the case as to why your accumulation is larger than needed. You need to implement BarsInProgress checks so that items are not unnecessarily updating. You also need to remove the if else as it is causing unnecessary changes.

                        Your code should reflect the following::
                        Code:
                        			if (CurrentBars[0] < 1)
                        				return;
                        
                        			if (BarsInProgress == 0 && CurrentBars[0] != activeBar)
                        			{
                        				buys = 0;
                        				sells = 0;
                        				activeBar = CurrentBars[0];
                        			}
                        
                        			if (BarsInProgress == 1)
                        			{
                        				if (Closes[1][0] >= Closes[3][0])
                        					buys += Volumes[1][0];
                        				else if (Closes[1][0] <= Closes[2][0])
                        					sells += Volumes[1][0];
                        			}
                        
                        			Sells.Set(-1 * sells);
                        			Buys.Set(buys);

                        Comment


                          #13
                          Hi Patrick,

                          I made your changes and now I don't get a plot at all. I've attached the updated script.
                          Attached Files

                          Comment


                            #14
                            Hello FIG690,

                            Thank you for your response.

                            Can you attach the unprotected code?

                            You can attach your indicator to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Indicator > select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.

                            Comment


                              #15
                              Attached. Sorry didn't know it was not readable.
                              Attached Files

                              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
                              344 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
                              557 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X