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

Error : A hosted indicator tried to load additional data. All data must first be load

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

    Error : A hosted indicator tried to load additional data. All data must first be load

    I have developed a 2 instrument indicator that loads DJIA in addition and compares its performance with the performance of a stock.

    When I try to call this indicator from within a strategy, I get the following error :

    "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state"

    the DJIA in the indicator is loaded within Configure state; the error doesn't make sense to me.

    else if (State == State.Configure)
    {
    AddDataSeries("^DJIA", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);

    }

    What is this error mean ?

    #2
    Hello afshinmoshrefi,

    The error indicates that the dataseries was not also added to the Strategy that called this.

    From the help guide:
    "Prevention of Redundant Data Loading
    In NinjaTrader 7, multiple Data Series could be added within a script, such as an indicator, and that script could then be hosted by another script, such as a strategy. While this is still possible in NinjaTrader 8, there is a new safeguard in place to prevent redundant data loading in both the hosting script and the hosted indicator.

    When hosting an indicator which adds Data Series programmatically, the hosting script must include the same calls to the AddDataSeries() method as the hosted script. Without this, an error will result, which reads "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its Configure state." Without this safegaurd in place, it would be possible for unnecessarily large amounts of data to be loaded concurrently, as would be the case in a direct call to an indicator method on each OnBarUpdate(). By adding the calls to AddDataSeries() to the hosting script, you can ensure that the data is loaded when needed. Also, when this is done in the hosting script, all identical calls to AddDataSeries() in the hosted script will be ignored, as the data is already available."
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I am getting the same message. How can I make sure all the data is being loaded that the indicator needs.

      Comment


        #4
        I fixed the issue by making sure that the same data series are loaded in both indicators. Indicator 1 was calling Indicator 2.

        Comment


          #5
          Hello [email protected],

          Thanks for your note.

          afshinmoshrefi is correct. Any call to AddDataSeries() done in one indicator, must also be added to any script calling that indicator.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            I only have one indicator and it gives me this message. How can I make sure that the data required is being loaded for the indicator. I have tried to change BarsToLoad and DaysToLoad without success.

            Comment


              #7
              Hello [email protected]

              Are you certain the error you are getting is:
              "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its Configure state."

              Your script does not call any other indicators at all anywhere in the script?

              Changing the amount of data loaded will not correct this error.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Yes that is the exact message I am getting. My script does call other indicators but one indicator does not depend on the other. The Indicator that is causing me the problem is the Pivot. I am using a multi-instrument strategy. I have tried to add additional time frames but have not gotten that to work.

                Comment


                  #9
                  Hello [email protected],

                  Originally posted by [email protected] View Post
                  My script does call other indicators but one indicator does not depend on the other.
                  This is incorrect. Any indicator you call from a script is dependent on that script.
                  (Try removing an indicator that is being called from another script through the NinjaScript Editor. You will not be able. If you manually remove an indicator that is called by another script, this will cause that script to error and it will not compile.)

                  You must add the all of the AddDataSeries calls to all scripts that call any indicator that adds a secondary series.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    I am trying to get Pivots on a 2 minute time frame. I was told that I needed to create another dataseries a Daily. I have tried many variations of this but have not been able to work. Because of what you mentionI have gone back to the example give me and I am getting the error Index is out of range. Its not creating the object for BarsInProgress #1 and the 0 gets an object but no data.
                    PROGRAM OUTPUT
                    BarsInProgress=0
                    Pivot=#00 0BarsInProgess=0

                    THE ERROR BEING:
                    Strategy 'test1': Error on calling 'OnBarUpdate' method on bar 1: You are accessing an: index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

                    PROGRAM LOOKS LIKE THIS

                    elseif (State == State.Configure) {
                    //Entered from screen
                    AddDataSeries(BarsPeriodType.Day, 1);
                    //Additional instruments
                    AddDataSeries("AAPL", BarsPeriodType.Minute,2);
                    AddDataSeries("AAPL", BarsPeriodType.Day, 1);
                    AddDataSeries("AMD", BarsPeriodType.Minute, 2);
                    AddDataSeries("AMD", BarsPeriodType.Day, 1);

                    CurrentDayOHL1 = CurrentDayOHL() ;
                    }

                    else if (State == State.DataLoaded) {
                    Pivots0 = Pivots(BarsArray[0], PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20);
                    Pivots1 = Pivots(BarsArray[1], PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20);
                    Pivots2 = Pivots(BarsArray[2], PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20);
                    Pivots3 = Pivots(BarsArray[3], PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20);
                    Pivots4 = Pivots(BarsArray[4], PivotRange.Daily, HLCCalculationMode.CalcFromIntradayData, 0, 0, 0, 20);
                    Pivots5 = Pivots(BarsArray[5], PivotRange.Daily, HLCCalculationMode.DailyBars, 0, 0, 0, 20);
                    }
                    }
                    protected override void OnBarUpdate()

                    { //Print("print#1");
                    if ((CurrentBars[0] < 1) && (BarsInProgress != 1))
                    return;
                    Print("BarsInProgress=" + BarsInProgress);

                    Print("Pivot=#0" + Pivots0.R1[0] + " " + Pivots0.Pp[0] + "BarsInProgess=" + BarsInProgress);
                    Print("Pivot=#1" + Pivots1.R1[0] + " " + Pivots1.Pp[0] + "BarsInProgess=" + BarsInProgress);
                    Print("Pivot=#2" + Pivots2.R1[0] + " " + Pivots2.Pp[0] + "BarsInProgess=" + BarsInProgress);
                    ANY HELP GIVEN WOULD BE APPRICATED!

                    Comment


                      #11
                      Try skipping the first 2 bars before start processing :

                      protected override void OnBarUpdate()
                      {
                      if (CurrentBars[1] < 2) return;



                      you may need to skip more than 2 bars based on how your are processing.

                      Comment


                        #12
                        Thank you! It seems that worked. when I tried to do it for all the instruments It gave me the same message again. Here is what I put in.

                        if (CurrentBars[BarsInProgress] < 10)
                        return;
                        Print("BarsInProgress=" + BarsInProgress);

                        Print("Pivot=#0" + Pivots0.R1[0] + " " + Pivots0.Pp[0] + "BarsInProgess=" + BarsInProgress);
                        Print("Pivot=#1" + Pivots1.R1[0] + " " + Pivots1.Pp[0] + "BarsInProgess=" + BarsInProgress);
                        Print("Pivot=#2" + Pivots2.R1[0] + " " + Pivots2.Pp[0] + "BarsInProgess=" + BarsInProgress);
                        Print("Pivot=#3" + Pivots2.R1[0] + " " + Pivots3.Pp[0] + "BarsInProgess=" + BarsInProgress);
                        Print("Pivot=#4" + Pivots2.R1[0] + " " + Pivots4.Pp[0] + "BarsInProgess=" + BarsInProgress);
                        Print("Pivot=#5" + Pivots2.R1[0] + " " + Pivots5.Pp[0] + "BarsInProgess=" + BarsInProgress);

                        Comment


                          #13
                          The issue would be the same. You are trying to access a bar in one of the time-frames that has not occurred yet. If you skip more bars it would probably work.

                          Comment


                            #14
                            I have remove 60 bars without success. I need to process only 2 minute time frames. Do you know how to select that in OnBarsUpdate. If its a minute or day time frame?

                            Comment


                              #15
                              If you are using Minute and day time-frame you have to take into account how many minutes are there in 1 day. If you are trading stocks or related indexes there would be 390 minute bars in every 1 day bar. If you are trying to skip 2 day bars, you have to skip 780 minute bars or 2 day bars. Make sure you are skipping the correct time frame bars..

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,414 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X