Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Instantiating indicators from other indicators

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

    Instantiating indicators from other indicators

    Hi,

    2 problems have appeared with NT7

    Problem 1:


    Like indicated here: http://www.ninjatrader-support2.com/...ad.php?t=22023
    you can't instantiate an indicator from another indicator in the Initialize() method. Proposed solution code is to move code to OnBarUpdate().

    This is not very cool because

    1. Well, instantiation of an indicator is not Bar code, it's an initialization, so it should logically be in Initialize() method

    2. There are some things that can't be done in OnBarUpdate(), for instance add plots. So in that case you can't move the code to OnBarUpdate(). So it's really not equivalent.

    Problem 2
    The Instrument is null on the instantiated indicator. I believe this worked in Beta3 but I'm not 100% sure.

    This bug is critical as you can't use properties like TickSize.

    #2
    - please make sure you are on NT7B4
    - issue 1: what exactly is the issue you experienced based on NT7B4
    - issue 2: this is by design. Instrument/TickSize never had been supported in Initialize(). It may or may not have worked in NT6.5

    Comment


      #3
      I think that any DataSeries objects (except ticker symbols) needs to be Added from OnBarUpdate(); they don't work right for me if Added from Initialize() (but there is no error message).

      NT7B4 was the first time I tried doing it, so I don't know if it's a new issue.

      Also, it seems that Initialize() is called even for Indicators that are not in use. I have a Print statement in the Initialize() section of one of my indicators, and it prints even when not used in any chart. Is this by design? If so, I would think it would be better to add things in OnBarUpdate() so they don't consume resources unless they are used.

      Comment


        #4
        Yes I'm on NT7B4.

        There is already a thread on issue 1 : you can't instantiate another indicator from one indicator's Initialize(), which would be the correct method to instantiate something. You have to instantiate it on OnBarUpdate or you'll run into BarInProgress exception.
        This is inelegant (instantiation is an init, not "bar" code), and if you want to do init stuff like adding plots you can't because once in OnBarUpdate it's too late

        issue 2 : when you instantiate an indicator from another one, Instrument property is null on the instantiated instrument. Please forget ticksize, but should'nt Instrument be equal to something ? With the debugger I managed to find something useful with the DataSeriesHelper interface but it's not public. The Instrument property is OK inside
        (Bars)(((DataSeriesHelper)(this.Input)).DataSeries )
        but you can't get there with the code. So please make Instrument property available again.

        Comment


          #5
          On 1): Again, please post some sample code. We tweaked it to make it more convenient. We needed sample code to understand what in your eyes would not be working.
          On 2): This will not change: don't access .Instrument in Initialize().

          Comment


            #6
            Originally posted by kdoren View Post
            Also, it seems that Initialize() is called even for Indicators that are not in use.
            Same as NT6.5: there are many temporary instances of indicators and strategies where .Initialize() is called.

            Comment


              #7
              Dierk, I have an indicator that references 2 symbols, the primary series, plus a second symbol which is one of the indicator parameters. Right now I Add() the second symbol in Initialize(), and it seems to work.

              Are you saying that I should Add() it in OnbarUpdate()?

              Thanks, Kevin

              Comment


                #8
                No, I'm saying you should not access the ".Instrument" property in Initialize(), which you don't need to add a secondary instrument.

                Comment


                  #9
                  Dierk, Is this only true for Indicators?

                  I have a strategy where the secondary series is Added in initialize, and I reference Instrument.MasterInstrument.Name because I use it to determine the (default) name of the secondary instrument. This allows me to backtest/optimize on an instrument list, which I wouldn't be able to do if I had to enter the secondary symbol name for each instrument. It seems to work fine.

                  Also, in indicators, I am referencing BarsPeriod.Id and BarsPeriod.Value which are needed to make the secondary series have the same period as the primary; I presume this is OK.

                  Thanks, Kevin

                  Comment


                    #10
                    Please see below: It's true for indicators and strategies.

                    Please check the NT6.5 docs on what you could access in Initialize() or not (NT7 docs are still in the making). Anything else may or may not work.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Dierk View Post
                      No, I'm saying you should not access the ".Instrument" property in Initialize(), which you don't need to add a secondary instrument.
                      Yes but suppose that for init purposes you need fullname ?

                      NT 6.5 and NT 7.0 doc states for Instrument.FullName
                      "This property can be accessed without a null reference check in the OnBarUpdate() event handler. When the OnBarUpdate() event is triggered, there will always be an Instrument object. Should you wish to access this property elsewhere, check for null reference first. e.g. if (Instrument != null)"
                      Which means you can access it from Initialize(), but you have to test for nullity first.
                      It works most of the time, but strangely Instrument is null when instantiated by another indicator (this did work in 6.5)

                      Comment


                        #12
                        Not sure how to make it any clearer: DON'T access .Instrument in Initialize().

                        Comment


                          #13
                          FYI you fixed this non-existent bug in 7b5.

                          Thanks

                          Comment


                            #14
                            Not sure why you think there was a bug. You had been using a "feature" which may have worked in NT6.5 but was not supported nor documented. As such there is no guarantee it would work as expected nor it wouldn't be broken on an update.

                            However, we introduced an officially supported feature with NT7 which you now can savely use. This feature is documented in the release notes.

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            605 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            351 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            105 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            560 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            561 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X