Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Struggling moving from tradestation to Ninja

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

    Struggling moving from tradestation to Ninja

    In Tradestation Easy Language you can create user-defined variables to use in the decision tree for trade signals. In TS the process is:
    1) Give the variable a name and a default value
    2) Specify the calculation of the variable mathematically and/or conditionally.
    3) The variable is updated each bar.
    3) Use the resultant value in your decision tree.

    I cannot figure out how to do this in Ninja Script. When I try I get method group or operand errors.

    Can someone point me to some information on how to create user-defined variables that can be used in strategies?

    #2
    Hello Steve,

    Thank you for your post.

    We have a reference sample which covers how to create User Defined Variables:



    Please apply the concepts in this guide and let me know if you run into any trouble.
    MatthewNinjaTrader Product Management

    Comment


      #3
      OK, tried that and received the following error when compiling " Your strategy likely holds one or more recursive properties......." When I choose to"edit" the recursive properties, it highlights the variable's name (momen) in the properties section:

      [Description("")]
      [GridCategory("Parameters")]
      public double momen
      {
      get { return momen; }
      set { momen = Math.Max(.5, value); }

      Comment


        #4
        Hello,

        You will need to change the public double to a Captial

        Code:
        [Description("")]
        [GridCategory("Parameters")]
        [COLOR="Red"]public double Momen
        [/COLOR]{
        get { return momen; }
        set { momen = Math.Max(.5, value); }
        }
        MatthewNinjaTrader Product Management

        Comment


          #5
          Just realized I put "public" instead of "private". When I put private it says the strategy already contains a definition for momen.

          Comment


            #6
            You will want it to be Public here, however this public variable should be capitalized.
            MatthewNinjaTrader Product Management

            Comment


              #7
              When I try to specify the calculations for momen say, close[0] - close[10], I get an error stating "close" is not allowed in the current context.

              private double momen = (close[0] - close[10]);
              Last edited by SteveH; 07-24-2013, 01:06 PM.

              Comment


                #8
                C# is CaSe sensative, so make sure you are calling the close data point by using the captial letter. Additionally, to get the most recent close price, you will want to use bar index of [0]

                Code:
                momen = Close[0] - Close[10];
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Now I get: "An object reference is required for the non-static field, method or property "NinjaTrader.Strategy.StrategyBase.Close.get"

                  Comment


                    #10
                    The Close data series needs to be set in the OnBarUpdate() method of your code.

                    Code:
                            #region Variables
                    		// first declare the variable type and name
                    		private double momen = 0;
                           
                            #endregion
                    Code:
                            protected override void OnBarUpdate()
                            {
                                            //here in OnBarUpdate you can set the value to the variable
                    			momen = Close[0] - Close[10];
                    			
                            }
                    MatthewNinjaTrader Product Management

                    Comment


                      #11
                      OK. If I follow the process correctly I need to:
                      1) Establish the variable in the //User defined variables section
                      2) Define the variable in the #region Properties section
                      3) Enter the calculations in the OnBarUpdate section

                      Correct?

                      Comment


                        #12
                        Hello,

                        Yes, that is correct
                        MatthewNinjaTrader Product Management

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        648 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        369 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        108 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        572 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        573 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X