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

indicator reading another indicator

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

    indicator reading another indicator

    Is there a way that one indicator can read another indicator?


    .I created an indicator with a List Array and I want to access the array. My list array is on my chart indicator but I want to create another indicator in a seperate panel and use the information in the List. Is this possible?

    #2
    Hello,

    Thanks for your post.

    It is possible to call indicator A from indicator B, and you can choose whatever panel you like.
    In order to do this you will need to expose your list by declaring it as a public class.
    Most commonly you see indicators calling on other indicators to get a Plots value. The standard format for all indicators that expose plots that can be accessed is:

    Indicator(overloads).plotname[BarsAgo]
    If you would like to have your indicator access non-plotted values than you will want to use an available class that implements the Series interface. Series<T>

    The following post goes into further detail on creating and accessing exposed objects.

    Exposing things other than plots


    If you have any further questions please let me know.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      thank you I can access it now but now I can't figure out why I can not draw a line in a panel indicator not a chart indicator

      Comment


        #4
        I just need to verify something I called my Indicator, do I have to put in all my fields or can I just access the drawlist

        i wrote this
        if(myChartIndicator.drawList[x].PivotType == 1)

        and I got an error.


        do I have to do this

        if(myChartIndicator(parameter,parameter,paramete, etc).drawList[x].PivotType ==1)


        because all I want is the charts drawList array.

        Comment


          #5
          Hello,

          "do I have to do this

          if(myChartIndicator(parameter,parameter,paramete, etc).drawList[x].PivotType ==1)"


          You are correct with this one, will need to include the parameters just like any indicator call.

          If you have any further questions please let me know.
          Josh G.NinjaTrader Customer Service

          Comment


            #6
            I would like to ask a related question about Performance and Memory when using this method of accessing exposed values in another indicator as described above on NT8.

            Let's assume our Main indicator (Indicator1) calls another (IndicatorX) and accesses some exposed values in IndicatorX.


            1. Does IndicatorX get loaded into memory, accessed, and thrown away each time a request for an exposed value is made?

            If it does then this would be quite memory and CPU intensive I would think. For example, what if Indicator1 has to access 10-20 values from IndicatorX on each chart bar that prints?

            2. Is it possible in IndicatorX to Expose a single Series that contains an instatiated class full of values?

            This would enable Indicator1 to make just one request to IndicatorX for data, retrieve the instatiated class and access all its field components from there.


            ...The perceived scenario where this might be useful would be where..

            IndicatorX is responsible for all the data collection and maths using OnBarUpdate.

            Indicators 1,2,3 etc. can access any of the values calculated by IndicatorX without the need to duplicate code and re-run the OnBarUpdate logic in IndicatorX.

            I hope this makes sense and that you can tell me if this is the most efficient approach and whether there is an example of code that shows how point 2. can be achieved?

            Thanks
            Last edited by MBScalper; 11-25-2019, 08:00 AM. Reason: Edited for clarification purposes

            Comment


              #7
              Hello MBScalper,

              1. This depends on the situation, if you mean calling the same indicator and same syntax: SMA(12)[0], no this is cached and will be reused. If you are instead calling new indicators each time :SMA(12) SMA(13) etc, a new indicator will be calculated and cached. Indicators are not disposed of until they are terminated. Exposed properties can also have the option of using the Update() method, if a property uses Update that will cause the script to have additional overhead when called.

              2. I would not suggest trying to over complicate the series being exposed, generally exposing a Series<double> is the best way/most efficient. If you expose a class and instantiate an object for each slot that would take a more resources than a simple type like a double.

              Your description in general is how all indicators work by default, if Indicator X does a calculation and plots it then Indicators 123 could access X to get the value it calculated. X would be calculated 1 to 3 times depending on what indicator 1,2,3 does with X. If 1,2,3 are all the same instrument and all have called X using the same parameters, it would return the cached instance. If there are differences in how X is being called, it would recalculate for that use case. You can see the same situation using a stock indicator like the SMA example from above.



              Please let me know if I may be of further assistance.







              JesseNinjaTrader Customer Service

              Comment


                #8
                Jesse,

                Thank you for your answer. What you said makes perfect sense.

                I have used update() in the properties of one of my Indicators (IndicatorX). I will look at whether it is necessary to do so in my case or not given your comment.

                Example:
                [Browsable(false)]
                [XmlIgnore]
                public Series<int> DS_Bar_Direction { get { Update();return ds_Bar_Direction; }}

                I expose a whole lot of properties, most of which start off in an instatiated class and then have their values put into a series variable somewhere in the OnBarUpdate method for the purpose of exposing each one to a calling indicator. The Calling Indicator (Indicator1 - does all the clever SharpDX display stuff) has to call IndicatorX 10-20 times to get all the exposed values.

                Do you know of any code example where an instantiated class is exposed?

                - Since I would like to see if performance improves when IndicatorX is called and returns one instantiated class.
                - This would also remove a lot of lines of code from my calling indicator.

                Many thanks,
                Last edited by MBScalper; 11-25-2019, 12:57 PM.

                Comment


                  #9
                  Hello MBScalper,

                  I have used update() in the properties of one of my Indicators (IndicatorX). I will look at whether it is necessary to do so in my case or not given your comment.
                  Yes if they are not necessary for the specific use case please do not use update, this is resource intense and is only suggested for specific uses. I would highly suggest using a Plot in place of a Series/Update to expose the data if your use allows for it.

                  Do you know of any code example where an instantiate class is exposed?
                  No, this goes outside of the general samples we would have for NinjaScript. If you want to start using complex structures like classes etc this falls into general C# coding which you can learn C# from external resources. These type of tasks are not documented in standard NinjaScript as it relies on your programming knowledge for the structures you are designing.

                  Series is exposed as a generic <T>, the standard use for a series would be a double however you can expose any Type.


                  I look forward to being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hi,

                    I have a question relating to exposed properties (similar to your example below).

                    double myvar = Indicator(overloads).ExposedProperty[BarsAgo];

                    I have an indicator which has about 30+ exposed properties. My indicator has a large number of input parameters and I am finding it cumbersome to type all those parameters/overloads each time I want to retrieve a different exposed property. Is there a way to parse a variable instead of the name of the exposed property? This way I could create a small method and parse the Property name in saving a lot of lines of code.

                    e.g.

                    double myvar = Indicator(overloads).%Variable%[BarsAgo];

                    Thank you.


                    Originally posted by NinjaTrader_JoshG View Post
                    Hello,

                    Thanks for your post.

                    It is possible to call indicator A from indicator B, and you can choose whatever panel you like.
                    In order to do this you will need to expose your list by declaring it as a public class.
                    Most commonly you see indicators calling on other indicators to get a Plots value. The standard format for all indicators that expose plots that can be accessed is:

                    Indicator(overloads).plotname[BarsAgo]
                    If you would like to have your indicator access non-plotted values than you will want to use an available class that implements the Series interface. Series<T>

                    The following post goes into further detail on creating and accessing exposed objects.

                    Exposing things other than plots
                    http://ninjatrader.com/support/forum...ead.php?t=4991

                    If you have any further questions please let me know.
                    Last edited by MBScalper; 12-09-2020, 10:58 PM.

                    Comment


                      #11
                      Hello MBScalper,

                      No but you could just use a variable for the indicator its self. The most simple way to do that is to generate the code with the strategy builder. If you use the indicator in any type of condition and click View Code you will get the correct variable for the indicator.

                      You could do:

                      IndicatorName myIndicator = IndicatorName(overloads);

                      Then later you would use myIndicator.plotName[BarsAgo]

                      JesseNinjaTrader Customer Service

                      Comment


                        #12
                        Fantastic!!!
                        So simple and saved me hundreds of lines of code too.

                        Thanks

                        Originally posted by NinjaTrader_Jesse View Post
                        Hello MBScalper,

                        No but you could just use a variable for the indicator its self. The most simple way to do that is to generate the code with the strategy builder. If you use the indicator in any type of condition and click View Code you will get the correct variable for the indicator.

                        You could do:

                        IndicatorName myIndicator = IndicatorName(overloads);

                        Then later you would use myIndicator.plotName[BarsAgo]

                        Comment


                          #13
                          Question: when I have one indicator already loaded on the chart, and a second shall retrieve data from the first indicator, would NT cache the first indicator a second time or is there a way to call exactly this instance.

                          As parameters may change, I wonder if there is a way to get the parameters of the currently loaded indicator. Maybe with something similar like chartControl.Indicators

                          And is hosting the indicator as an object the most resource efficient way?

                          The thing is, since OnRender doesn't allow drawing on different price panels, you need an indicator for each panel. But in the end it shall just extend the first indicator and not cause a second instance of it. It shall save resources by not using the Draw Method which has the DrawOnPricePanel feature.

                          Greetings

                          Comment


                            #14
                            Hello seykool,

                            When using indicators that have the same data and parameters the cache would be used to use the existing instance.

                            From what you described it sounds like you would need just apply the indicator twice to the chart, once on the first price panel and then again on the second price panel.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Ah, in fact, two instances of the same indicator calculate only once. Problem solved. Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Barry Milan, Today, 10:35 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by WeyldFalcon, 12-10-2020, 06:48 PM
                              14 responses
                              1,427 views
                              0 likes
                              Last Post Handclap0241  
                              Started by DJ888, Yesterday, 06:09 PM
                              2 responses
                              9 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by jeronymite, 04-12-2024, 04:26 PM
                              3 responses
                              40 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Today, 08:51 AM
                              2 responses
                              16 views
                              0 likes
                              Last Post bill2023  
                              Working...
                              X