Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

VWAP Modification

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

    #31
    Hello DTSSTS,

    Thanks for your notes.

    You may consider setting the ArePlotsConfigurable property to false so that plots are not configurable in the indicator dialog.

    ArePlotsConfigurable: https://ninjatrader.com/support/help...nfigurable.htm

    When using the AddDataSeries() method overload that allows you to specify a trading hours template you must supply a sting instrumentName argument since the method requires it.

    If you want the added secondary series to use the primary series instrument, you could set the string instrumentName​ property to Instrument.FullName.ToString(). For example:

    AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH")

    Review the AddDataSeries() help guide page to see what arguments are required to use when specifying a trading hours template.

    And, see the sample code in this help guide: https://ninjatrader.com/support/help...barsperiod.htm

    To see what a trading hours template's name is, go to Tools > Trading Hours and note the name of the template.

    Review this help guide page: Trading Hours: https://ninjatrader.com/support/help...urs_window.htm

    In regard to BarsInProgress, BarsInProgress 1 refers to the first added series in a script. BarsInProgress 2 refers to the second added series in a script. Say you have called AddDataSeries() twice in the script. The first time you call it that BarsInProgress index for that added series will be BarsInProgress 1. The second time you call AddDataSeries() that specific added series will have be BarsInProgress 2.

    It is very important to review this entire help guide document to understand how multi-timeframe/multi-instruments NinjaScripts work: https://ninjatrader.com/support/help...nstruments.htm

    Yes, that is how logic could be used to check if BarsInProgress 1 or BarsInProgress 2 is processing.

    Thank you for pointing that out regarding the links. I have edited the links in the previous post and tested them to confirm they are working now.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #32
      Really not wanting to see ALL Plots to ArePlotsConfigurable false, just the transparent ones

      ******************************************

      try these 2 but neither will compile

      /// TradingHours.Get("Use instrument settings")

      AddDataSeries(Data.BarsPeriodType.Minute, 1, TradingHours.Get("CBOE US Index Futures ETH"));

      /// RTH

      AddDataSeries(Data.BarsPeriodType.Minute, 1, "US Equities RTH");

      ****************************

      on the links YOUR welcome, I saw this behavior on many older post this weekend

      thanks again​

      Comment


        #33
        Hello DTSSTS,

        Thanks for your notes.

        The ArePlotConfigurable property would apply this to all plots in the script.

        There are no supported methods or properties available for only preventing certain plots from being configurable in a custom NinjaScript.

        Those lines of code are not compiling successfully because you are not supplying the proper arguments when calling AddDataSeries(). As stated in my last post, you MUST supply the arguments to the AddDataSeries() method that is supported and mentioned in the help guide. You cannot simply omit certain arguments or change the arguments that this method takes.

        The syntax is AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName) in the AddDataSeries() help guide.

        This means you must supply an instrumentName, barsPeriod, and tradingHoursName property to the AddDataSeries() method. An example of what this might look like could be seen on my previous post and seen below.

        AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH")

        ​As noted in my previous post, "If you want the added secondary series to use the primary series instrument, you could set the string instrumentName​ property to Instrument.FullName.ToString()."

        Please review the syntax section of the AddDataSeries() help guide to see what arguments are required when calling this method with a tradingHoursName overload.

        AddDataSeries: https://ninjatrader.com/support/help...dataseries.htm

        And, please review the second sample code in the BarsPeriod help guide page linked here which demonstrates passing in a BarsPeriod argument to the AddDataSeries() method.

        BarsPeriod: https://ninjatrader.com/support/help...iod.htm​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #34
          sorry i have been using this type for years AddDataSeries(Data.BarsPeriodType.Minute, 30); with no reference to instrument this is the script created by the strategy builder for secondary series

          AddDataSeries(Instrument.FullName.ToString(), Data.BarsPeriodType.Minute, 1, "US Equities RTH");

          nor this

          AddDataSeries(Instrument.FullName.ToString(), Data.BarsPeriodType.Minute, 1, TradingHours.Get("CBOE US Index Futures ETH"));

          will not compile

          YOUR EXAMPLE WORKS

          AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH");

          new BarsPeriod and Value - 1 ARE NEW TO THE SCRIPTS

          WE learn from the strategy builder and this is what it creates for us

          AddDataSeries(Data.BarsPeriodType.Minute, 1)

          so should i change all that are like the last example

          so these work

          AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH");
          AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "CBOE US Index Futures ETH");

          Use instrument settings is what i generally use for futures

          is this "CBOE US Index Futures ETH" the same as Use instrument settings

          and can this be used Use instrument settings

          thanks​

          Comment


            #35
            Hello DTSSTS,

            Thanks for your note.

            "AddDataSeries(Instrument.FullName.ToString(), Data.BarsPeriodType.Minute, 1, "US Equities RTH");

            AddDataSeries(Instrument.FullName.ToString(), Data.BarsPeriodType.Minute, 1, TradingHours.Get("CBOE US Index Futures ETH"));"

            This code above will not compile successfully because you are not using the correct syntax. You are supplying a BarsPeriodType argument where a BarsPeriod argument needs to be supplied.

            In the AddDataSeries() help guide we can see that BarsPeriodType is not the same thing as BarsPeriod. We can also see that we must pass in a BarsPeriod when using the syntax that allows you to specify a tradingHoursName.

            AddDataSeries(string instrumentName, BarsPeriod barsPeriod, string tradingHoursName)

            Further, BarsPeriodType is the BarsType used for the bars period, such as Minute, Second, etc. This is only the bars period, not the interval.

            BarsPeriod is a BarsPeriod object that defines the period type and interval.

            When using the AddDataSeries() syntax that lets you specify a tradingHoursName, you must pass in a BarsPeriod.

            See the BarsPeriod help guide page linked in post # 33 and in post # 31 which contains sample code demonstrating this.

            Note that the Strategy Builder uses only one of the available AddDataSeries() method syntaxes. The Strategy Builder does not have the option to supply AddDataSeries() with a BarsPeriod argument. This syntax is specific to unlocked scripts.

            You would only need to use this specific syntax when you want to define a tradingHoursName since that is the specific syntax mentioned in the help guide that lets you specify a tradingHoursName. Otherwise, you could use the other syntax you mentioned, AddDataSeries(BarsPeriodType periodType, int period), for other added series in the script.
            Last edited by NinjaTrader_BrandonH; 04-24-2023, 02:06 PM.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #36
              Sorry I really do not know what that last post is about

              I STATED that is used the below code and it compiles so I assume it is correct

              AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH");/// Closes[1]
              AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "CBOE US Index Futures ETH");/// Closes[2]​

              ARE THE ABOVE CORRECT?

              IF those are correct the we have that part, now I am back to an area that was the WHERE to START the calculation that took 5 days for me to figure out on the other dataseries and plots
              the below is what I am using for those to mare the starting bar

              int highestBarIndex3 = HighestBar(Highs[3], 78);
              DateTime highestBarTime3 = Time[highestBarIndex3];​

              SO I NEED THE SAME FOR THE NEW RTH and ETH dataseries (I have to mark the BAR Time for the calculations to work

              SO HOW DO I mark the First Bar of the Session RTH - which I know is 9:31 AM EST and (and Also the first bar ETH) which is 6:01 PM EST

              I thought that adding the new DataSeries was going to automatically have the start point at the firstbarofsession but that is not the case

              if ((Bars.IsFirstBarOfSession)
              && (BarsInProgress == 1))​

              int vwapRTHIndex1 = IsFirstBarOfSession; << ----- what will mark the first 1 minute bar
              DateTime vwapRTHstarttBarTime1 = Time[vwapRTHIndex1];​


              UPDATE: APPEARS I GOT THESE BACKWARDS


              if (BarsInProgress == 1))​

              }

              if ((Bars.IsFirstBarOfSession)​
              Last edited by DTSSTS; 04-24-2023, 03:06 PM.

              Comment


                #37
                Hello DTSSTS,

                Thanks for your note.

                Yes, that would be the correct syntax for the AddDataSeries() method.

                I see you are referencing Highs[3] when assigning a value to the highestBarIndex3 variable.

                Do you only have the 2 secondary data series you noted in post # 36 added to the script? Or, do you have a third secondary data series added to the script?

                Say the added series that is set to use the 'US Equities RTH' trading hours template is the first added series in the script.

                AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH"); //BarsInProgress 1

                AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "CBOE US Index Futures ETH"); //BarsInProgress 2​


                Since it is the first added series, this would mean the BarsInProgress value of this additional series is BarsInProgress 1.

                To check if the current bar processing is the first bar of the session for that additional series you would check if BarsInProgress is equal to 2 and then check if Bars.IsFirstBarOfSession.

                For example:

                Code:
                if (BarsInProgress == 1)
                {
                    if (Bars.IsFirstBarOfSession)
                    {
                        //add your logic here that you want to process on the first bar of the session for the second additional series
                    }
                }
                To check if the current bar processing is the first bar of the session for the second added series in the script that is set to use the "CBOE US Index Futures ETH" trading hours template, the code might look something like this.

                Code:
                if (BarsInProgress == 2)
                {
                    if (Bars.IsFirstBarOfSession)
                    {
                        //add your logic here that you want to process on the first bar of the session for the second additional series
                    }
                }


                BarsInProgress: https://ninjatrader.com/support/help...BarsInProgress
                IsFirstBarOfSession: https://ninjatrader.com/support/help...stbarofsession
                Last edited by NinjaTrader_BrandonH; 04-24-2023, 03:26 PM.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #38
                  Yes this is what I thought for ETH

                  if (BarsInProgress == 2)
                  {
                  if (Bars.IsFirstBarOfSession)

                  and yes I do have additional data series added after these 2 where I start the HighestBar etc with Closes[3] etc

                  Do I need to go back and add the if (BarsInProgress == 3)​ etc to those areas?????????

                  and should I update my dataseries for those as well ?????????

                  ie from

                  AddDataSeries(Data.BarsPeriodType.Minute, 1);/// Closes[3]

                  to this

                  AddDataSeries(Instrument.FullName.ToString(), Data.BarsPeriodType.Minute, 1);/// Closes[3]

                  or to this


                  AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1};// Closes[3]

                  Thanks again for all the help - I think I am near to have all needed info finish this indicator

                  Comment


                    #39
                    Hello DTSSTS,

                    Thanks for your notes.

                    You would likely not need to put int highestBarIndex3 = HighestBar(Highs[3], 78); into a BarsInProgress == 3 condition. Using Highs[3] as the Series input for HighestBar() means that you are supplying the HighestBar() with the High PriceSeries value of that third added series in your script.

                    No, you would not need to update your AddDataSeries() method. You may leave it as AddDataSeries(Data.BarsPeriodType.Minute, 1);.

                    Let me know if I may assist further.
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #40
                      Thanks

                      Leaving the int highestBarIndex3 = HighestBar(Highs[3], 78);​ should be the same as removing it Correct?

                      so OK either way;

                      Thanks again for all the help, I learn alot during this post,
                      WE ARE DONE HERE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!

                      I know what you are thinking but I cannot type it here.

                      Comment


                        #41
                        Hello DTSSTS,

                        Thanks for your notes.

                        I am not sure I entirely follow your comment "Leaving the int highestBarIndex3 = HighestBar(Highs[3], 78);​ should be the same as removing it Correct?"

                        If you need this line of code in your script for calculations then you might not want to remove it from the script. If it is not necessarily needed for calculations then you could consider removing it.

                        I am happy that we were able to provide you with the education you needed so that you could create a custom NinjaScript that meets your goals.

                        Please let me know if I may assist you further with this.
                        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                        Comment


                          #42
                          OK I have complete the Floating Anchored VWAP Indicator - works as expected on Charts
                          all plots are created by the Secondary DataSeries so no matter what type candle they are applied to chart Wise the plots remain consistent

                          here are my secondary dataseries for reference to my Questions


                          AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH");/// Closes[1]
                          AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "CBOE US Index Futures ETH");/// Closes[2]


                          AddDataSeries(Data.BarsPeriodType.Minute, AnchorONEDataSeriesMinutes);/// Closes[3]
                          AddDataSeries(Data.BarsPeriodType.Minute, AnchorTWODataSeriesMinutes);/// Closes[4]
                          AddDataSeries(Data.BarsPeriodType.Minute, AnchorTHREEDataSeriesMinutes);/// Closes[5]
                          AddDataSeries(Data.BarsPeriodType.Minute, AnchorFOURDataSeriesMinutes);/// Closes[6]


                          We are using the first 2 for RTH Standard VWAP and Extended Hours Session VWAP

                          MY ISSUE when applying to a Strategy Errors are created because of Secondary Data of the Indicator

                          the Strategy already has multiple Secondary Dataseries as well

                          ERROR STATES

                          'IndicatorName' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its Configure state. Attemplted to load MNQ JUN23 Globex: 1 Minute

                          Thanks

                          Comment


                            #43
                            Hello DTSSTS,

                            Thanks for your notes.

                            Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided.​

                            The above information is stated in the AddDataSeries() help guide page linked below.

                            AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

                            This means that you need to hardcode the values into the AddDataSeries() method instead of using variables such as AnchorONEDataSeriesMinutes, AnchorTWODataSeriesMinutes, and so on.

                            As for the error message, the error indicates that an indicator added a data series with AddDataSeries() but the host strategy or calling indicator did not.

                            From the AddDataSeries() help guide linked above:
                            "Should your script be the host for other scripts that are creating indicators and series dependent resources in State.DataLoaded, please make sure that the host is doing the same AddDataSeries() calls as those hosted scripts would. For further reference, please also review the 2nd example below and the 'Adding additional Bars Objects to NinjaScript' section in Multi-Time Frame & Instruments"

                            From the Multi-Timeframe/Multi-Instrument help guide:
                            "To maximize data loading performance, any NinjaScript object (indicator or strategy as host) which references a multi-series indicator which calls AddDataSeries must include it's own calls to AddDataSeries(). For example, if the code above was included in an indicator, and that indicator was referenced in a NinjaScript strategy, then the hosting strategy will need to include the same calls to AddDataSeries(). When the strategy adds the additional Bars objects, the calls to AddDataSeries() within the indicator will be ignored. If the Bars objects are not added by the strategy in such cases, and error will be thrown in the Log tab of the Control Center that would read - "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state."

                            Working with Multi-TimeFrame/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/helpGuides/nt8/index.html?multi-time_frame__instruments.htm#AddingAdditionalBarsOb jectToninjascript

                            See this forum thread for more information about this error: https://forum.ninjatrader.com/forum/...​​
                            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                            Comment


                              #44
                              IS THIS

                              Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided.​

                              REFERRING TO THIS in my Indicator

                              AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH");/// Closes[1]
                              AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "CBOE US Index Futures ETH");/// Closes[2]


                              AddDataSeries(Data.BarsPeriodType.Minute, AnchorONEDataSeriesMinutes);/// Closes[3]
                              AddDataSeries(Data.BarsPeriodType.Minute, AnchorTWODataSeriesMinutes);/// Closes[4]
                              AddDataSeries(Data.BarsPeriodType.Minute, AnchorTHREEDataSeriesMinutes);/// Closes[5]
                              AddDataSeries(Data.BarsPeriodType.Minute, AnchorFOURDataSeriesMinutes);/// Closes[6]

                              IF YOU ARE JUST REFERING TO

                              AnchorONEDataSeriesMinutes THAT can simply be over come with

                              AddDataSeries(Data.BarsPeriodType.Minute, 1);/// Closes[3]
                              AddDataSeries(Data.BarsPeriodType.Minute, 5);/// Closes[4]
                              AddDataSeries(Data.BarsPeriodType.Minute, 15);/// Closes[5]
                              AddDataSeries(Data.BarsPeriodType.Minute, 30);/// Closes[6]

                              WHEN USING THE INDICATOR In a Strategy, THAT part change does allow me to add​ all of this in my Strategy

                              AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "US Equities RTH");/// Closes[1]
                              AddDataSeries(Instrument.FullName.ToString(), new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1}, "CBOE US Index Futures ETH");/// Closes[2]​


                              AddDataSeries(Data.BarsPeriodType.Minute, 1);/// Closes[3]
                              AddDataSeries(Data.BarsPeriodType.Minute, 5);/// Closes[4]
                              AddDataSeries(Data.BarsPeriodType.Minute, 15);/// Closes[5]
                              AddDataSeries(Data.BarsPeriodType.Minute, 30);/// Closes[6]​

                              THEN ANY additional data series the Strategy in using for other indicators or conditions set

                              IF I PLACE THE SECONDARY DATASERIES as in my last example as show, with the indicator work as expected OR do I also need to hardcoded​ the Period Lookback I am using in the indicator

                              I have a variable lookback period as well, SO IF I KNOW the way above will work for the indicator to find the data series to function I can go back and hardcode those items.

                              This is the indicator in the dataload region

                              ATSFloatingAnchors1 = ATSFloatingAnchors(Close, true, true, true, 1, 120, true, 5, 78, true, 15, 78, true, 30, 78);

                              the 1 , 120 is 1 minute with 120 Periods etc that is Closes[3] and is Closes[3] for the indicator as well, when the indicator was loaded into the strategy those inputs were as shown above, The 120 Period is also a variable AnchorONELookBackPeriod SO NOT HARDCODED in the indicator to clarify if I need to Hardcore the AnchorONELookBackPeriod or NOT

                              Thanks
                              Last edited by DTSSTS; 05-01-2023, 06:23 AM.

                              Comment


                                #45
                                I haven't followed all of this entirely, BUT where you're sending Instrument.FullName.ToString() in that particular overload, you could always send null which means the same thing, yet works in situations where this other approach does not (like Market Analyzer). Remember, you have to AddDataSeries while in State.Configure, but you can't reliably access Bars.Instrument until later in State.DataLoaded (and by then it's too late to add more data series). What you will find is that if you just go ahead and do it, it works sometimes, but not reliably, and definitely not in Strategy Analyzer.
                                Bruce DeVault
                                QuantKey Trading Vendor Services
                                NinjaTrader Ecosystem Vendor - QuantKey

                                Comment

                                Latest Posts

                                Collapse

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