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 User Defined Strategy Variable?

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

    Adding User Defined Strategy Variable?

    Different strategies have different variables or parameters that the user can change when running the strategy.

    I would like to know how to add such a parameter to my strategy that is visible and editable through the "Edit Strategy" dialogue. Just making the variable in the code is not enough and I have been unable to find this on the forums or the help documentation.

    Also, I would like to add a new column under the strategies tab to display some of these variable at all time, but that is secondary to creating them.

    Thank you.

    #2
    Hello elkinnm,
    To assist you further may I know are you editing the strategy via the Strategy Wizard or via the NinjaScript Editor.

    I look forward to assisting you further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      I am editing through the NinjaScript editor. I would not mind using the strategy wizard, but I have very specific goals and don't know if the wizard will be sufficient.

      Comment


        #4
        Hello elkinm,
        Thanks for the clarification.

        You need to create custom properties to do it. For example if you are calling an SMA with and periodicity of 14 from a strategy then the code will be.

        Code:
        double smaValue = SMA(14)[0];
        Now if you want to make the periodicity (i.e. 14) a variable (so that you can enter any value via the strategy parameters dialog), then please modify it as per below:

        in variable
        Code:
        private int smaPeriod = 14;  //default value is 14
        in OnBarUpdate
        Code:
        double smaValue = SMA(smaPeriod)[0];
        in properties
        Code:
        [Description("Period for SMA")]
        [GridCategory("Parameters")]
        public int SMAPeriod
        {
        	get { return smaPeriod; }
        	set { smaPeriod = Math.Max(1, value); }
        }
        You can also refer to this post which discusses more on NinjaScript parameters


        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thanks, but so far it did not work.

          in the properties I added:

          public int MaxPos
          {
          get{return maxPos;}
          set{maxPos = MaxPos;}
          }

          In variables I have:
          private int maxPos = 5;

          and under Initialize I have:
          this.MaxPos = maxPos;

          Then I compiled with no errors.
          Then I tried adding applying my new strategy expecting to find a new MaxPos variable, but it was not there.

          Is there anything else I missed?

          Thanks again.

          Comment


            #6
            Hello,
            Please modify your code as per below:


            Code:
            public int MaxPos
            {
                  get{return maxPos;}
                  set{maxPos = [COLOR="Green"][B]value[/B][/COLOR];}
            }
            this is fine
            Code:
            private int maxPos = 5;
            no need for this
            this.MaxPos = maxPos;

            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Got it. The last piece I was missing was:
              [GridCategory("Paramaters")]
              without it it was showing up under misc and I could not see it.

              For the last piece, can you help me add a column under the strategies tab to display a value constantly, so I don't need to stop and edit the strategy to see it.
              So in this case I have a Parameters column, but I want a separate MaxPos column visible at all times.

              Some time ago I saw a post about doing this, but I don't remember how or how to find that post?

              Thanks again.
              Last edited by elkinm; 05-29-2012, 01:57 PM. Reason: update to post.

              Comment


                #8
                Hello elkinm,
                Glad to know you are able to run the strategy.

                Unfortunately, you cannot have a separate column for any individual strategy parameter. The Parameter column will display all the parameters.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  I thought for sure I saw a post about addint a new column.
                  For example, if I want to see some strategy value such a working quantity or some other calculation from the strategy?
                  And if there is no way, how can I see the strategy parameters without stoping the strategy. I often want to check what values it is using as it is running, but I don't want to turn it off.

                  Thanks

                  Comment


                    #10
                    Hello elkinm,
                    You can view the parameters from the Parameters column itself. However there are no way to have separate columns for each parameters.
                    Attached Files
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      OK, That works, what about a value from my code that is not a parameter? Is there a way to see it other then printing continually to the output window?

                      Thanks again.

                      Comment


                        #12
                        Hello elkinm,
                        There is no way other than printing the values in the Output Window for any private variable.

                        If you are using the chart to run the strategy then you can also consider using the code DrawTextField which will display the values of the private variables.



                        Please let me know if I can assist you any further.
                        JoydeepNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by AnnBarnes, Today, 12:17 PM
                        1 response
                        2 views
                        0 likes
                        Last Post NinjaTrader_Zachary  
                        Started by Lopat, 03-05-2023, 01:19 PM
                        4 responses
                        167 views
                        0 likes
                        Last Post Sam2515
                        by Sam2515
                         
                        Started by f.saeidi, Today, 12:14 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post f.saeidi  
                        Started by giulyko00, Today, 12:03 PM
                        0 responses
                        4 views
                        0 likes
                        Last Post giulyko00  
                        Started by AttiM, 02-14-2024, 05:20 PM
                        12 responses
                        213 views
                        0 likes
                        Last Post DrakeiJosh  
                        Working...
                        X