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 funk10101, Today, 12:02 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by GLFX005, Today, 03:23 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by nandhumca, Yesterday, 03:41 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by The_Sec, Yesterday, 03:37 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by vecnopus, Today, 06:15 AM
          0 responses
          1 view
          0 likes
          Last Post vecnopus  
          Working...
          X