• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

User parameter get and set code

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

    User parameter get and set code

    I'm used to doing this for my user parameters in C#:

    Code:
            [Description("range width MA len")]
            [GridCategory("Parameters")]
            public int RangeWidthMaLen
            {
                get { return rangeWidthMaLen; }
                set { rangeWidthMaLen = value; }
            }
    I code mostly in Java when I'm not coding Ninjascript, so this is a bit unfamiliar. I've coded a class which is instantiated by my indicators and strategies with a straight constructor call when the instance is declared like this:

    Code:
    private LogHelper logHelper = new LogHelper();
    so I figure I can do something similar with get {} and set {} on my LogHelper class to initialize the variable directly from the indicator/strategy user parameter code, something like this:

    Code:
            // in the indicator
            private LogHelper logHelper = new LogHelper();
    
            [Description("Basic/Fills/Orders/OHLC")]
            [GridCategory("Parameters")]
            public LogHelper.LogDetail LogDetail
            {
                get { return logHelper.logDetail; }
                set { logHelper.logDetail = value; }
            }

    where LogDetail is an enum on LogHelper.

    I'm not clear how to code the set and get on the LogHelper class.

    Can I use the same sort of syntax like this?
    Code:
            public LogHelper.LogDetail LogDetail
            {
                    get { return logDetail; }
                    set { logDetail = value; }
            }
    or do I have to write out getLogDetail() and setLogDetail(LogDetail)?

    I'm going to try it now but I'd appreciate if someone could tell me what's correct so I don't end up messing around for ages.
    Thanks

    #2
    Hello adamus,

    Thanks for your note.

    While I do not see anything wrong with the syntax you are using, these methods are completely unsupported by NinjaTrader.

    The C# world is very unlimited on possible code practices. While NinjaTrader does allow for custom C# code, to be mindful of our resources we are only able to answer questions that are documented in our Help Guide.

    As such, there is a supported method to write to the log. This would be the Log() function.

    Please see the following document in our help guide.
    http://www.ninjatrader.com/support/h...es/nt7/log.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea B, thanks for the info. I'm familiar with the logging methods in NT7 already.

      I am coding a class which bundles up all the logging functionality that I need over and above what NT7 already provides. The main feature I need is to be able to log to file, mainly because the NT7 Output window doesn't allow me to search. So my class allows me to write to file, or to the output window, dependant on a parameter which I set to suit my needs.

      It's the getters and setters for this class that I wanted to make more efficient, hence my original question.

      I've played around with the format a bit and I grasped most of it.

      What I want to do is to have user parameters on my Indicator or Strategy which directly set the parameters on my logging class.

      It seems I can do this just by instantiating the logging class when declaring it in the indicator, and making its parameter variables public.

      Code:
          public class PermaCodeSR005 : Indicator
          {
              private LogHelper logHelper = new LogHelper();
      
      
              [Description("Comma-seperated list of markets to log (leave blank to see all markets)")]
              [Gui.Design.DisplayName("Market filter")]
              [GridCategory("Parameters")]
              public string LogMarkets
              {
                  get { return logHelper.marketFilter; }
                  set { logHelper.marketFilter = value; }
              }        
      }
      namespace PermaCode 
      {
          public class LogHelper
          {
              // User-defined params:
              public string marketFilter = "";
      As a software developer by trade I'm not happy with this work-around, e.g. making the variable public - especially if I ever decide to share the code - which I why I asked about using the C# set and get technique. If there is any straight-forward way of doing this which I'm missing, please let me know, although my reading didn't reveal anything but complex solutions.

      Comment


        #4
        Hi adamus,

        That I am aware of, the only way to access a variable in another class is to make the variable public in that class you are trying to set the variable for.

        Your other option is to combine the classes into one class so that you may keep all the variables private and then protect your code.

        That would involve duplicating that code for each indicator, however.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by adamus View Post
          Hi Chelsea B, thanks for the info. I'm familiar with the logging methods in NT7 already.

          I am coding a class which bundles up all the logging functionality that I need over and above what NT7 already provides. The main feature I need is to be able to log to file, mainly because the NT7 Output window doesn't allow me to search. So my class allows me to write to file, or to the output window, dependant on a parameter which I set to suit my needs.

          It's the getters and setters for this class that I wanted to make more efficient, hence my original question.

          I've played around with the format a bit and I grasped most of it.

          What I want to do is to have user parameters on my Indicator or Strategy which directly set the parameters on my logging class.

          It seems I can do this just by instantiating the logging class when declaring it in the indicator, and making its parameter variables public.

          Code:
              public class PermaCodeSR005 : Indicator
              {
                  private LogHelper logHelper = new LogHelper();
          
          
                  [Description("Comma-seperated list of markets to log (leave blank to see all markets)")]
                  [Gui.Design.DisplayName("Market filter")]
                  [GridCategory("Parameters")]
                  public string LogMarkets
                  {
                      get { return logHelper.marketFilter; }
                      set { logHelper.marketFilter = value; }
                  }        
          }
          namespace PermaCode 
          {
              public class LogHelper
              {
                  // User-defined params:
                  public string marketFilter = "";
          As a software developer by trade I'm not happy with this work-around, e.g. making the variable public - especially if I ever decide to share the code - which I why I asked about using the C# set and get technique. If there is any straight-forward way of doing this which I'm missing, please let me know, although my reading didn't reveal anything but complex solutions.
          If the class inherits/derives from nothing, then you must either expose a backing store using properties, or declare the variable as public, before it can be accessed from outside the class.

          However, as it seems to be just a variable, it might be easier to declare it protected in a partial class.
          Last edited by koganam; 07-23-2013, 01:23 PM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by thomaspartyof10, Today, 02:33 AM
          1 response
          18 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by manueldecastro, Yesterday, 12:57 AM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_ChrisL  
          Started by ArmKnuckle, Today, 01:59 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by seppyr, Today, 01:53 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by matthewbartlett, Today, 01:22 AM
          1 response
          10 views
          0 likes
          Last Post Emma1
          by Emma1
           
          Working...
          X