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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          43 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          21 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          30 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          50 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          41 views
          0 likes
          Last Post CarlTrading  
          Working...
          X