Announcement

Collapse
No announcement yet.

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 Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        581 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        337 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
                        554 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