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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      157 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      91 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      143 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      130 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      107 views
      0 likes
      Last Post CarlTrading  
      Working...
      X