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

How to access the value of Days to Load in State.Configure

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

    How to access the value of Days to Load in State.Configure

    I want to do something like this:

    Code:
    else if (State == State.Configure)
    {
    if (Bars.BarsData.DaysBack < 10)
    AddDataSeries(null, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, 10, null, false);
    else
    AddDataSeries(BarsPeriodType.Minute, 1440);
    }
    The purpose is this. If I load 1 day on a 5 minute chart, I want it to load extra daily bars for my daily indicator to work,
    however, if I load 60 days on the 5 minute chart, then I want to follow the number of days from the 5m chart,
    so I need to get the value of the Days to Load in order to know which AddDataSeries to add.

    Thanks in advance!​

    #2
    Hello davydhnz,

    Thanks for your post.

    ChartBars.Properties.DaysBack would return an int representing the Chart's Data Series configured "Days to load" when the RangeType.Days is selected.

    ChartBars: https://ninjatrader.com/support/help.../chartbars.htm
    ChartBars.Properties: https://ninjatrader.com/support/help...properties.htm

    I see you are dynamically adding a data series with the AddDataSeries() method in the code you shared which is not supported.

    AddDataSeries() arguments should be hardcoded and should not be placed within a condition.

    From the AddDataSeries() help guide documentation:

    "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided. Trying to load bars dynamically may result in an error similar to: Unable to load bars series. Your NinjaScript may be trying to use an additional data series dynamically in an unsupported manner.​"

    If you are using the same data series as the primary. You will need to load the number of days for the chart if you use a daily series on the chart. This is expected due to the note on the AddDataSeries page:

    "When adding multiple Data Series of the same instrument and the same Bar Type, the 'barsToLoad' property will only be effective on the first added series. Subsequent series with a different barsToLoad setting will not load a different number of bars then the first series."

    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

    You could see an example of loading more daily bars than the primary series on this forum thread: https://forum.ninjatrader.com/forum/...06#post1150106
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the response NinjaTrader_BrandonH.

      The thing about daily bars is they don't provide the same open and close price as 1440 minute bars.

      If only there was a day to limit the amount of days the chart displays for the primary series while loading more days than the chart displays.

      I found your reply helpful though for planning next steps.

      All the best,

      Davydh

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X