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

Additional tick data series when chart period is set to bars

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

    Additional tick data series when chart period is set to bars

    Hello,

    In some of my code, I add an additional data series of the 1 tick type to access the bar historical tick data, like this

    AddDataSeries( Data.BarsPeriodType.Tick, 1);

    Which works fine. One issue though - If the chart period type is set to bars, rather than days, the data series does in fact only load that many 1 tick bars, instead of enough ticks to fill the primary data series bars (which is what would have made more sense to me). It does not seem possible to say, load 1 day minimum of tick data with the addserries() function, if the primary series is set to load, say, 500 bars?

    Is there a simple workaround for this, or am I missing something? I am looking to have enough 1 tick bars to always cover the primary series range. Thanks.

    #2
    Hello pjsmith,

    Thanks for your post.

    Correct, when adding further data series to your script they will automatically load the same data length as the series of the chart so yes if the chart series has a specified number of bars then any added dataseries would only load that many bars.

    The only option, if you are unable to change your charts data series, would be to use the AddDataseries() overload that allows you to specify the number of bars to load but then this would require you to know the number of tick bars in your desired period or perhaps estimate.

    Please note that the AddDataseries() overload that uses the int barsToLoad has this consideration, "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 than the first series."
    Reference: https://ninjatrader.com/support/help...dataseries.htm
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Read the warnings in the AddDataSeries() help text about using dynamically loading dataseries.

      The approach below is for a specific situation for an indicator indicator which is only designed to work on a 1 second primary dataseries.

      The problem being solved here is when the primary data series was loaded by bars and not days there was not enough of the secondary series being loaded. So loading 1000 second bars in the primary resulted in 1000 ticks being loaded in the secondary. Not enough. The solution is in the "else" construct. Loading 100 ticks per second loads enough data to satisfy the requirements.

      If more than 5000 would mean the primary data is being loaded by days and so the secondary series will have an equal time period.

      Code:
      [FONT=Courier New]if (Bars.Count > 5000)
      {
          AddDataSeries(Data.BarsPeriodType.Tick, 1);
      }else{
          string Inst=Instrument.ToString(), Hrs=Bars.TradingHours.Name;
          BarsPeriod BpTick=new BarsPeriod { BarsPeriodType = BarsPeriodType.Tick, Value = 1 };
          AddDataSeries(Inst, BpTick, Bars.Count*100, Hrs, Bars.IsResetOnNewTradingDay);
      }[/FONT]

      Comment


        #4
        Hello Bidder,

        The issue here would be this is not officially supported. The branching conditional command (the if statement) is dynamic. Dynamically loading series can cause issues. (Using variables, instead of hard coded values would also be dynamic)

        From the help guide:
        "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."



        There is a feature request for a DaysToLoad overload for AddDataSeries(), tracked with ID# SFT-4583, I will be happy to add your vote toward.

        In the meantime, I'm not aware of a good workaround other than using Days to load for the primary series.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by pibrew, Today, 06:37 AM
        0 responses
        0 views
        0 likes
        Last Post pibrew
        by pibrew
         
        Started by rbeckmann05, Yesterday, 06:48 PM
        1 response
        12 views
        0 likes
        Last Post bltdavid  
        Started by llanqui, Today, 03:53 AM
        0 responses
        6 views
        0 likes
        Last Post llanqui
        by llanqui
         
        Started by burtoninlondon, Today, 12:38 AM
        0 responses
        10 views
        0 likes
        Last Post burtoninlondon  
        Started by AaronKoRn, Yesterday, 09:49 PM
        0 responses
        15 views
        0 likes
        Last Post AaronKoRn  
        Working...
        X