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

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 Christopher_R, Today, 12:29 AM
          0 responses
          6 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,235 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          3 views
          0 likes
          Last Post thread
          by thread
           
          Started by jclose, Yesterday, 09:37 PM
          0 responses
          7 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,415 views
          0 likes
          Last Post Traderontheroad  
          Working...
          X