• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing Multiple Custom Indicator Plots within a Strategy

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

    Accessing Multiple Custom Indicator Plots within a Strategy

    What is the best approach to access a custom indicator from within a strategy given the following general case example:

    myCustomIndicator has three parameters (parmA, parmB, parmC) and outputs four plots - "plot1", "plot2", "plot3", "plot4".

    1) Within the strategy code, how would I assign the variable myIndicatorValue to the current value of the MyCustomIndicator "plot3"?

    2) What if I wanted the value 10 bars ago for "plot3"?

    A specific example for each is appreciated. Thanks!
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    #2
    Not sure I follow. There is no difference between your custom indicator in a strategy and a standard NT indicator like e.g. MACD (which has 3 plots) which you would access like this:
    double d = MACD(fast, slow, smooth).Avg[10];
    DierkNinjaTrader Customer Service

    Comment


      #3
      Thanks Dierk,

      so the general case is:

      strategyVar = indicatorName(parm1, parm2, ...).indicatorPlotName[barsago];

      Perfect!
      whitmark
      NinjaTrader Ecosystem Vendor - Whitmark Development

      Comment


        #4
        As a follow-up question, what is the general case code (or example) if I wanted to plot the "plot3" series of a custom indicator for the current bar value or the value 10 bars back? This seems to work differently than the assignment example. Thanks.
        whitmark
        NinjaTrader Ecosystem Vendor - Whitmark Development

        Comment


          #5
          Again, not sure I follow. Below you pointed out the current usage already. What are you looking for?
          DierkNinjaTrader Customer Service

          Comment


            #6
            Hi Dierk,

            What I am trying to understand is how to reference different plots from a custom indicator to 1) be accessed for subsequent calculations in the strategy logic or 2) pass plots to the chart, perhaps with some style changes. In this case I might only want to plot some, but not all, of the indicator plots on the strategy chart.

            For use case #1 it would appear that I can reference the plot name directly and can address specific bars in a series (e.g., ".plot3[0]"). In use case #2, I would need to reference the plot number (e.g., ".Plots[2]") realizing it is zero based as sequenced in the custom indicator. In this case there is no addressing of the plot by name, only by its slot number.

            Seeking clarification on what seems to be two approaches to reference plots of a custom (or standard) indicator. Thanks.

            Whitmark
            whitmark
            NinjaTrader Ecosystem Vendor - Whitmark Development

            Comment


              #7
              Yes, you can only access plots by their index within the Plots[] collection.

              For clarification, a plot is only the visual representation of data contained in a DataSeries.

              So if you have a plot named "Plot1" and its the only plot within the indicator, you can access this plot object via Plots[0] and manipulate its properties.

              The underlying data point of that plot are contained in a DataSeries object exposed by a property such as "public DataSeries Plot1".

              So, you get at the the plot and the underlying data, you always:

              myIndicator.Plots[plot index]
              myIndicator[n barsAgo] --> Default plot
              myIndicator.DataSeriesPropertyName[n barsAgo] -->
              RayNinjaTrader Customer Service

              Comment


                #8
                Ray, thanks for the thorough explanation. One more follow-up question to complete the thread:

                If I have a custom indicator with several parameters, do I have to restate all of the parameters with each indicator call or is there a way to forgo these references each time if I am looking for a way to just access values for different n barsago using the same parm set? For example;

                As you can imagine, coding expressions like

                if (myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[0]
                > myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[1])

                etc, can be pretty cumbersome, yet there is always this remedy:

                double myValue0 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[0];
                double myValue1 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[1];
                double myValue2 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[2];
                double myValue3 = myCustomIndicator(parm1, parm2, parm3, parm4, parm5).myDSName[3];

                But there may be best practice for how to do this.

                Thanks,

                Whitmark
                whitmark
                NinjaTrader Ecosystem Vendor - Whitmark Development

                Comment


                  #9
                  Yes, you have to restate them unless you assign the indicator to a variable.

                  For example:

                  MyCustomIndicator myCustomIndicator = myCustomIndicator(parm1, parm2, parm3, parm4, parm5);

                  if (myCustomIndicator.myDSName[0] > myCustomIndicator.myDSName[1])
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Ray, that works well, but if I understand the OOP concept correctly, your example should read as follows where the MyCustomIndicator is the indicator name and the myCustomIndicator is the name of the instance of the indicator that you would like to reference in your strategy. Typically, I will shorten myCustomIndicator to something pithy like myCI since I will be referring to it frequently.

                    For example:

                    MyCustomIndicator myCustomIndicator = MyCustomIndicator(parm1, parm2, parm3, parm4, parm5);

                    if (myCustomIndicator.myDSName[0] > myCustomIndicator.myDSName[1])
                    whitmark
                    NinjaTrader Ecosystem Vendor - Whitmark Development

                    Comment


                      #11
                      That is correct.
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Collections/Arrays of DataSeries objects

                        Hi,

                        This thread seems to come close to what I'm after but not quite. Apologies if this is a silly question, I'm more of a VB background.

                        How does one obtain an array/collection of DataSeries objects, but WITHOUT using the Add() function (which puts them into the Values collection and would mean that they are plotted)?

                        The reason I don't want to use Add() is that I don't want the group of DataSeries objects being plotted.

                        What won't work here is putting them all into the Values collection (via Add() method) and making some plots "invisible"/transparent, as that would adversely affect the DataSeries that I do want to plot.

                        Some background: what I am trying to achieve is an indicator which is built up from an arbitrary number of components, where each component is weighted according to how well it performs over time under a particular measure. So in one version of the indicator I want to be able to keep the performance over time of each component as an array of DataSeries but not plot these - what I want to plot is the measure of performance for each component (so I'd put the component performance DataSeries into the Values collection via Add()).

                        Cheers,
                        fttbb.

                        Comment


                          #13
                          Do you mean you just want an array of data points that are in sync with the number of bars on your chart?

                          If yes, please check out the DataSeries class - http://www.ninjatrader-support.com/H...iesObject.html
                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            Collections/Arrays of DataSeries objects

                            Hi NinjaTrader_Ray,

                            How can you ask that having read my message?

                            I said that I want "an array/collection of DataSeries objects" but without using the Add() method or the Values collection of DataSeries objects.

                            Do you understand this?

                            Clearly then:
                            1. I know what the DataSeries class is; and
                            2. I've read the help function about DataSeries objects, the Add() method and the Values collection, since I explained why the Values collection of DataSeries objects is not the collection that I want.

                            So please don't just refer me to the help information about the DataSeries object.

                            I look forward to a considered answer.

                            Regards,
                            fttbb.

                            Comment


                              #15
                              Sorry, misunderstanding.

                              There is no supported class for a collection of DataSeries objects. You will need to use a standard C# collection class such as an ArrayList.
                              RayNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pstrusi, Today, 03:11 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post pstrusi
                              by pstrusi
                               
                              Started by godric, Today, 01:29 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Jim  
                              Started by blar58, Today, 02:06 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_JoshG  
                              Started by woodyfox, Yesterday, 08:06 AM
                              3 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_PatrickH  
                              Started by julifro, Today, 11:58 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_PaulH  
                              Working...
                              X