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 llanqui, 04-28-2024, 10:32 AM
                        6 responses
                        35 views
                        0 likes
                        Last Post llanqui
                        by llanqui
                         
                        Started by geotrades1, Today, 08:33 AM
                        6 responses
                        19 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Started by dcriador, Today, 10:45 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post dcriador  
                        Started by llanqui, 04-28-2024, 03:53 AM
                        2 responses
                        27 views
                        0 likes
                        Last Post llanqui
                        by llanqui
                         
                        Started by RaddiFX, Yesterday, 09:55 PM
                        5 responses
                        32 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X