Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adding Sufficient Daily Data Series to Indicator on 1 Minute Chart.

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

    Adding Sufficient Daily Data Series to Indicator on 1 Minute Chart.

    I have a 1 minute chart with 30 days of AAPL. Since AAPL doesn't trade on the weekends, there will be approximately 20 days of one minute data, depending on the 30 days picked.

    In my Indicator I want to have at least 10 bars of the SPY for the first 1 minute bars processed by the indicator.

    Code:
        var dailyPeriod = new BarsPeriod()
        {
            BarsPeriodType = BarsPeriodType.Day,
            Value = 1,
            MarketDataType = MarketDataType.Last
        };
    
        AddDataSeries("SPY", dailyPeriod, 10, "Default 24x7", null);
    I end up with only 10 bars of daily data, but 20 days of 1 minute data. The 10 days of data will be from the "current" day which is the last day of the date range.

    If I am viewing January 1st to January 30th the daily bars will only be from ~the 15th of January to the 30th.

    In order to make sure I have at least 10 days of data prior to processing January 1st on the one minute chart, I will need to figure out how many trading days there are the date range, then add 10 more bars to that value and I need to do all this in State.Configure.

    This gets even more complicated if I change the range of the chart. I could be looking at 5 minute bars and looking at 90 days. Now I will need # of trading days in 90 days + 10.

    How can I calculate this value in State.Configure?

    Why doesn't the barsToLoad parameter base it off the first bar of the chart, instead of the last?

    #2
    For anyone looking for the answer, it appears that
    Code:
    ChartControl.PrimaryBars.Properties.DaysBack
    will give you an answer that is more then what you need, but gets you in the ball park.

    This also won't work unless the indicator is used directly on a chart. If used from another indicator, the ChartControl will be null.
    Last edited by ntbone; 02-03-2021, 03:22 AM.

    Comment


      #3
      Hello ntbone,

      Thanks for your post.

      Using ChartControl.PrimaryBars.Properties.DaysBack may work in several cases but as this would involve accessing information based on data/user input, and as you notice, the reference would not be guaranteed in State.Configure.

      Dynamically adding data series based on data loaded or user defined inputs is not fully supported, so the recommendation would be to load enough data that will satisfy the needs for any other data series that must be added.

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

      barsToLoad would be used to request a specific number of bars, not to be confused with adding bars before the starting bar in the data series.

      We look forward to assisting.
      Last edited by NinjaTrader_Jim; 02-03-2021, 08:59 AM.

      Comment


        #4
        Can you explain more as to why this is not supported? What possible issues may I find by trying to load it.

        As an example of a use case for what I am doing. suppose I want to be sure I have a valid moving average value for the additional data series I add to my indicator. This requires that data series having at a minimum, the additional bars required to calculate the moving average. Since the first bar processed is defined by the user when they set up the chart, its impossible to predict the value needed to ensure that additional data series has enough bars to provide that moving average. This issue is significantly more problematic with that series being a day series for a 1 minute chart.

        One option would be to not specify the bars to load, but then I would require a large # of data to be loaded to potentially do the any processing. In the case of say a 20 period moving average on daily chart and one minute chart for the indicator, I would need at least 20 trading days worth of minute data before I'd even be able to process one bar.

        Comment


          #5
          Hello ntbone,

          While we have been able to dynamically add data in many cases since NinjaTrader 7, this was never 100% supported. Issues can be specifically seen when running optimizations and you will generally see an error message when trying to do so "Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner."

          The option you describe would be the fully supported way forward. We do not want to discourage trying what you are doing, but If you encounter any issues trying to dynamically add data based on User Input or the primary data series, we suggest testing hard coded data series before performing any other troubleshooting.

          Although this will not change the data loaded, something else to consider would be to check the bars of your added data series in State.DataLoaded to see where the starting bars are, and you could use the bar indexes of those starting bars with CurrentBar checks in OnBarUpdate to prevent processing on unnecessary bars. The performance gain here may be permissible and it may be easiest just to load enough data to satisfy the secondary data series. In State.DataLoaded, we can reference bars with the following:

          Code:
          for (int i = 0; i < BarsArray[0].Count-1; i++)
              Print( BarsArray[0].GetTime(i));
          We look forward to assisting.

          Comment


            #6
            Thanks. For now, if the ChartControl is available I plan to generate the parameter for bars to load and will see if I experience issues as described.

            The ideal way for me moving forward would be if bars to load was based on the first bar of the primary data series. This way the indicator will always have the required additional data it needs to process the first bars bars of the primary data series. Waiting until there's enough data on additional data series that has a bigger period than the primary data series would require a lot more of the primary data series to pass before processing could be executed.

            Comment


              #7
              One scenario where a ChartControl is not existent is immediately after adding the indicator to a chart for the first time. ChartControl seems to be set at some later state then State.Configure. Without the ChartControl, one cannot determine the approximate range of the chart. Additionally, using the ChartControl's range to determine the # of daily bars to load may result in more days loaded then are needed. This can happen if there are insufficient minute bars for the range requested.

              Can a feature request be created to have BarsToLoad for AddDataSeries be be based on the first bar instead of the current bar? Having this be a fixed # makes it difficult to show proper historical behavior for an indicator that uses AddDataSeries.

              Comment


                #8
                Hello ntbone,

                I have submitted a request to have barsToLoad start from the starting point of the primary data series as opposed to from the current time on the chart.

                The ticket ID is SFT-5182. This is an internal number, but for anyone else wishing to have their interest tracked, please let our support staff know that you would like a vote added for this request.

                Feature/Enhancement 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

                We look forward to assisting.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                576 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
                553 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