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

Calling Indicator into Strategy..but then what if

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

    Calling Indicator into Strategy..but then what if

    I have mastered the basic idea...

    Code:
    Add(AA01(1,18,55,3));
    My question is, how can I keep from hard re-coding the strategy every time I want to make a change to the indicator, which I can do in the settings of the indicator? For example: If I wanted to change the 18 to 24. Simple. I open the indicator, go to the correct parameter setting and make the change, hit apply, and it's done. But the strategy is still reading the "18" because it is hard coded. Isn't there a way to force the strategy to "read" the 24 and apply it?

    #2
    Hello sarasotavince,

    Thank you for your post.

    You would need to set a user defined variable in the strategy as well and then assign that variable when calling the AA01. For information on user defined variables please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=5782

    Comment


      #3
      I see. Seems the public int is the key...or at least the first step. Much appreciated. I now have some direction....

      Comment


        #4
        Patrick (or anyone),

        I have hit a road block... To keep it simple, here is the code from the Indicator AA01:

        Code:
        FROM Variables.....
        
        private int setTicks = 1;
        
        FROM Properties...
        
        [Description("How many ticks for trade signal")]
        [GridCategory("Parameters")]
                public int SetTicks
                {
                    get { return setTicks; }
                    set { setTicks = Math.Max(1, value); }
                }
        Now the code from the Strategy:

        Code:
        FROM protected override void Initialize()
        
        Add(AA01(SetTicks,18,55,3,0,0, etc.));
        The error message is when I try to compile the strategy: "SetTicks does not exist in the current location." If I replace the "SetTicks" with the indicator value of "1" then it compiles and runs no problem.

        What am I missing? Please and Thank You. I have also tried "setTicks" but with same results.
        Last edited by sarasotavince; 06-16-2014, 11:33 AM.

        Comment


          #5
          Hello sarasotavince,

          Thank you for your response.

          The variable needs to be created within the strategy as well, not just the indicator.

          Comment


            #6
            After reading your first post three (3) times, I tried that and it worked. So, here is my final question: Now I have the same variable in both the indicator and the strategy. I set the default value for the strategy variables at ZERO, since I am pulling all variable values from the indicator. Editing the value from strategy's property box should have no effect correct since the true value of the variable is coming from the property box of the indicator (once applied and saved), via the Add line in the strategy's code. Do I have this correct?

            Comment


              #7
              Hello sarasotavince,

              When you pass a parameter into the indicator method, that is the value that will be used. So if you set the Strategy's variable to 0 and pass that to the indicator method in the Strategy, the indicator is going to use 0. If you would like an example, please go to Tools > Edit NinjaScript > SampleMaCrossover > and view how the fast and slow variables in the strategy are passed as the period for the SMAs.

              Comment


                #8
                I am sorry Patrick but your example was of no help. I thought I was passing a value from an indicator to a strategy. I thought I needed that variable in both the indicator and the strategy. When I look at indicator SMA, there is no input for slow and fast, only a period. I see where SampleSMA uses the ADD line to get slow and fast but how it is getting it from SMA I have no idea, thus I have no example to build upon.

                Is there a more more detailed example you can suggest? Sometimes I find only a line or two these posts makes sense....more detailed examples help. I find the NT examples overly simplistic and not very useful...unfortunately. Thanks. I will keep trying.

                Comment


                  #9
                  Originally posted by sarasotavince View Post
                  I am sorry Patrick but your example was of no help. I thought I was passing a value from an indicator to a strategy. I thought I needed that variable in both the indicator and the strategy. When I look at indicator SMA, there is no input for slow and fast, only a period. I see where SampleSMA uses the ADD line to get slow and fast but how it is getting it from SMA I have no idea, thus I have no example to build upon.

                  Is there a more more detailed example you can suggest? Sometimes I find only a line or two these posts makes sense....more detailed examples help. I find the NT examples overly simplistic and not very useful...unfortunately. Thanks. I will keep trying.
                  You have only 2 choices: the indicator parameters are either fixed (hard coded) or they are adjustable.

                  If you want the indicator parameters to be adjustable, those parameters must be specified by the calling object (the strategy), and passed back to the called object (the indicator). The indicators output will always be available to the strategy: you simply have to access that output however you want to do so. In this scenario, you have a dual passing mechanism. The strategy determines what parameters it wants the indicator to use, and the indicator uses those parameters, and passes values back to the strategy.

                  Comment


                    #10
                    I now have the same variables in the indicator and the strategy, which seems redundant (but whatever). Since the strategy calls the indicator I only enter the variables values in the strategy, then as you say, pass them back to the indicator (which seems backwards). In any case, I can now change a variable "on the fly" and there is hard no hard coding in the strategy, which was the goal. Thanks All.

                    Comment


                      #11
                      Originally posted by sarasotavince View Post
                      I now have the same variables in the indicator and the strategy, which seems redundant (but whatever). Since the strategy calls the indicator I only enter the variables values in the strategy, then as you say, pass them back to the indicator (which seems backwards). In any case, I can now change a variable "on the fly" and there is hard no hard coding in the strategy, which was the goal. Thanks All.
                      No, it is not redundant. That is how OOP is supposed to work. Objects are independent entities, who must have their parameters passed correctly when they are invoked. The variables are not the same: they are completely independent, and have nothing really to do with each other unless you ask them to. They only have the same name, because that is what you chose to do.

                      And, yes. When I first started with OOP, it confused the heck out of me too.
                      Last edited by koganam; 06-18-2014, 01:36 PM.

                      Comment


                        #12
                        Fair Enough.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by kulwinder73, Today, 10:31 AM
                        1 response
                        8 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by RookieTrader, Today, 09:37 AM
                        3 responses
                        15 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by terofs, Yesterday, 04:18 PM
                        1 response
                        24 views
                        0 likes
                        Last Post terofs
                        by terofs
                         
                        Started by CommonWhale, Today, 09:55 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by Gerik, Today, 09:40 AM
                        2 responses
                        8 views
                        0 likes
                        Last Post Gerik
                        by Gerik
                         
                        Working...
                        X