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

Can Volumetric bars be added as a second data series?

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

    #16
    Hello tonynt,

    You would use the appropriate BarsInProgress index for each data series that is Volumetric. The primary could be used as BarsArray[0].BarsType or Bars.BarsSeries.BarsType, and each additional volumetric data series would be BarsArray[X] where X is the BarsInProgress index of that data series.

    When using the data access methods, you will need to use bar indexes that are associated with that particular data series. For example:

    Code:
    NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType barsType2 = BarsArray[2].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsType;
    
    Print(barsType2.Volumes[CurrentBars[2]].GetDeltaForPrice(Closes[2][0]));
    Publicly available information on BarsInProgress and creating a Multi Time Frame NinjaScripts can be found here - https://ninjatrader.com/support/help...nstruments.htm

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #17
      Hello,

      referring to your reply#14 is this correct AddVolumetric("0", BarsPeriodType.Range, 3, VolumetricDeltaType.BidAsk, 1);?

      (without " " I get error messages when compiling)

      And with "0" I get in log tab the attached message.

      Thank you!
      Tony
      Attached Files
      Last edited by tonynt; 09-04-2019, 07:14 AM. Reason: add screenshot

      Comment


        #18
        Hello tonynt,

        In your snippet you are passing the string "0" NinjaTrader thinks you are looking for an instrument named "0."

        Passing null as the instrument parameter would look like:

        AddVolumetric(null, BarsPeriodType.Range, 3, VolumetricDeltaType.BidAsk, 1);

        Please let me know if you have any questions.
        JimNinjaTrader Customer Service

        Comment


          #19
          Hello,

          so as Jim stated above, I can use null, when adding Volumetric Data Series, which is the same instrument as the primary Data Series. Can I use something similar for
          intbaseBarsPeriodTypeValue, when I want to add the same BarsPeriodTypeValue as the primary Data Series?


          Thank you,
          emuns

          Comment


            #20
            Hello emuns,

            Thanks for your message. Passing null is only supported for the Instrument parameter. Capturing the BarsPeriodType of the primary data series may work under many cases, but would not be fully supported for reference in State.Configure. Strategy Optimizations, for example, will not work when the BarsPeriod is referenced in State.Configure.

            AddDataSeries(BarsPeriod.BarsPeriodType, 1); // (Unsupported reference to BarsPeriod in State.Configure. Reference is not guaranteed.)

            AddDataSeries overload reference - https://ninjatrader.com/support/help...dataseries.htm

            Please let us know if we can be of further assistance.
            JimNinjaTrader Customer Service

            Comment


              #21
              Hello,

              I'm trying to add a volumetric data series in my script to get the daily POC from volumetric bar, running my script on a 30 min TF bar as a primary data serie. This is the script:

              else if (State == State.Configure)
              {
              AddVolumetric("ES 06-22", BarsPeriodType.Day, 1, VolumetricDeltaType.BidAsk, 1);
              }
              }

              protected override void OnBarUpdate()
              {

              double price;

              NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe barsType = BarsArray[1].BarsType as NinjaTrader.NinjaScript.BarsTypes.VolumetricBarsTy pe;

              if (barsType == null)
              return;

              Print("Maximum Combined: " + barsType.Volumes[CurrentBars[0]].GetMaximumVolume(null, out price) + " at price: " + price);


              }

              I'm getting an error message shown in screenshot, where is the mistake in my code? Thanks

              Attached Files

              Comment


                #22
                Hello federicoo,

                When you add an additional data series, OnBarUpdate updates for the primary data series AND the secondary series that you added.

                You will want to structure your code so you know which data series your logic will be processed on. See below for how BarsInProgress is used to make sure logic is checked only on specific data series.

                Event Driven OnBarUpdate - https://ninjatrader.com/support/help...arupdateMethod

                After observing this, also take note of how CurrenBar/CurrentBars is used.

                Accessing Price data in a Multi Time Frame Script - https://ninjatrader.com/support/help...arsninjascript

                After reviewing the above the issues should make more sense:

                You are supplying the CurrentBars[0] index (aka the current bar index of the primary data series) with a reference on the secondary data series. CurrentBars[1] would be recommended to be checked since that index would be relative to the added data series.

                Keep in mind, you will also have to make sure that you have processed X number of CurrentBars[1] to be able to reference that index or that many BarsAgo on the added data series.

                Making sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm


                JimNinjaTrader Customer Service

                Comment


                  #23
                  Hello,

                  I want to get the developing POC of the present volumetric bar (not the close bar but the developing present bar). For example, configuring the volumetric bar as a Day, with 3 as a parameter. So each bar represent 3 days, but I want to get the poc of the developing bar.

                  In this link, the poc is retrieved from the last closed bar, not the present bar:

                  https://ninjatrader.com/support/help...tric_bars2.htm - Using Orderflow Volumetric bars in NinjaScript.

                  Please let me know,

                  Thanks



                  Comment


                    #24
                    Hello federicoo,

                    When a script processes historical data, or when it uses Calculate.OnBarClose, it will process logic only when bars close.

                    If you want the developing POC of the developing bar, you can add the volumetric data series and you can set Calculate to Calculate.OnEachTick.

                    If you are changing a default in State.SetDefaults (I.E. if you change what Calculate gets set to in State.SetDefaults,) remember that you will need to remove and re-add the script to load in the new default.
                    JimNinjaTrader Customer Service

                    Comment


                      #25
                      Thank You Jim,

                      In order to use this in strategy analyzer, I would prefer to use onbarclose method but in one minute bar.

                      In resume, it should wait the close of each 1 min bar (primary data serie), and then get the POC of the volumetric bar (secondary data serie) of the last 3 days counted back from that 1 minute bar (present bar).

                      So, in every 1 min bar update I should have the POC of the 3 days preceding that present one-minute (counted from this present 1 min bar).

                      Thanks again

                      Comment


                        #26
                        Hello fredericoo,

                        If you are processing OnBarClose and want to reference 3 days back from the currently processing minute, I may suggest something like:

                        barsType.Volumes[CurrentBars[1]-2].GetMaximumVolume(null, out price)

                        Where we use CurrentBars[1]-2 to essentially say "2 bars ago" on the daily volumetric series.

                        Since this would be OnBarClose behavior when the current daily bar has not yet closed, using CurrentBars[1]-2 could give you the index for the bar you are looking for.

                        I may also suggest using prints and printing out the timestamp of your daily bar so you know you have the right index.

                        For example, the following will tell you the timestamp of the daily bar when you use the CurrentBars[1]-2 bar index.

                        Print(BarsArray[1].GetTime(CurrentBars[1]-2));
                        JimNinjaTrader Customer Service

                        Comment


                          #27
                          Hello,

                          I want to be able to calculate imbalances in Volumetric Data in real time. What would be the most efficient way to calculate it from within the script? If I re-calculate all prices/imbalances on each tick - it would waste too many CPU cycles in volatile markets like NQ and ES. Should I introduce 1 or 2 second series, get all prices from all levels during that second bar, and basically repeat calculations each second or two? Or is there a better way?

                          Thanks

                          Comment


                            #28
                            Hello music_p13,

                            This is really a subjective question, but in principle, decreasing how often you calculate something will decrease overhead.

                            Adding an additional data series to calculate things on a smaller interval may be helpful, but may be complex.

                            If the smaller interval updates are not needed in historical processing you could consider:

                            With Realtime processing, detect imbalances from a timer.

                            With Historical processing, detect imbalances on bar closes.

                            JimNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by PaulMohn, Today, 03:49 AM
                            0 responses
                            6 views
                            0 likes
                            Last Post PaulMohn  
                            Started by inanazsocial, Today, 01:15 AM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_Jason  
                            Started by rocketman7, Today, 02:12 AM
                            0 responses
                            10 views
                            0 likes
                            Last Post rocketman7  
                            Started by dustydbayer, Today, 01:59 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post dustydbayer  
                            Started by trilliantrader, 04-18-2024, 08:16 AM
                            5 responses
                            23 views
                            0 likes
                            Last Post trilliantrader  
                            Working...
                            X