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

Indicator creating Secondary series with BarsToLoad isn't processing historical data

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

    Indicator creating Secondary series with BarsToLoad isn't processing historical data

    I am creating an indicator which adds a secondary data series that has a daily period and a different # of bars to load than the primary data series. I create an indicator using the secondary data series, but that indicator is not getting OnBarUpdate for the historical data of the secondary data series.

    Consider the following code.

    Code:
    class SomeIndicator: Indicator
    {
        protected override void OnStateChange()
        {
            switch(State)
            {
                case State.SetDefaults:
                    //...
                    break;
                case State.Configure:
                    {
                        var barsPeriod = new BarsPeriod() { BarsPeriodType = BarsPeriodType.Day, Value = 1, MarketDataType = MarketDataType.Last };
                        AddDataSeries(Instrument.FullName, barsPeriod, 30, Instrument.MasterInstrument.TradingHours.Name, null);
    
                        sma = SMA(BarsArray[1], 14);
                    }
                    break;
            }
        }
    
        protected override void OnBarUpdate()
        {
            if(BarsInProgress == 0)
            {
                Print("Bar " + CurrentBars[0]);
    
                if(CurrentBars[1] > sma.Period)
                {
                    for(int i = 0; i < CurrentBars[1]; i++)
                    {
                        // Cannot execute this code because despite CurrentBars[1] being 27, sma[0] is not valid (let alone any additional values)
                        //Print("SMA " + sma[i]);
                    }
                }
            }
            else if(BarsInProgress == 1)
            {
                Print("Daily Bar " + CurrentBars[1]);
            }
        }
    
        SMA sma;
    }
    If I apply SomeIndicator to a 1 minute chart that loads 2 days of historical data I should see the following I do see bars printed for both series with the Daily Bar going up to 28. However I am unable to access the values for sma. If I debug OnBarUpdate of SMA I see that it gets called for the primary data series, but not daily data for the series that it is fed.

    How do I get sma to be populated with the 27 days of data that its data series has?

    #2
    Hello ntbone,

    Thanks for your post.

    From the help guide: "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." Reference: https://ninjatrader.com/support/help...dataseries.htm

    So you would need in this case the chart bars days to load to be sufficient for your daily bars.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I read that in the help guide. It says the "first added series". In my case the "first added series" is the daily bars with 30 days, so if I add another series I won't get more then 30 days.

      Further, if you look at the output of the print statements, all 30 bars do get processed in OnBarUpdate from the daily bar series. The problem is that the sma indicator itself has OnBarUpdate called for the primary data series, and not the Secondary Data series, even though the Secondary Data series is what is fed to it.

      Comment


        #4
        Hello ntbone,

        Thanks for your reply.

        Please instantiate the SMA in State.Data.Loaded (or State.Historical).
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by sephichapdson, Today, 11:36 PM
        0 responses
        1 view
        0 likes
        Last Post sephichapdson  
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,612 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Working...
        X