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

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 wzgy0920, 04-20-2024, 06:09 PM
      2 responses
      26 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, 02-22-2024, 01:11 AM
      5 responses
      32 views
      0 likes
      Last Post wzgy0920  
      Started by wzgy0920, Yesterday, 09:53 PM
      2 responses
      49 views
      0 likes
      Last Post wzgy0920  
      Started by Kensonprib, 04-28-2021, 10:11 AM
      5 responses
      191 views
      0 likes
      Last Post Hasadafa  
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,230 views
      0 likes
      Last Post xiinteractive  
      Working...
      X