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 Indicator Results from Different Bar Types

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

    Accessing Indicator Results from Different Bar Types

    I run an indicator A on two different Renko charts, indicator B on two different tick charts and indicator C on two different range charts. My main chart is a time chart on which I run my main indicator. Is there any way I can access the results generated by the indicators in the other charts using my main indicator in the time chart?

    Also, is it possible to get the results of the other indicators without creating the charts on the screen? In other words, I know I can add a series, for example,

    Code:
     AddDataSeries(BarsPeriodType.Tick, 500);
    but I am not sure how to apply the indicator to that series and retrieve the indicator results.

    #2
    Hello Zeos6,

    The easiest way to accomplish this would be to add the data series of the different time durations you are looking to use. You would use AddDataSeries as you suspect. To specify a specific data series, you would pass the indicator a data series such as BarsArray[1], meaning the 1st data series added to the indicator, whereas BarsArray[0] would refer to the primary. You could also use Closes[1] or Highs[1] referring to the 1st data series.

    See,


    See,


    Please see the following reference example for referencing additional data series from within a strategy.



    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi AlanP,

      Thank you for your reply. Yes, I am aware that I can add the various data series. The issue really is... how do I apply a separate indicator to each series to extract the results I need? I certainly don't want to add the indicator code in again.

      Comment


        #4
        Hello Zeos6,

        You could pass each additional data series to the indicator, for example using the SMA,

        SMA(Closes[1], 10),
        SMA(Closes[2], 10),
        SMA(Closes[3], 10),

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi AlanP,

          Thank you for your reply. I should have been more precise. I am adding a custom bar type and my indicator is a custom indicator. Does every indicator by default take a bar series as an input or is there special coding required for that? In other words, how would I run a custom indicator on a custom bar type series?

          Comment


            #6
            Hello Zeos6,

            Yes, all indicators can be passed a dataseries.

            At the following link you would want to see the 2nd note about adding a data series for a custom bar type.


            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Hi AlanP,

              OK. So if I can just pass a series into my indicator, MyIndicator(mySeries), how do I access the close, open, etc of the series in the indicator? Do you have a simple example you could show me please? It would be appreciated. Thank you.

              Comment


                #8
                Hello Zeos6,

                To get a SMA of the highs of a secondary series you could,

                SMA(Highs[1],10)[0];

                Please see the following links,




                You could also see the preloaded strategy on NinjaTrader called SampleMultiTimeFrame.

                Please let us know if you need further assistance.
                Alan P.NinjaTrader Customer Service

                Comment


                  #9
                  Hi AlanP,

                  Thank you for the reply but this is completely missing the point. I am not sure how to ask this question even more simply without getting a completely trivial response. Here I will try again...

                  I have a custom indicator: NOT a NT indicator, and certainly more complex than a moving average indicator. My questions are:

                  1. Does EVERY indicator (including ANY custom built indicator) have a built in constructor to accept a series input?

                  2. If not, can you give me a sample that would allow me to do that.

                  3. If yes, how do I add a custom bar type as the series input to the custom indicator?

                  4. How do I access the High, Low, etc values of the custom bar type series inside the custom indicator for calculation purposes?

                  Comment


                    #10
                    Hello Zeos6,

                    You can pass a custom indicator a custom bar type series.

                    I put together a sample which demonstrates how to pass a custom data series to an indicator. I included notes in the indicator to guide you through the process.

                    Please let us know if you need further assistance.
                    Attached Files
                    Alan P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thank you very much AlanP. Your sample was quite helpful. I get it regarding adding a custom Bar Type. I want to also add that your Bar Type sample was helpful as well. I now have two questions:

                      1. In a custom Bar Type, is there a way that Value could be used for integer input and Value2 as a custom decimal (or type double) multiplier to apply to Value? I am also building a custom Bar Type and need to apply decimal (type double) multipliers to Value.

                      2. The sample indicator with the custom Bar Type was helpful but it isn't really addressing the heart of my question. The key question is: now that the custom Bar Type has been added in your indicator, how do I apply a custom indicator to the added custom Bar Type and retrieve values calculated by the custom indicator? And I'd like to do all this from inside your indicator.

                      Finally, if the custom indicator that uses the custom bar type calculates results, how can those results be retrieved?

                      Your help would be greatly appreciated. Thank you.
                      Last edited by Zeos6; 08-24-2017, 09:39 AM.

                      Comment


                        #12
                        Hello Zeos6,

                        At this time Value and Value2 are both type integers, I did request that either or both be doubles as I was having the same issue where I wanted to pass a decimal number but could not, which is why in my bar type you enter a whole number and depending on tick size of the instrument, an adjustment is made (line 40 of my bar code). I will add your vote to this feature request, SFT-2533. If anyone else reading this would also like to see this change please like this post and I will submit your vote as well.

                        I’ve attached a screen shot of 2 indicators, a chart and output window. In MyCustomIndicator7, I add a custom bar type, and within OnBarUpdate I pass this series to another indicator called SpecialCustomIndicator using Closes[1]. SpecialCustomIndicator prints to the output window the Close value of the data series being passed to it…which is the secondary series added in MyIndicator7.

                        Please let us know if you are still having difficulty.
                        Attached Files
                        Alan P.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi AlanP,

                          Thank you for your reply.

                          As to custom BarTypes, the most ideal would be to allow the addition of custom properties to the Bar Type. I am able to add a property to the Bar Type Property Grid but the values do not get passed to the Bar Type. As a second option, maybe Value and Value 2 could be Generics.

                          Can I please get a copy of your ' MyCustomIndicator7', and your other indicator, 'SpecialCustomIndicator'? I'd like to study it in more detail.I would really appreciate it.

                          Finally, if the custom indicator that uses the custom bar type calculates some values, how can those values be retrieved?

                          Thank you for your help.
                          Last edited by Zeos6; 08-24-2017, 09:40 AM.

                          Comment


                            #14
                            Hello Zeos6,

                            I have attached both indicators and the bar type.

                            Regarding your following question, could you please provide more detail on what you mean by retrieved?
                            Attached Files
                            Alan P.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi AlanP,

                              Thank you very much for the samples. Much appreciated.

                              1. The custom indicator will calculate a number of flags and values relating to conditions and setups on the chart. Ideally therefore I would like to save all those in a tuple (maybe class or struct) and pass the tuple back to the calling indicator for use inside the calling indicator.

                              So if your SpecialCustomIndicator created a tuple containing results, how would an updated (most current) version of that tuple be passed back to MyCustomIndicator7, and how would MyCustomIndicator7 access those results?

                              2. Can I also pass the custom bar into the indicator as follows rather than specifying say, closes?

                              Code:
                              if (State == State.SetDefaults)
                              {
                                  BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType)123, BarsPeriodTypeName = "myCustomBar",};
                              }
                              else if (State == State.Configure)
                              {
                                  AddDataSeries(new BarsPeriod() { BarsPeriodType = (BarsPeriodType)123, Value = 5, Value2 = 8 });
                              }
                              
                              protected override void OnBarUpdate()
                              {
                                          if(CurrentBars[0]<10 || CurrentBars[1]<10  ) return;
                                          
                                          SpecialCustomIndicator(myCustomBar);
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Perr0Grande, Today, 08:16 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post Perr0Grande  
                              Started by elderan, Today, 08:03 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post elderan
                              by elderan
                               
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post quantismo  
                              Working...
                              X