Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting AddDataSeries BarsToLoad from ChartBars

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

    Setting AddDataSeries BarsToLoad from ChartBars

    I'd like to load a secondary data series a bit longer (1day longer) than the primary one, so I tried the following code. (The primary series is 15min)

    else if (State == State.Configure) {
    int daysToLoad = (int)(ChartBars.Bars.ToDate - ChartBars.Bars.FromDate).TotalDays + 1;
    var barsPeriodDay = new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1 };
    var tradingHours = ChartBars.Bars.TradingHours.ToString();
    AddDataSeries(Instrument.FullName, barsPeriodDay, 11, tradingHours, null);
    }

    But, the first time I enables the code, the following null reference exception occurred. ( I re-enables it on the same chart, it works fine.)

    Error on calling 'OnStateChange' method: Object reference not set to an instance of an object.

    I know that in "Best Practice" section, we should wait using ChartBars until the state has reached State.Historical, but on the other hand, AddDataSeries must be call in State.Configure. So is there any way to achieve this properly ?

    #2
    Hello tmk-c,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    Pulling the primary series in the Configure State is not permitted as the data would not be available. You would need to either hard code the barsToLoad or even use a user defined int for the barsToLoad.

    This restriction is detailed at the following link: http://ninjatrader.com/support/helpG...dataseries.htm

    Please let me know if you have any questions.

    Comment


      #3
      Hello Patrick,

      Thank you for your reply. Is there any possibility to achieve this by using BarsRequest ? I don't know much on how to use BarsRequst at this time, but is it worth spent time to dig into it ?

      Comment


        #4
        Hello tmk-c,

        Thank you for your response.

        Using the BarsRequest you would still need a value for the barsBack or DateTime value. Essentially this would require the same matter of using hard coded or user defined variables.

        Please let me know if you have any questions.

        Comment


          #5
          Hello Patrick,

          Thank you for the clarification. I would use user defined variables.

          Thanks.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          43 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          48 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X