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

How to access another indicators configurable properties

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

    How to access another indicators configurable properties

    I have indicatorA with several properties that are user configurable via its indicator panel. I have another indicatorB that wants to use some of the same settings and I don't want the user to have to set the properties in both places.

    From indicatorB, when I code IndicatorA().PropertyName from within onbarupdate(), I get the original default value as set in indicatorA variable section and not the value the user set via indicatorA's dialog.

    I use configurable properties all the time and the work great when only reference by the indicator that set them.

    Is there a way to get the value the user has set in the dialog from another indicator?


    Code:
     
    ///****IndicatorA
     
    private int propertyTest = 2;
     
    // Initialize has nothing related
     
    // OnBarUpdate has nothing related
     
    #region Properties
    [Category("Whatever")]
    [Description("Sets the whatever")]
    [NinjaTrader.Gui.Design.DisplayName("Whatever Property)")]
    public int PropertyTest
    {
      get { return propertyTest ; }
      set { propertyTest = value; }
    }
    #endregion
    Then user changes PropertTest to a 10 in the indicator dialog.

    Code:
     
    //**** IndicatorB
     
    ...OnBarUpdate()
    {
      Print("Test: " + IndicatorA().PropertTest)  <----- always prints "2"
    }
    When I add a Print() of the property to OnBarUpdate() on IndicatorA, for each bar I get...

    Code:
     
    Test: 2
    Test: 10

    #2
    Hi ActiveHawk,

    Thanks for your post.

    Please review those two links here -

    1. http://www.ninjatrader-support2.com/...ead.php?t=4991

    2. http://www.ninjatrader-support.com/H...V6/Update.html

    It is important that you use the Update() method to force an update of the embedded indicator values.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Not related to Update()

      Thanks for the reply. I'm familier with the use of Update() but this doesn't seem to be a problem with calling Update(). It fails with or without the call to Update() in the property getter. It has to do with variables that are changed by the user not being available to other indicators.

      I've included two simple test indicators. TestIndB calls TestIndA to get the value of A's user configurable property (ExposedVariable) but can only ever get the default and not the value set by the user.

      The ExposedVariable can be changed all you want in the dialog of TestIndA and the output window will always show "Exposed Variable: 2".

      See simple test code below...

      TestIndA.cs
      Code:
       
      public class TestIndA : Indicator
      {
        private int exposedVariable = 2;
       
        protected override void Initialize()
        {
          Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
          CalculateOnBarClose = true;
          Overlay = true;
          PriceTypeSupported = false;
        }
       
        protected override void OnBarUpdate()
        {
          Plot0.Set(Close[0] + (10*TickSize));
        }
       
        [Browsable(false)]
        [XmlIgnore()]
        public DataSeries Plot0
        {
          get { return Values[0]; }
        }
       
        // [Browsable(false)] // user configurable property
        // [XmlIgnore()] // user configurable property
        public int ExposedVariable
        {
        get { Update(); return exposedVariable; } // Update() doesn't matter here.
        set { exposedVariable = value; }
        }
      }
      TestIndB.cs
      Code:
       
      public class TestIndB : Indicator
      {
       
        protected override void Initialize()
        {
          Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot0"));
          CalculateOnBarClose = true;
          Overlay = true;
          PriceTypeSupported = false;
        }
       
        protected override void OnBarUpdate()
        {
          Print("Exposed variable from TestIndB: " + TestIndA().ExposedVariable);
        }
       
        [Browsable(false)]
        [XmlIgnore()]
        public DataSeries Plot0
        {
          get { return Values[0]; }
        }
      }

      Comment


        #4
        Hi ActiveHawk,

        Thanks for posting the test indicators.

        You cannot make a user defined input variable directly available to other indicators.

        For that matter please create another variable that tracks the user defined input one and expose that to access it from the other study.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        2 views
        0 likes
        Last Post Javierw.ok  
        Started by timmbbo, Today, 08:59 AM
        2 responses
        10 views
        0 likes
        Last Post bltdavid  
        Started by alifarahani, Today, 09:40 AM
        6 responses
        40 views
        0 likes
        Last Post alifarahani  
        Started by Waxavi, Today, 02:10 AM
        1 response
        18 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Kaledus, Today, 01:29 PM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X