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

How to iterate over all user-created "this.Parameters" in NT Strategy code.

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

    How to iterate over all user-created "this.Parameters" in NT Strategy code.

    Hello,

    My users are creating NinjaScript strategies, and they are creating custom parameters for their strategies that look something like this in the C# code:

    privateint ticksBetter = 1;

    [Description(
    "Ticks Better is used to do such-and-such.")]
    [Category(
    "Parameters")]
    publicint TicksBetter
    {
    get { return ticksBetter; }
    set { ticksBetter = Math.Max(0, value); }
    }

    I am looking for a way to iterate over all user-created custom parameters so that I can write this information out to a database. Using intellisense inside of a strategy, I can't find a collection like "this.Parameters". Is there a collection that holds these parameters that I can iterate over in C# code?

    Thanks in advance!

    ChiTrader2000

    #2
    Unfortunately ChiTrader2000, this is not supported.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      ChiTrader2000, it's not just not supported by NT, but there is no concept in C# which provides collections for methods, variables or properties automatically. Guess you have to collect it by your own.

      Regards
      Ralph

      Comment


        #4
        Hello,

        Thanks for the information.

        I will just write it myself using C# Reflection.

        Thanks again,

        ChiTrader2000

        Comment


          #5
          Just an idea for coding. Instead of using private variables like:
          private int ticksBetter = 1;
          you could use the desired (and self-designed) collection as source the properties are reading from, and as target the properties are writing to. This way your collection is always up-to-date without additional coding required.

          Regards
          Ralph


          Comment


            #6
            Hello Ralph,

            That's a great way to do it without using System.Reflection. Problem solved!

            Thanks again!

            ChiTrader2000

            Comment


              #7
              Hi there:

              Alright, I'm fairly new to NT and only started to code in C# but I have been coding in Java for over 12 years. Take a look at this:



              In Java it's possible to use 'introspection' to dynamically retrieve a class' parameters and then loop through them. The article covers both Java and C#.

              Good luck!

              Michael

              Comment


                #8
                Can you tell us what function is called to get the Parameter name string that is displayed in the chart, or in the Parametesr column of the strategies tab?

                Comment


                  #9
                  Never mind, me and my seemingly limitless genious has figured it out!



                  public string getParameterString()
                  {
                  string parameterString = "";

                  foreach( NinjaTrader.Strategy.Parameter parameter in this.Parameters)
                  {
                  parameterString += "( ";
                  parameterString += parameter.Name;
                  parameterString += " = " + parameter.Value;
                  parameterString += " ) - ";

                  }
                  return parameterString;

                  }

                  Comment


                    #10
                    Note: this is a area which is beyond what we provide support for. Please be aware that the undocumented features you're using might be gone or work differently on next NT version/release.

                    Comment


                      #11
                      When's that? Approx?

                      Comment


                        #12
                        Hello,

                        There is no set release date. We are hoping to get it into Beta testing within a few months.
                        DenNinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by WHICKED, Today, 12:56 PM
                        2 responses
                        15 views
                        0 likes
                        Last Post WHICKED
                        by WHICKED
                         
                        Started by Felix Reichert, Today, 02:12 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post Felix Reichert  
                        Started by Tim-c, Today, 02:10 PM
                        0 responses
                        1 view
                        0 likes
                        Last Post Tim-c
                        by Tim-c
                         
                        Started by cre8able, Today, 01:16 PM
                        2 responses
                        9 views
                        0 likes
                        Last Post cre8able  
                        Started by chbruno, 04-24-2024, 04:10 PM
                        3 responses
                        49 views
                        0 likes
                        Last Post NinjaTrader_Gaby  
                        Working...
                        X