Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Add Dataseries

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

    Add Dataseries

    Hello,

    when using this syntax (null) in an indicator that calculates from volumetric does this work correctly then when applying the indicator eg in a 1 minute chart or 5 Range chart? I thought with this solution I dont need to modify the indicator for every instrument and with the int for the value of the added dataseries its easier to handle in the parameters when applying instead in the code as well.

    else if (State == State.Configure)
    {
    AddVolumetric(null, BarsPeriodType.Range, valuedataseries, VolumetricDeltaType.BidAsk, 1);
    }

    Thank you!
    Tony
    Last edited by tonynt; 02-17-2021, 02:19 PM. Reason: wrong translation

    #2
    Hello tonynt,

    Thank you for your reply.

    Yes, you should be able to use null as the instrument name to default to the same instrument as the primary series. Do you seem to be having issues with this?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Hello,

      thank you for your reply. Not issues yet, but because its part of a lot of calculations from that dataseries I thought its faster to know before by one accurate reply in the forum instead of working round and comparing results.

      And how do I use volumetric dataseries with sizefilter for primary dataseries in the code? Has this to be added even when referring to the chart dataseries like AddVolumetric(string instrumentName, Data.BarsPeriodType baseBarsPeriodType, int baseBarsPeriodTypeValue, Data.VolumetricDeltaType deltaType, int tickPerLevel, int sizeFilter, string tradingHoursName, bool? isResetOnNewTradingDay)


      Thank you!

      Tony
      Last edited by tonynt; 02-18-2021, 08:18 AM. Reason: add question size filter volumetric

      Comment


        #4
        I am attempting with an indicator that trades with buttons to add a secondary instrument to place in the Order part of the indicator

        AddDataSeries(Symbol2, Data.BarsPeriodType.Second, 20);


        I added the data series with an user input Symbol2

        in paraments as public string Symbol2


        THE ABOVE PARTS seems to likely work, attempting to place in the Order part of the coding is a different story

        below is the code for the working order code that trades the primary symbol

        Order mar****rder = account.CreateOrder(Instrument, OrderAction.SellShort, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, 2, 0, 0, string.Empty, "Short conditional", new DateTime(), null);


        i need somehow to identify the Instrument in below Line (I have tried MasterInstrument InstrumentName and many other ways I have read in forums but without success in compiling the indicator
        Order mar****rder = account.CreateOrder(Instrument.InstrumentName[Symbol2], OrderAction.SellShort, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, 2, 0, 0, string.Empty, "Short conditional", new DateTime(), null);

        Thanks

        Comment


          #5
          Hello tonynt and DTSSTS,

          Thank you for your notes.

          tonynt:

          how do I use volumetric dataseries with sizefilter for primary dataseries in the code? Has this to be added even when referring to the chart dataseries like AddVolumetric(string instrumentName, Data.BarsPeriodType baseBarsPeriodType, int baseBarsPeriodTypeValue, Data.VolumetricDeltaType deltaType, int tickPerLevel, int sizeFilter, string tradingHoursName, bool? isResetOnNewTradingDay)

          That is correct. If you are adding a Volumetric series to your script and would like to set a sizeFilter for the primary instrument, you would need to use the following method from the help guide documentation and set the instrumentName to null or use the actual name of the primary instrument.

          AddVolumetric(string instrumentName, Data.BarsPeriodType baseBarsPeriodType, int baseBarsPeriodTypeValue, Data.VolumetricDeltaType deltaType, int tickPerLevel, int sizeFilter, string tradingHoursName, bool? isResetOnNewTradingDay).

          See the help guide link below for more information.
          AddVolumetric - https://ninjatrader.com/support/help...volumetric.htm

          DTSSTS:

          I see that you are adding an instrument dynamically within AddDatSeries(). As stated in the Warning section of the AddDataSeries() help guide documentation: "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. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."

          That being said, to reference an added series in your script you would need to use a BarsInProgress check. For example, if this is the first added series in your script you would check if (BarsInProgress == 1) followed by calling your order entry method with an Instrument for the instrument property. This checks to ensure that the instrument being process is the added series followed by placing an order to that instrument

          See the help guide links below for more information.
          AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm
          CreateOrder() - https://ninjatrader.com/support/help...reateorder.htm
          Working with Multi-Instrument and Multi-Timeframe scripts - https://ninjatrader.com/support/help...nstruments.htm

          Let us know if we 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


            #6
            I am piggy-backing on this thread if that is OK. I understand the limitation that the parameters of the desired dataseries can't rely on user input, but can we use conditionally executed AddDataSeries statements?

            For example, assume the userInput supplied by the user is either a "1","2" or a "3" -to indicate which of the following AddDataSeries' statements are executed:

            if (userInput == 1))
            AddDataSeries(Data.BarsPeriodType.Tick, 900); //index == 1
            else if(userInput == 2)
            AddDataSeries(Data.BarsPeriodType.Tick, 2700); //index == 2
            else if(userInput == 3)
            AddDataSeries(Data.BarsPeriodType.Tick, 5400); //index == 3

            Comment


              #7
              Hello EminiTrader,

              Thanks for your note.

              It would be possible to add a secondary data series to the script based on a user input variable since this would not be considered dynamically adding a data series. Please see the attached example script which demonstrates this. In the example script, check for the user input and add a secondary series based on that input. We then print out BarsInProgress and BarsPeriodType within OnBarUpdate() to see that the secondary series is added and processing.

              See the help guide documentation below for more information.
              BarsInProgress - https://ninjatrader.com/support/help...inprogress.htm
              BarsPeriod - https://ninjatrader.com/support/help...barsperiod.htm

              Please let us know if we may assist further.
              Attached Files
              <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


                #8
                Thanks Brandon!!

                Comment


                  #9
                  Originally posted by NinjaTrader_BrandonH View Post
                  Hello EminiTrader,

                  Thanks for your note.

                  It would be possible to add a secondary data series to the script based on a user input variable since this would not be considered dynamically adding a data series. Please see the attached example script which demonstrates this. In the example script, check for the user input and add a secondary series based on that input. We then print out BarsInProgress and BarsPeriodType within OnBarUpdate() to see that the secondary series is added and processing.

                  See the help guide documentation below for more information.
                  BarsInProgress - https://ninjatrader.com/support/help...inprogress.htm
                  BarsPeriod - https://ninjatrader.com/support/help...barsperiod.htm

                  Please let us know if we may assist further.
                  Thanks for this Brandon. Using the AddDataSeriesIndicator, the strategy does run on backtesting, but will not run on Optimizing. Any idea why?
                  Thanks!

                  Comment


                    #10
                    Hello aaadetos,

                    Thanks for your note.

                    When implementing the code from the previously attached indicator, UserInputAddDataSeriesIndicator, into a modified version of the SampleMACrossover strategy, I am able to see prints in the NinjaScript Output window for the different BarsInProgress values in the script when running an Optimization. See the attached script that I used to test this.

                    Please add prints to your strategy that print out the BarsInProgress value and the BarsPeriod.BarsPeriodType in your script. The prints would look something like this.

                    Print ("BarsInProgress: " + BarsInProgress+ " BarsPeriodType: "+ BarsPeriod.BarsPeriodType);

                    Do you see prints for the primary series (BarsInProgress 0) and the added series (BarsInProgress 1)?

                    Do you see any error messages displaying when running an optimization on your strategy?

                    Note from the help guide "the AddDataSeries(string instrumentName) overload allows loading a different instrument yet using the same BarsPeriod. This could not be supported for Strategy Analyzer use with the 'Optimize Data Series' option enabled, doing so may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."

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

                    I look forward to assisting further.
                    Attached Files
                    <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


                      #11
                      Hey guys,

                      is there a way to add a secondary series only in a specific instance? Lets say it shall only add the series if BarsTypePeriod == Minute and only if BarsTypePeriod.Minute <= 5

                      Greetings

                      Comment


                        #12
                        Hello seykool,

                        Thanks for your note.

                        Unfortunately, it would not be possible to add a secondary data series in the manner you described.

                        You could consider adding a secondary data series to the script based on a user input variable. Please see the script in post #7 which demonstrates this.

                        Let us know if we 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


                          #13
                          Hi Brandon,

                          yep I saw it. Great help!

                          Greetings

                          Comment

                          Latest Posts

                          Collapse

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