Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to interact with indicators added to strategy?

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

    how to interact with indicators added to strategy?

    I have the following situation.

    I have customized an indicator and added two public methods to it. These methods are used to provide the pricelevels on which horizontal bars will be drawn (these lines represent the entry and exit values that are in effect). When I add the indicator to a chart and change the settings via the UI everything works correct.

    Now I'm adding this indicator to a strategy via the add() method in the initialize method of the strategy, as documented. However, this does not return a reference to the created indicator on the chart.
    Endresult is that I have no means (pointer or reference) of communicating with indicators I've added in a strategy, althoug they have the public methods in place to interact with.

    I've ran out of ideas here and I'm hoping I missed something obvious.Hope someone can help or shatter my intentions for good

    #2
    If your custom indicator does not hold any plots, then OnBarUpdate() will not be called. You need to call the Update() method within your public property getter. Call this method before returning the property value will force a call on OnBarUpdate() and ensure that the indicator calculations are up to date.
    RayNinjaTrader Customer Service

    Comment


      #3
      Thanks for answerring Ray,

      Unless I misunderstand you, what you describe is not the answer to my issue.

      Let me first explain a bit more about what this indicator is doing.

      The indicator has one plot which draws itself correctly. There are also two horizontal lines in the indicator pane which are initially drawn at levels as provided in the parameters.

      However, these horizontal lines are drawn with the DrawHorizontalLine method (not with add()) as they are dynamic and the levels at which they are drawn can and will dynamically change. Hence, I have created two public methods (set methods) that can be called to provide new values where the horizontal lines need to be drawn. As soon as one of these values changes, the indicator calls RemovesDrawObjects and then draws the horizontal lines at the newly indicated levels.

      The above works perfectly stand-alone when I add the indicator to a chart.


      When I add this indicator via the add() method to a strategy it plots and draws everything correctly. That is not the problem.

      My strategy later on determines certain entry/exit thresholds and to visualise this I would like to display these levels on the indicator chart (hence why I made the lines dynamic in the first place). The only thing I would need to do in my strategy is call these two public set methods in my indicator and provide the new levels for the horizontal line and the indicator will do the rest.

      Now, and this is my real problem, I cannot call these two public set methods of the indicator as I do not have a reference/handle to the indicator object itself.

      When I added the indicator with the add() method in the strategy I get no reference/handle returned, so I cannot do <indicator handle>.Setmethod(<value>).

      So after this long story, my question is, How can I interface with an indicator object after it is added to a strategy via the add() method?

      Hope this makes things a bit clearer.

      Comment


        #4
        One of my tech's will dig deeper into this inquiry on Monday.
        RayNinjaTrader Customer Service

        Comment


          #5
          So you are trying to pass values from the strategy back into the indicator and have the horizontal lines update from these strategy values?

          If you could upload an as-simple-as-possible version of both your strategy and indicator it would help us diagnose this scenario. Thanks.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Hi Josh,

            Yes, what you describe is exactly what I'm tring to achieve. Unfortunately I do not have a simplefied version available at this time (and it will take me some time to make one..) but I think you know what I'm after and we understand eachother.

            basicly my one and only question is:

            How can I obtain the object/reference/handle (whatever you call it) to an indicator I add to a strategy with the add() method. The add() method does not return this, so hopefully there is another way.


            If this question answered the rest will fall into place.

            Comment


              #7
              Okay then please post the exact error message you are receiving and if you could please post at least your public set methods and the line of code where you are attempting to Set the values from your strategy.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Well Josh,

                and that is exactly were my problem is...

                I do not have an error message for you (if I was only that far) because I don't know how to call the public methods of the indicator that I have added to the strategy with add() .

                Let me use the dataseries object as an example.

                Code:
                 
                [FONT=Courier New][COLOR=#0000ff]private[/COLOR] DataSeries myDataSeries;[/FONT]
                 
                [FONT=Courier New]myDataSeries = [COLOR=#0000ff]new[/COLOR] DataSeries([COLOR=#0000ff]this)[/COLOR][/FONT]
                The code above creates a new Dataseries object and the handle to the object is put in the variable. Afterwards you can use this variable to access the object and call its methods. Standard procedure right?

                Now..when I add an indicator to a strategy in the following manner.

                Code:
                Add(SMA(20));
                then I get the indicator nicely drawn on the chart but I get no object reference back to allocate to a variable.. Hence, I have no way of communicating (calling the public methods) of this specific indicator later on.


                Hopefully this explains it in more detail and I'm hoping I'm missing something very obvious here.

                Comment


                  #9
                  Okay. Maybe I am not understanding what step you are at, but please see this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=4991

                  Essentially you just create yourself something like this:
                  Code:
                  // In Variables section
                  private double test = 0;
                  
                  // In Properties region
                  public double Test
                  {
                      get { Update(); return test; }
                  }
                  Now in the strategy you would just do:
                  Code:
                  IndicatorName().Test = 0.5;
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    I tried that initialliy but it didn't work.. I get the following error

                    "No overload for method <indicator> takes '0' arguments"

                    ...which I can understand.


                    however, going forward on your idea...if I can make an overloaded version of my indicator which takes only the two needed variables then I would be in business I guess.

                    Any tips on how to do that?

                    Comment


                      #11
                      You need to pass in all the proper parameters of your indicator. If your indicator takes 2 parameters you need to do IndicatorName(param1, param2).Test = 0.5.

                      You call your indicator how you normally would. Just add .Test or whatever you name your variable as.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        Gosh Josh, we are getting somewhere now.
                        Something is happening so we are one step closer.

                        Unfortunately, not the right thing yet. The problem I'm having now is that the variable that I'm trying to set is also part of the parameter list.


                        So, lets say my indicator looks like the following:

                        indicator(int parm1,int parm2, int parm3, bool test)


                        I then try to set the public method as follows:

                        indicator(value 1,value2,value3, true).test=false;


                        hence, I provide a parameter value to the same variable as I'm trying to set with the method.


                        I think this is easy to solve. I just need to prevent the variables that I have defined as being part of the parameter list. However, I have no clue how to do that.

                        Hope you can help me out once more..


                        I guess asking for a C++ scriptlanguage is too much to ask for .......this C# is so weird...

                        Comment


                          #13
                          I suggest you separate them out. Use two separate variables.
                          Josh P.NinjaTrader Customer Service

                          Comment


                            #14
                            I have that, they are seperate variables with seperate Properties.


                            I have done the following..

                            Code:
                             
                            [Description("Description of property")]
                            [Category("Parameters")]
                            public int Method1 
                            {
                                     get { return var1; }
                                     set { var1 = value; }
                            }
                            In the piece of code above the is the line that says
                            Category("Parameter"), I change "Parameter" to "Test". By doing that after compilation the variable is removed from the parameter list of the indicator, which is what I want.

                            I'm wondering if there are any other special keywords that can be used in "category" that have a special meaning or that you can just make somethig up?

                            Comment


                              #15
                              You can make up what you want. If you remove the line entirely you won't see the option anywhere which is what I would do because it is not something I would want to change manually.
                              Josh P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              589 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              342 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              103 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              555 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X