Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable naming convention?

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

    Variable naming convention?

    I noticed that the strategy wizard names a variable with a lowercase first letter, then there is this body of code at the end which assigns the same variable name except with uppercase first letter as compared to the original.

    Should I be using the variable with the uppercase or the lowercase in my OnBarUpdate() and Initialize() functions? Is there a difference?

    Thanks!

    Code:
    #region Variables
    private int timeResolution = 1;
    #endregion
    
    ...
    ...
    
    	[Description("Time resolution")]
            [GridCategory("Parameters")]
            public int TimeResolution
            {
                get { return timeResolution; }
                set { timeResolution = Math.Max(1, value); }
            }
    Last edited by llstelle; 11-13-2012, 12:20 PM.

    #2
    Hello llstelle,
    The strategy wizard do so to match the property name and the private variable name.

    You can use any one of it. They will return the same.

    NinjaScript is basically C# and follows the normal C# rules.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by llstelle View Post
      I noticed that the strategy wizard names a variable with a lowercase first letter, then there is this body of code at the end which assigns the same variable name except with uppercase first letter as compared to the original.

      Should I be using the variable with the uppercase or the lowercase in my OnBarUpdate() and Initialize() functions? Is there a difference?

      Thanks!

      Code:
      #region Variables
      private int timeResolution = 1;
      #endregion
      
      ...
      ...
      
          [Description("Time resolution")]
              [GridCategory("Parameters")]
              public int TimeResolution
              {
                  get { return timeResolution; }
                  set { timeResolution = Math.Max(1, value); }
              }
      Correct use is to use the public name. That is because the accessors can contain code. However, in many cases, it really does not make a difference, as ultimately, the backing store will reflect the same value as the public variable.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      600 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      347 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      558 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      558 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X