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

Loading additional data within an indicator from indicator

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

    Loading additional data within an indicator from indicator

    I'm just looking for some clarification from a NT8 guru.

    I have an indicator that I wrote that calls another indicator from a third party. The third party indicator is locked- I don't have access to the code but it has a number of outputs that I call from within my indicator.

    When I call a particular output I receive this error in the NT output window.
    A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state.
    I've done some online digging and found some references to this error. It seems that I need to call my AddDataSeries in all indicators. In my indicator I call two data series in addition to the primary data series.
    AddDataSeries(BarsPeriodType.Tick, secondticksize); //Adds the DataSeries for second time frame.
    AddDataSeries(BarsPeriodType.Tick, thirdticksize); //Adds the DataSeries for third time frame.
    To clarify. Do I need to add the same AddDataSeries to the third party (locked) indicator as well? Also, is my indicator the "host" indicator or is the third party indicator the host?
    I have my AddDataSeries in the 'State == State.Configure' section.

    Thank you in advance.

    #2
    Hello fling_wing, and thank you for your question.

    The third party indicator is responsible for adding its own data series. If you add a data series using the methods you showed, it would be added to the outer indicator or strategy, not the locked indicator called from your indicator or strategy.

    If you have a simplified code sample you could share, which does not have any of your proprietary logic, and does call another locked indicator or strategy the same way yours does, I would be happy to review this indicator or strategy and make further recommendations.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply, Jessica.

      I could create some sample code but will take me a little time to do it so that it displays the same error. Also, the locked indicator has an installer (not a cut and paste into Indicators folder) so it all gets a bit fridley
      Do you have an email I can send the files to rather than post publicly?

      In the mean time. Just to get it through my thick head. I can't access the locked indicator code so couldn't add anything to it anyway. Is there a possible way around this error without having to access the locked indicator code? If there isn't, it isn't really worth us going any further. (Don't want to waste your time)

      Comment


        #4
        Of course. Please e-mail platformsupport[at]ninjatrader[dot]com , and please include this number in the body of your e-mail :
        1537455

        It is possible that your indicator has made some of its variables public. You could try

        indicatorInstance.Add(/* your arguments here*/);

        It is possible you will get an access violation doing that, but it is always worth a shot.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Email sent. Thanks Jessica.

          Am happy to post the solution once we know it on the grounds it may help others.

          Comment


            #6
            Hello fling_wing,

            Thank you for sending me that code sample.

            I am going to summarize the changes I made to defeat the access protection surrounding the locked indicator's method for adding data series . Defeating access protection is not recommended in production code; a better solution is to reach out to the vendor of this product and ask them to create a supported method for adding data series to their indicator, and to prevent the behavior you were seeing. They should be made aware of this support ticket, and would likely appreciate your logs.

            However, for quality analysis and development, defeating access protection around seams is a viable and important tool commonly used in industry, even when full access to the source is made available, as it preserves the state of the device under test. Further, this helps both us and the vendor of your product determine exactly what the cause of the behavior you were seeing is. In our case, since this compiles and runs cleanly, we have determined there is not a flaw in NinjaTrader causing what you were observing, and the vendor will have some good clues available to repair their product.

            Summary follows :

            Code:
            [FONT=Courier New]    /// <summary>
                /// Allows us to cheat IndicatorName's access restrictions
                /// </summary>
                private class IndicatorNameWrapper : IndicatorName
                {
                  public IndicatorNameWrapper(IndicatorName source)
                  {
                    // Decide what to shallow copy here
                  }
            
                  public void AddDataSeriesWorkaround(BarsPeriodType periodType, int tickSize)
                  {
                    AddDataSeries(periodType, tickSize);
                  }
                }
            [/FONT]
            Code:
            [FONT=Courier New]
            IndicatorNameWrapper instanceName = new IndicatorNameWrapper(IndicatorName(args));
            instanceName.AddDataSeriesWorkaround(BarsPeriodType.Tick, tickSize);[/FONT]
            Please let us know if there are any other ways we can help.
            Jessica P.NinjaTrader Customer Service

            Comment


              #7
              Just to conclude this thread for now. Jessica, thank you very much for your time and expertise during our email conversations regarding this subject matter. I learnt a lot.

              I have contacted the vendor of the 'locked' indicator. They have advised that I need to add a 1 tick DataSeries to my indicator that's calling theirs.
              Evidently the locked indicator requires the 1 tick for it's calculations.
              The down side to doing this is that adding 1 tick to multiple charts really drains the computer resources. I've had Ninja crashing and locking up due to this on multiple charts.
              In my case, I have 3 tick charts open at a time, utilising the NT8 tabs in the same chart window. I've never had a problem with NT7 and these indicators working together so I may have to go back to that NT version.

              This is from the developer.
              NT8 now enforces an indicator calling another indicator to have already loaded all the dataseries the called one needs. NT7 kind of did this on the fly (and not overly reliably). There is no workaround as far as I know, and in any case it is done for reliability, so you probably want it. Just use charts with less lookback, I guess.
              So, I have a solution to my original query but it's created another.

              Not to worry, upward and onward.

              Comment


                #8
                Need help

                I am trying to access data from another indicator

                I have this bit of code that used to work in NT7. Need it to work in NT8

                Indicator indi;

                for (int index = 0; index < ChartControl.Indicators.Count; index++)
                if (ChartControl.Indicators[index].Name == "IndicatorName")
                {
                indi = (Indicator) ChartControl.Indicators[index];
                }

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

                I have the source to both the hosted and hosting indicator. I am at a loss as to how to make the data available to access this data.

                Comment


                  #9
                  Hello zextra, and thank you for your question.

                  What this is telling you is that you need to call AddDataSeries() within the calling strategy's State == State.Configure block. This loads Bars data that the hosted indicator requires. Once the strategy calls AddDataSeries() on the necessary instruments, the hosted indicator's calls to AddDataSeries() will be ignored, and it will use the data obtained by the strategy.

                  Please let us know if there are any other ways we can help.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    Please give an example

                    Thank you for the reply. However, I still don't get it. Could you please provide an example? All these terms hosting, hosted, calling, is very confusing which parts we are talking about. Thank you.

                    Comment


                      #11
                      I am not using any strategies. To clarify:

                      Indicator A has data I want to access in Indicator B

                      Comment


                        #12
                        Thank you for the clarification zextra. All the above applies to indicators as well.

                        I would like to ensure we are working with NinjaTrader 8?

                        If we are, could you send me this block of code, so that I can provide better assistance?

                        Code:
                        [FONT=Courier New]
                        else if (State == State.Configure)
                        {
                            // This block
                        }[/FONT]
                        There should be a block that looks like that in both indicator A and indicator B. Both will help.
                        Jessica P.NinjaTrader Customer Service

                        Comment


                          #13
                          Here is my code

                          Yes, I am trying to get this to work with NT8

                          Code:
                          // This is the indicator A that has the data I want to access from Indicator B
                          		else if (State == State.Configure)
                          		{				
                                      Calculate = Calculate.OnEachTick;
                                      IsOverlay = true;
                                      
                          			// This is a necessary added data series to this indicator since it uses 2 time frames
                          			// The first time frame is whatever Period Type the chart is set to and the second one
                          			// is 1 tick. Hence one AddDataSeries here
                          			AddDataSeries(BarsPeriodType.Tick, 1);
                          
                                      PaintPriceMarkers = false;
                                      IsAutoScale = false;
                                      ArePlotsConfigurable = false;
                          			DisplayInDataBox = true;        
                          			ShowTransparentPlotsInDataBox = true;
                          						
                                      AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Bar, "Size");
                                      AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Bar, "Width");
                          		}			
                          
                          
                          
                          // This is indicator B. I want to access the Plots from indicator A
                                  else if (State == State.Configure)
                                  {			
                                      Calculate = Calculate.OnEachTick;
                                      IsOverlay = true;
                          			IsAutoScale = false;			
                          			PaintPriceMarkers = false;
                          			ArePlotsConfigurable = false;
                          			ShowTransparentPlotsInDataBox = true;
                          			
                          			AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Bar, "Data1");
                          			AddPlot(new Stroke(Brushes.Transparent), PlotStyle.Bar, "Data2");
                                  }
                          		
                          
                          
                          // From indicator B, this is the code that worked in NT7 to access the plots from Indicator A
                          
                          public void foo()
                          {
                          	Indicator indi = null;
                          
                          	for (int index = 0; index < ChartControl.Indicators.Count; index++)
                          		if (ChartControl.Indicators[index].Name == "IndicatorA")
                          		{
                          			indi = (Indicator) ChartControl.Indicators[index];
                          		}	
                          		
                          	
                          	// These are the 2 crucial lines of code that I cannot get to work
                          	// When trying to run this I get:
                          	// "A hosted indicator tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state."
                          	if (blah) return indi.Values[0][0]));		//This gives data from Plot named "Size"
                          	else return return indi.Values[1][0]));		//This gives data from Plot named "Width"
                          }
                          // Please show how I can get this to work for NT8. Thanks in advance!!!

                          Comment


                            #14
                            Thank you zextra. You will need to add this code before you add any other data series to Indicator B's State == State.Configure section.

                            Code:
                            [FONT=Courier New]            AddDataSeries(BarsPeriodType.Tick, 1);[/FONT]
                            Jessica P.NinjaTrader Customer Service

                            Comment


                              #15
                              Interesting, this did not work initially. But after I exposed the values using this example here http://ninjatrader.com/support/forum...ead.php?t=4991, now everything is working. Thank you for your help!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Shansen, 08-30-2019, 10:18 PM
                              24 responses
                              938 views
                              0 likes
                              Last Post spwizard  
                              Started by Max238, Today, 01:28 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by rocketman7, Today, 01:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post rocketman7  
                              Started by wzgy0920, 04-20-2024, 06:09 PM
                              2 responses
                              27 views
                              0 likes
                              Last Post wzgy0920  
                              Started by wzgy0920, 02-22-2024, 01:11 AM
                              5 responses
                              32 views
                              0 likes
                              Last Post wzgy0920  
                              Working...
                              X