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

Addition Data Series

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

    Addition Data Series

    Hi,

    I would the user to add multiple data series in a chart using the ninja script properties. When I have the user add the data series via

    I getting error mesage: "OnBarUpdte method on bar 0: you are accessing an index with a value that is invalid since it is out of range.

    Not sure what I am doing wrong.

    Code:
    else if (State == State.Configure)
    {
        AddDataSeries(symbol2, BarType2, Period);
    }
    
    
    [NinjaScriptProperty]
    [Display(Name = "Symbol2:", Description = "Enter instrument symbol", Order = 70, GroupName = "13-1 Instrument Analytics")]
    public string symbol2 
    { get; set; }
    
    [NinjaScriptProperty]
    [TypeConverter(typeof(NinjaTrader.Gui.Tools.BarsPer iodTypeSelector))]
    [Display(Name = "Chart Type", Description = "Select Time Frame Type", Order = 71, GroupName = "13-1 Instrument Analytics")]
    public BarsPeriodType BarType2
    { get; set; }
    
    [NinjaScriptProperty]
    [Display(Name = "Period", Description = "Select Time Frame Type", Order = 72, GroupName = "13-1 Instrument Analytics")]
    public int Period
    { get; set; }

    #2
    Hello bjunaid,

    Thanks for your post.

    What happens when you have multiple data series is that each data series will call the OnBarUpdate(). This means for example if the 4th series calls OnBarUpdate() and the code tries to reference a value in another series that has not loaded or another bar before the first bar, you will get that indexing error. You would need to ensure that all data is loaded before trying to process it. A common approach is through the check of the Currentbars[barsArray], Reference: https://ninjatrader.com/support/help...urrentbars.htm

    You may want to also review: https://ninjatrader.com/support/help...nstruments.htm

    Note: We do not recommend dynamically adding data series. From the help guide: "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." Reference: https://ninjatrader.com/support/help...dataseries.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hi Paul,

      I want the user s to be able to enter the data series from the properties menu. How can I do this safely and accurately?

      Comment


        #4
        hello bjunaid,

        Thanks for your reply.

        The help guide is pretty clear that we cannot support dynamic allocation.

        What you could do is hardcode all of the data series needed and then through the UI logic, allow the user to select which one to use and then use that logic to process in your coding.

        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          Wouldn't that take an incredible amount of processing power.

          If I have 10 data series added with multiple time frames. I have user select a security which I then set using using an if statement switch statement.

          Would you be able to provide an example of something similar?

          Comment


            #6
            Hello bjunaid,

            Thanks for your reply.

            Certainly, it would load up quite a bit.

            I have no examples of something similar.

            Can you elaborate more about what you are trying to do as perhaps there is another solution?

            Why are you having the user select an instrument, bar type, and period, which I assume are different than the chart series?

            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hi Paul,

              I want the strategy to compare instrument with another instrument(s) through properties drop down menu before entering into the position to determine if it matches certain conditions. The objective is to be able to easily backtest and optimize the strategy without having to change or tweak the code every time. I don't expect the user to select a different BarType everytime but it made more sense to just use the BarTypes already defined within Ninjatrader.

              Here is what I have so far:

              Click image for larger version

Name:	Capture2.jpg
Views:	199
Size:	112.0 KB
ID:	1130441



              Thanks,


              Comment


                #8
                Hello bjunaid,

                Thanks for your reply.

                Regrettably, I can offer no solution that would be 100% supported, back testable, and optimizable other than to hardcode as mentioned but I certainly understand your concerns and the limitation this provides. Currently, with your coded intention, you would be able to access any instrument, time frame, and supported bar type. Perhaps there is a compromise where you can offer a limited selection of comparables that can be hardcoded.

                You are of course free to use unsupported approaches but you may or may not run into situations where the script will not work as intended. If you are experiencing issues dynamically adding data, we ask that the code gets reverted to being hardcoded before asking for support.

                I will create a feature request to support dynamically adding data series. If a feature request for this already exists, your vote will be added to it. In either case, I will update this thread with that feature request number.

                Feature Request Disclaimer.
                We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing.
                When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number will be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.
                Release Notes - https://ninjatrader.com/support/help...ease_notes.htm
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Hello bjunaid,

                  Just to follow up on the feature request.

                  The feature request has been identified as SFT-5152, "Ability to dynamically add multiple data series to a strategy based on user selections".

                  Feature Request Disclaimer.
                  We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing.
                  When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number will be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.
                  Release Notes - https://ninjatrader.com/support/help...ease_notes.htm
                  Paul H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Waxavi, Today, 02:10 AM
                  1 response
                  16 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by Kaledus, Today, 01:29 PM
                  5 responses
                  13 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by Waxavi, Today, 02:00 AM
                  1 response
                  12 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by alifarahani, Today, 09:40 AM
                  5 responses
                  23 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by gentlebenthebear, Today, 01:30 AM
                  3 responses
                  17 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X