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 calling another Indicator

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

    Indicator calling another Indicator

    Hi guys

    I've been fiddling with this all day and am a bit stuck, I'm trying to load 1 indicator from another indicator, so i assume first thing I have to do is add the second indicator to my first in the initialise event?

    Like so:

    protectedoverridevoid Initialize()
    {
    Add(FalseBreakRev(
    1,SF,SP));

    signalD =
    new DataSeries(this);
    CalculateOnBarClose =
    true;
    Overlay =
    true;
    PriceTypeSupported =
    true;
    }

    On compilation however I'm constantly getting this error:

    Indicator\RNBSignals.cs,The best overloaded method match for 'NinjaTrader.Indicator.IndicatorBase.Add(NinjaTrad er.Gui.Chart.Line)' has some invalid arguments,CS1502 - click for info,46,4,

    Indicator\RNBSignals.cs,Argument '1': cannot convert from 'NinjaTrader.Indicator.FalseBreakRev' to 'NinjaTrader.Gui.Chart.Line',CS1503 - click for info,46,8,


    I have tried calling the indicator in the same way from my strat and I don't get this problem, it only seems to be when i call one indicator like this, is my implementation incorrect?.

    Thanks
    Cheers
    Ross


    #2
    Ross, unfortunately you can't add an indicator to an indicator in Initialize() like you can with strategies.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hmmm... ok I thought this might be the case, what would be the suggested method then for what I'm trying to achieve, presumably i can still reference values in another indicator from the first right?

      What I'm trying to do is have indicator 2 able to function entirely independently.

      Indicator 1 has an option to switch on indicator 2, if this is the case then indicator one will use various indicator 2 values and override some of its own signals based on indicator 2 signals.

      Without having the ability to add indicator 2 onto the same chart as indicator 1 if indicator 1 has the parameter set to work in conjunction with 2, does this mean that the user will have to manually add the second indicator to the chart every time they want it to work in conjuction with 2? Or am I just incorrectly implementing the adding of indicator 2 to the same chart as indicator 1 from within indicator 1? why does it not work like a strat?

      Hopefully not to confusing.

      Thanks
      Ross

      Comment


        #4
        Ross, it is possible to use indicator values in other indicators. Please see this thread--it goes over how to access an indicator's variable in a strategy. The same concepts apply for with an indicator.

        The main reference in the thread goes to this reference sample-Exposing indicator values that are not plots.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Thanks Austin, I call indicators from my auto strats and use values which i expose through data series so I've got the gist of how this should be done.

          Neither of those links touches on the issue which i have though of having an indicator add another indicator to a chart which is my main sticking point.

          I can do this no problem from my autostrat, Initialise Event, how come not from an indicator?

          Cheers
          Ross

          Comment


            #6
            Originally posted by DangerBoy View Post
            I can do this no problem from my autostrat, Initialise Event, how come not from an indicator?
            Indicators are independent studies. If you wanted another indicator you could just add the other indicator directly. If you wanted them all together you could add a strategy. If you just want indicators and no strategy, go ahead and add them individually and save the chart template.

            Another option would be to just hack together a "super indicator" that includes all the logic from all the indicators you want.

            Basically, indicators in NinjaTrader 6.5 weren't built for nesting.
            AustinNinjaTrader Customer Service

            Comment


              #7
              OK understood, unfortunately putting everything in one lump is not the way i program so that is not an option, I cut everything into individual units so they may be reused, if I want to use indicator 2 in other potential configurations, i don't want all of indicator 1's logic in there also.

              At this point I will have to rely on the user to make sure that if indicator A has the option for indicator B checked that indicator B has been added to the chart by the user otherwise indicator A will not function correctly as it will call an indicator that is not even on the chart (not sure if this will cause an error at this point as haven't tried it yet, assuming exposed values will all just be null).

              The main issue here is that I am not able to programatically close this loop and so I would have to rely on the user to add all the potential nested indicators.

              Not the worst thing in the world but would be great if indicators had the ability to add another in the future.

              Thanks allot for the help, speedy response as always.

              Cheers
              Ross

              Comment


                #8
                Indicator using another Indicators Calcs

                I am confused by this as well....

                The Reference sample only deals with an indicator exposing values to a strategy, but that isn't what I want to do, and can't use the Add method to add my indicator to another indicator like the Reference sample strategy example does, as the previous poster found.

                I want this chunk of logic to stay a separate chunck and re-use it only by accessing a double value it calculates in other indicators. I want to pass the value the 1st indicator calculates to another indicator for use in the second indicator's calcs.

                Surely this is possible?
                Last edited by Crassius; 03-02-2011, 01:58 PM.

                Comment


                  #9
                  Crassius,

                  Exposing values to a strategy is the exact same procedure as exposing the value for another indicator to access. Once your calculation is exposed you can access it any where.

                  Indicators cannot Add() other indicators. That is a strategy only concept. You do not need to Add() an indicator to use its values. Just call the indicator within the script you want and access the values directly. For instance, if you had an indicator that wanted to use the SMA indicator, you do not need to Add() the SMA you could just call SMA(20)[0] for instance.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks... that clears that up

                    I think what confused me was this first line in the Indicator: Exposing indicator values that are not plot reference sample:

                    There may be cases where you want to have your indicator calculate non-plotted values that you will want to access from other indicators or strategies.

                    When I read read the indicators I put in bold, I guess I put my blinders on and kept trying to make the strategies syntax work.

                    Comment


                      #11
                      Dear Customer Support,


                      I have a similar question regarding referencing indicator value from another indicator.

                      When I try to call indicator value for say SMA(10)[10] from another indicator on OnBarUpdate, it seems that the indicator value is not being referenced.
                      It seems that I can only call indicator value for current bar Value[0], but not the past bar say Value[10].


                      I'm just trying to plot the following line but it is not working.
                      Plot0.Set(Math.Log(SMA(10)[0] / SMA(10)[30]));


                      When I make a DataSeries within the new indicator and copy the SMA value to this DataSeries, and then reference the past bar value, it works (like you find in the code of MACD). But it is alittlebit annoying copying incidator value to a DataSeries.
                      Is there any simple way that I can use, when I want to create an indicator which use past bar value of another indicator? (Like Add method you can use in a strategy?)

                      Look forward to hearing from you.


                      <Sample Code is as follows>
                      public class SampleIndicator : Indicator
                      {
                      #region Variables
                      // Wizard generated variables
                      private int lookBack = 1; // Default setting for LookBack
                      // User defined variables (add any user defined variables below)
                      #endregion
                      /// <summary>
                      /// This method is used to configure the indicator and is called once before any bar data is loaded.
                      /// </summary>
                      protected override void Initialize()
                      {
                      Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                      Overlay = false;
                      }
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                      // Use this method for calculating your indicator values. Assign a value to each
                      // plot below by replacing 'Close[0]' with your own formula.
                      //Plot0.Set(Math.Log(SMA(10)[0] / SMA(10)[lookBack]));
                      Plot0.Set(SMA(10).Value[lookBack]);

                      }

                      Comment


                        #12
                        hana_maui, are you receiving any errors in the logs (right-most tab of Control Center)?

                        If you want to use a value of an indicator, you can just call it directly:
                        Code:
                        // to get the 10 period ATR from 3 bars ago
                        double atr_value = ATR(10)[3];
                        
                        // 20 period sma from 10 bars ago
                        double sma_value = SMA(20)[10];
                        AustinNinjaTrader Customer Service

                        Comment


                          #13
                          Unless you escape the lookBack bars initially, that should fail with an indexing error. Look in your logs to see if there is such an error. If there is, there is more than one way to fix it. An inelegant but very effective method is to simply not process those bars where the indexed value does not yet exist.

                          You can do that by adding, at the start of the OnBarUpdate() method, the following line:

                          Code:
                          if (CurrentBar < lookBack) return;

                          Comment


                            #14
                            Dear Mr. Austin and Koganam,

                            Thanks for your feedbacks.

                            if (CurrentBar < lookBack) return;
                            have solved the problem.


                            And I didn't know that errors on indicators will also be mentioned under the logs tab.
                            I was assuming only strategy errors will be mentioned here.


                            Thank you for your kind support.

                            Comment


                              #15
                              I developed a TRIN indicator and am trying to call it from the SMA indicator. The SMA line appears to be plotting based on the underlying TRIN's data series value instead of the TRIN value.

                              I have calls to Value.Set in the TRIN indicator, but that doesn't seem to make a difference. Is there something that I should be doing to get the SMA indicator to use the TRIN value instead?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by prdecast, Today, 06:07 AM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by Christopher_R, Today, 12:29 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_LuisH  
                              Started by chartchart, 05-19-2021, 04:14 PM
                              3 responses
                              577 views
                              1 like
                              Last Post NinjaTrader_Gaby  
                              Started by bsbisme, Yesterday, 02:08 PM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by i019945nj, 12-14-2023, 06:41 AM
                              3 responses
                              60 views
                              0 likes
                              Last Post i019945nj  
                              Working...
                              X