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

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 funk10101, Today, 12:02 AM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by GLFX005, Today, 03:23 AM
                        1 response
                        6 views
                        0 likes
                        Last Post NinjaTrader_Erick  
                        Started by nandhumca, Yesterday, 03:41 PM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by The_Sec, Yesterday, 03:37 PM
                        1 response
                        11 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by vecnopus, Today, 06:15 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post vecnopus  
                        Working...
                        X