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

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 Christopher_R, Today, 12:29 AM
          0 responses
          9 views
          0 likes
          Last Post Christopher_R  
          Started by sidlercom80, 10-28-2023, 08:49 AM
          166 responses
          2,235 views
          0 likes
          Last Post sidlercom80  
          Started by thread, Yesterday, 11:58 PM
          0 responses
          3 views
          0 likes
          Last Post thread
          by thread
           
          Started by jclose, Yesterday, 09:37 PM
          0 responses
          8 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,415 views
          0 likes
          Last Post Traderontheroad  
          Working...
          X