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

Using Values from Another Indicator

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

    #16
    I'm not able to access the updated indicator one object from indicator two.
    Indicator two gets the indicator one object when the indicators load, but after that, any change to the exposed variable in indicator one is not reflected in indicator two.

    Indicator one:
    Code:
    protected override void OnBarUpdate()
    {
    exposedMfe = Close[0];
    exposedHasPosition = hasPosition;
    ...
    }
    
    #region Properties
    [Browsable(false)] // Prevents showing up on the UI property grid
    public double ExposedMfe
    {
    // Update() calls OnBarUpdate to ensure our exposed variable is up-to-date
    get { Update(); return exposedMfe; }
    }
    
    [Browsable(false)] // Prevents showing up on the UI property grid
    public bool ExposedHasPosition
    {
    get { Update(); return exposedHasPosition; }
    }
    I can retrieve the updated value of ExposedMfe without any problem, but ExposedHasPosition does not update in indicator two.

    Indicator two:
    Code:
    protected override void OnBarUpdate()
    {
    if (State == State.Realtime)[INDENT]{
    valMfe = MyMFE().ExposedMfe;
    hasPosition = MyMFE().ExposedHasPosition;
    }[/INDENT]
       }
    Any help would be much appreciated, as I have spent way too long on this.

    Comment


      #17
      Think I have solved it with:
      Code:
      private static bool exposedHasPosition        = false;
      ...
      
      #region Properties
      [Browsable(false)] // Prevents showing up on the UI property grid
      public bool ExposedHasPosition
      {[INDENT]get { return exposedHasPosition; }
      //It looks like Update() is not required[/INDENT]
       
      
      
        }
      Looks like the static modifier is the key to getting this to work.
      Last edited by FatCanary; 06-21-2021, 03:13 AM.

      Comment


        #18
        I have a similar question - I would like to expose values calculated by an indicator A to an indicator B. The main reason is that indicator A draws in one separate panel, and indicator B should draw on the price panel. I expose as per the example above variables calculated by indicator A. When I want to use these in indicator B, I'd use something like valMfe = IndicatorA().ExposedVariable.
        But the problem is my indicator A takes a number of parameters that I want programmable - if I code this in indicator B, I would need to call IndicatorA(10, 20, 30, etc..) hardcoded. Instead, I want to use the active parameters in use for that indicator.
        Not sure if that is clear - I do not want to have to hardcode values of parameters in use for indicatorA when accessing the exposed variable, instead I want to use the current active indicatorA parameters and retrieve its exposed variable.

        Comment


          #19
          Hello Laurentvan,

          If your indicator A has user input properties you can just pass those to indicator b instead of hard coding values like you had shown. You would replace the numbers you had shown with the property names.
          JesseNinjaTrader Customer Service

          Comment


            #20
            Thanks - how do I do that programmatically? e.g from Indicator B, how do I access the user input property of indicator A? (these are typically entered from the Indicators dialog manually),
            Thank you!

            Comment


              #21
              Hello Laurentvan,

              Whichever indicator you add to the chart would need to pass the values to the indicator being called in code. For example if you call IndicatorA in IndicatorB's code you would pass the user input that you configured in the user interface to IndicatorA. You would need to define the same user input in both indicators.

              For example if you have a user input called Period you would add that user input to the parameters when you call the indicator.

              IndicatorA(Period)
              JesseNinjaTrader Customer Service

              Comment


                #22
                Thank you and sorry that is still not exactly what I am looking for.
                IndicatorA has something like 20 user input properties, manually entered and modified in the Indicators window/Properties section. I run tests with different values entered manually in this window.
                I could indeed add all the properties into IndicatorB as well but it's a lot of work to modify in both places each time and mirror both IndicatorA and B.

                Would there be another way to expose a variable from IndicatorA to IndicatorB, without having to duplicate all these properties?
                Thanks again

                Comment


                  #23
                  Hello Laurentvan,

                  If you have 20 user inputs in indicatorA you already have the code required to modify indicatorB, you can copy/paste those same inputs into indicatorB to update it. That will make the overloads for the indicator automatically when you compile and then you would pass the user inputs from indicatorA to B when you call B. That would be the suggested way to pass user inputs to an indicator that you call in code so its default values for the properties are being set at the right time. Trying to expose properties in a different way would require using more lines of code and using Update() in each of the public properties which is less efficient overall. In either case you still need to make a public property inside of indicaorB that matches the input inside indicatorA so the value can be passed.



                  JesseNinjaTrader Customer Service

                  Comment


                    #24
                    Thank you - I am still unsure of how this works.
                    Say I have added Indicator A manually through the Indicator window. Do you suggest there is a way to add a new Indicator B programmatically from within the Indicator A? If so, how do I do this?
                    Once added, am I able to map the Indicator B to a specific panel to display its content?
                    Thanks again.

                    Comment


                      #25
                      Hello Laurentvan,

                      You cannot add another indicator visually from an indicator, you can only call it in code to get its values. Only strategies can visually add indicators that it calls by using AddChartIndicator.

                      JesseNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by AaronKoRn, Today, 09:49 PM
                      0 responses
                      11 views
                      0 likes
                      Last Post AaronKoRn  
                      Started by carnitron, Today, 08:42 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post carnitron  
                      Started by strategist007, Today, 07:51 PM
                      0 responses
                      11 views
                      0 likes
                      Last Post strategist007  
                      Started by StockTrader88, 03-06-2021, 08:58 AM
                      44 responses
                      3,980 views
                      3 likes
                      Last Post jhudas88  
                      Started by rbeckmann05, Today, 06:48 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post rbeckmann05  
                      Working...
                      X