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 Noerclou, Today, 04:55 AM
      0 responses
      2 views
      0 likes
      Last Post Noerclou  
      Started by llanqui, Yesterday, 09:59 AM
      2 responses
      17 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by ThoriSten, Today, 03:56 AM
      0 responses
      6 views
      0 likes
      Last Post ThoriSten  
      Started by PhillT, 04-19-2024, 02:16 PM
      3 responses
      23 views
      0 likes
      Last Post mangel2000  
      Started by TraderBCL, Today, 02:37 AM
      0 responses
      4 views
      0 likes
      Last Post TraderBCL  
      Working...
      X