Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

referring to indicator in strategy analyzer

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

    referring to indicator in strategy analyzer

    Hi,
    Currently, I have something like the following in my Initialize event handler of my strategy to load my indicator:
    Add(MyIndicator());

    I have a module level variable (m_iMyIndicator) that gets initialized
    in the OnStartUp event.

    The Add function doesn't have a return value, so I have to get a reference to my indicator via the following in the OnStartUp event:

    m_iMyIndicator = (NinjaTrader.Indicator.MyIndicator)(from a in ChartControl.Indicators where a.Name == "MyIndicator"
    select a).FirstOrDefault();

    This works great under normal chart operations. However, when I try to run it in the strategy analyzer, ChartControl is null.

    So, my question is how to get a reference to an Added indicator from something other than the chart control? My strategy needs info from the running indicator to make decisions.
    Thanks ... Ed


    #2
    Hello edstaffin,

    Thank you for your post.

    You would call the indicator method for your calculations, not the "added" indicator via the Initialize() method.

    Please take a look at the indicator methods at the following link for examples: http://www.ninjatrader.com/support/h...indicators.htm

    Comment


      #3
      I guess I didn't explain properly. I am not interested in those methods. Only certain custom properties that I wrote into the indicator that are set at runtime.
      Thanks .... Ed

      Comment


        #4
        Hello edstaffin,

        They are values you exposed, correct? If so, just call the method and the values.

        Comment


          #5
          Via what object? I am currently using he object returned from

          m_iMyIndicator = (NinjaTrader.Indicator.MyIndicator)(from a in ChartControl.Indicators where a.Name == "MyIndicator"
          select a).FirstOrDefault();

          which works perfectly when I add my strategy to a chart and enable it. However, as I said in my original note, when I try to optimize my strategy via the strategy optimizer, ChartControl is null. So the question remains ...
          how to get a reference to an Added indicator from something other than the chart control?
          Thanks ... Ed

          Comment


            #6
            Originally posted by edstaffin View Post
            Via what object? I am currently using he object returned from

            m_iMyIndicator = (NinjaTrader.Indicator.MyIndicator)(from a in ChartControl.Indicators where a.Name == "MyIndicator"
            select a).FirstOrDefault();

            which works perfectly when I add my strategy to a chart and enable it. However, as I said in my original note, when I try to optimize my strategy via the strategy optimizer, ChartControl is null. So the question remains ...
            how to get a reference to an Added indicator from something other than the chart control?
            Thanks ... Ed
            You cannot.

            It may not be such a good idea to be using the undocumented ChartControl if you can avoid it. Instead, create a named instance of the indicator object, and refer to that specific instance.

            Comment


              #7
              Hi,
              Thanks for the response. The question here is ... how? How do I "create a named instance of the indicator object?"
              Thanks ... Ed

              Comment


                #8
                Originally posted by edstaffin View Post
                Hi,
                Thanks for the response. The question here is ... how? How do I "create a named instance of the indicator object?"
                Thanks ... Ed
                Either one of these posts demonstrate how to declare and reference a named instance of an indicator.

                ref: http://www.ninjatrader.com/support/f...d.php?p=221406

                Comment


                  #9
                  Take 2

                  Hi,
                  Let me try this from a different angle.
                  Here is what I am trying to accomplish. I have a completed indicator that works like a champ. I want to create a strategy for it. I have a set of properties on my indicator that are designed to communicate indicator state to the strategy. Chief among them is a property called DoTrade, which tells the strategy to enter a trade.

                  I could duplicate my code in the strategy (and in fact I have done this in the past), however, that means maintaining duplicate code in 2 places ... bad.

                  So, I want to reference a running indicator in my strategy. Going through the chart control to get that reference works perfectly on a chart, but does not work when going through the strategy analyzer. The question is, how can I get my already working code to play nice with the analyzer?

                  Thanks ... Ed

                  Comment


                    #10
                    Originally posted by edstaffin View Post
                    Hi,
                    Let me try this from a different angle.
                    Here is what I am trying to accomplish. I have a completed indicator that works like a champ. I want to create a strategy for it. I have a set of properties on my indicator that are designed to communicate indicator state to the strategy. Chief among them is a property called DoTrade, which tells the strategy to enter a trade.

                    I could duplicate my code in the strategy (and in fact I have done this in the past), however, that means maintaining duplicate code in 2 places ... bad.

                    So, I want to reference a running indicator in my strategy. Going through the chart control to get that reference works perfectly on a chart, but does not work when going through the strategy analyzer. The question is, how can I get my already working code to play nice with the analyzer?

                    Thanks ... Ed
                    Is DoTrade a public property? What kind of primitive is it? A bool, int or double? Or is it a member of a ...Series?

                    Comment


                      #11
                      DoTrade is a public bool property that is one of several similar properties such as Direction (short), EntryPoint (double) etc.
                      Thanks ... Ed

                      Comment


                        #12
                        Originally posted by edstaffin View Post
                        DoTrade is a public bool property that is one of several similar properties such as Direction (short), EntryPoint (double) etc.
                        Thanks ... Ed
                        In accordance with both of the threads to which I referred you initially.

                        Declare an instance of the object.
                        Code:
                        #Variables
                        private MyIndicator m_iMyIndicator;
                        Initialize the object, and Add, if wanted visually
                        Code:
                        protected override void Initialize()
                        {
                        // ...
                        m_iMyIndicator = MyIndicator(desired parameters listed here, comma delimited);
                        Add(m_iMyIndicator);
                        // ...
                        }
                        Use the object, by referring to its public properties.
                        Code:
                        protected override void OnBarUpdate()
                        {
                        // ...
                        
                        //such as,
                        bool SomethingThatDependsOnDoTrade = ... m_iMyIndicator.DoTrade ...;
                        
                        //or,
                        if (m_iMyIndicator.DoTrade)
                        {
                        //MakeMegaBucks();
                        }
                        
                        //...
                        }
                        You have to make sure the DoTrade is populated correctly, by calling Update() in the getter of the indicator.

                        The alternative will be to make DoTrade a boolSeries, trading convenience for memory use.

                        ref: http://www.ninjatrader.com/support/f...ead.php?t=4991

                        Comment


                          #13
                          I knew there was some magic sauce!

                          Hi,
                          Got it!
                          So the big issue turned out to be the missing Update() call in my indicator's getters.
                          I don't know how I was supposed to know about this without someone like you telling me but I am ever so grateful you did.

                          Thanks again ... Ed

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          633 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          364 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
                          567 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          568 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X