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

Accessing data from a hosted indicator

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

    Accessing data from a hosted indicator

    Hello,
    I am having trouble accessing some data from a hosted indicator. The hosted indicator has some signals, let’s call them Signal A, and these occur on bar[1], as they can only be confirmed when there is not a similar signal on bar[0]. On the hosted indicator I have written a series bool to show when Signal A occurs at bar[1], and my output window shows it to be true on the correct bars. I have included the series bool in the properties region so that I can access it from a hosting indicator.
    In the hosting indicator, I have defined the hosted indicator and included any additional data series from the hosted indicator. I have then set up some code so that when Signal A is true in the hosted indicator, a separate series bool in the hosted indicator should also be true (then I will be able to combine with other signals in the hosting indicator to give a further signal – this part is not important for now). All compiles OK, but the series bool in the hosting indicator is always showing false, even on bars that the hosted indicator series bool show to be true. Any ideas as to how I resolve this would be welcomed. Thank you.
    Code:
    if(BMTCMA00.SignalA[1]==true) 
    //        {
    //             gapA[1]=true;
    //        }

    #2
    Hello GeorgeW,
    Thanks for your post.

    Is the above snippet what you are using in your code? Commented out that way?

    Can you show us more code for both of these scripts?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your response, Josh.
      The code is not commented out. Below is a snippet of the code in the hosting indicator.
      Code:
      public class MainConfirmDir05 : Indicator
          {
               #region Variables
              //#########################################################################################
      private BMTCMAStochastics18 BMTCMAStochastics00; 
                      private Series<bool> gappedAU;
      
              //#########################################################################################
              #endregion
      
      else if (State == State.DataLoaded)
                  {
      BMTCMAStochastics00            = BMTCMAStochastics18(FastLimit, SlowLimit);
      gappedAU = new Series<bool> (this);
      }
      
      OnBarUpdate
      #region variables
      
      gappedAU[0] = false;
      
      #endregion
      
      if(BMTCMAStochastics00.GappedAUSignal[1]==true) 
              {
                  gappedAU[1]=true;
      
              }

      Comment


        #4
        GeorgeW,

        That code does not compile for me. Tough to say what's going on in your script without having compilable samples. If gappedAU is what you are trying to access in the other indicator, perhaps it is because the series is not public.

        The following snippets allowed me to set a boolean value in one indicator and then retrieve that value in another.

        Code:
        public class Test1 : Indicator
        {
            public Series<bool> testBool;
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name = "Test1";
                    Calculate = Calculate.OnBarClose;
        
                }
                else if (State == State.DataLoaded)
                {
                    testBool = new Series<bool> (this);
                }
            }
        
            protected override void OnBarUpdate()
            {
                if(CurrentBar<1)return;
        
                if(Open[0]>Close[0])
                    testBool[0] = true;
            }
        }
        and the calling indicator:

        Code:
        public class Test2 : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name                                        = "Test2";
                    Calculate                                    = Calculate.OnBarClose;
                }
            }
        
            protected override void OnBarUpdate()
            {
                Print(AAATest1().testBool[0]);
            }
        }
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,
          I have taken a further look at the indicators, and the problem is occurring because of the resetting of gappedAUSignal[0] = false; in the host indicator. If it is not reset to false, then some of the signals at bar[1] identified in the host indicator are incorrect. I note that you did not do a reset in your example. But if I do not do the reset, then the hosting indicator does pick up changes to gappedAUSignal[1] from the host indicator and changes from false to true on the same bars, albeit that some of them are wrong for the reason I have explained before. So it seems that where I place the reset may be the solution. Have you any ideas about that? Thanks.

          Code:
          [LIST][*]
           [B][B]OnBarUpdate #region variables  gappedAUSignal[0] = false;  #endregion[/B][/B][/LIST]

          Comment


            #6
            I have resolved the issue, and the indicators are now working as expected. Although the signal in the host indicator is on BarsAgo[1], it can only be true if there is no signal on BarsAgo[0]. So instead of setting gappedAUSignal[1] = true; when a signal occurs, I should have set gappedAUSignal[0] = true; and then that is what I should draw into the hosting indicator. Thanks for the help.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by rocketman7, Today, 02:12 AM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by briansaul, Today, 05:31 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by PaulMohn, Today, 03:49 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by frslvr, 04-11-2024, 07:26 AM
            6 responses
            106 views
            1 like
            Last Post NinjaTrader_BrandonH  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            6 responses
            26 views
            0 likes
            Last Post trilliantrader  
            Working...
            X