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

Adding custom Indicator to a new Indicator

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

    Adding custom Indicator to a new Indicator

    Hi all,

    I have a proprietary indicator I wrote let's name it Indicator1 that gets no arguments.
    Now I'm developing a new indicator let's name it Indicator2.

    Within Indicator2 I want to use the values of Indicator1 so I write the following code:

    Code:
     #region Variables
            private Indicator1 indicator1= null;
     #endregion
    
    protected override void Initialize()
     {
           indicator1 = Indicator1();
           Add(indicator1); //ERROR!!!!!!!
    }
    
     protected override void OnBarUpdate()
            {
    //This is the way I want to use it
    if(indicator1[0] > 10)
     //Do someting...
    }
    My error is that I can't add the Indicator1 to Indicator2. If I don't use the Add(indicator1) I only get zeros when accessing indicator1[0].

    How can I solve it?

    BTW in Strategies I don't have any problems adding Indicators.

    Thank in advance!

    #2
    Add(indicator1); //ERROR!!!!!!!
    You have identified the error. Remove the line.

    IOW, we do not "Add" indicators to other indicators: we add indicators to strategies.
    Last edited by koganam; 01-19-2011, 06:30 AM.

    Comment


      #3
      Yes, but then the data in indicator1 is all zeros.

      Comment


        #4
        Unfortunately only strategies could Add() indicator for display...are you trying to access plots of your called indicator? Only those would be exposed for access automatically, regular variables / dataseries needed to be made public first - http://www.ninjatrader.com/support/f...ead.php?t=4991

        Also: please ensure CalculateOnBarClose ist not set by code in the called indicator.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi Bertrand,

          I did what you said and it didn't work, I even tried few IDataSeries. I'm a professional programmer so fully understand what you meant.
          When I'm working with Strategies I don't have these problems.
          Can you check that is not NT bug?

          Comment


            #6
            I'm not aware of any issues with indicator from indicator access - can you send me your sample code that is not working as you expect, so I can look into it? You can reach me at support at ninjatrader dot com Attn Bertrand - judging from the indicator call in your first post there's no method / property / plot access for the to be called indicator - so is it returning one value only?
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Originally posted by freewind View Post
              Yes, but then the data in indicator1 is all zeros.
              Does Indicator1 expose a plot, or is it used purely for data manipulation?

              Comment


                #8
                Hi Koganam,

                Indicator1 expose a plot.
                I also tried it with any IDataSeries and all returned zeros.

                Comment


                  #9
                  Do you get the same result if you just access the main value of it?

                  Print(Indicator1().Value[0].ToString());
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Yes I'm getting the same result zeros.

                    BTW on a chart that use Indicator1 the data is plotted correctly!

                    Comment


                      #11
                      Just replied to your note send to support freewind, in the BarSpread one you miss the proper NS generated wrappers, this will result in an issue calling it from other scripts. If you save the code to a new script and recompile the wrappers should get regenerated, please retry calling the new indicator then.
                      BertrandNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by freewind View Post
                        Yes I'm getting the same result zeros.

                        BTW on a chart that use Indicator1 the data is plotted correctly!
                        Did you use a description string for Indicator1?
                        If so, did you use one long string, or did you, for readability, use a string expression?

                        Comment


                          #13
                          Yes I use a description attribute above the class name.
                          I use a string expression.

                          Comment


                            #14
                            THAT is what is breaking.

                            Originally posted by freewind View Post
                            Yes I use a description attribute above the class name.
                            I use a string expression.
                            As ETFVoyageur and I discovered, after much cavorting and hair-pulling, using a string expression over there will stop the NT magic code from being regenerated. (Actually, he discovered it, and kindly alerted me completely out of the blue!) IOW, use a single long string, not a string expression, for the description, at least when compiling.

                            Of course, nothing stops you from then replacing the string with a string expression, and compiling again, as THAT single change does not need the magic code to be recompiled. Awfully cumbersome, but if you insist on having conveniently readable source code, that is your only option for now.

                            Is it not surprising how something that all good coders logically do, almost without thinking about it, to improve the readability of their source code, leads to code that will not compile correctly? And with a silent failure at that: no warning, no failure, no log.

                            Comment


                              #15
                              Hi Koganam,

                              Your Voodoo did not work.
                              But Bertrand from NT gave me a hack to solve the problem.
                              His solution was to use:
                              Indicator1(Close).Plot0[0]


                              It works but I don't understand why this is working and not the reference?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AaronKoRn, 04-27-2024, 09:49 PM
                              3 responses
                              30 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by f.saeidi, Today, 07:07 AM
                              6 responses
                              19 views
                              0 likes
                              Last Post f.saeidi  
                              Started by cmtjoancolmenero, Today, 02:31 PM
                              6 responses
                              15 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by Graci117, Yesterday, 11:40 PM
                              5 responses
                              27 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by rene69851, Today, 03:25 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post rene69851  
                              Working...
                              X