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 Hwop38, 05-04-2026, 07:02 PM
      0 responses
      160 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      307 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      245 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      348 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      178 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X