Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NT8 Best Practices Setting Variables Question

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

    NT8 Best Practices Setting Variables Question

    Hello,

    My question refers to the NT8 manual on the best practices section as seen below.

    I understand why variables which reset during the life of the script should be set in State.Configure; however in this example, is it showing that the script is moving the "changing values" completely out of the class level and into the State.Configure section? Or are they still kept in the class level and written again in the State.Configure?


    #2
    Hello Don22Trader1,

    Thank you for your post.

    Unfortunately, your image did not load properly. Are you referring to the following section of the NinjaScript Best Practices page regarding class level variables?

    Click image for larger version

Name:	classLevelVariables.png
Views:	213
Size:	58.4 KB
ID:	1219194




    If you are referring to something else, please try attaching the image again in your reply or paste it into the body of your reply so I may better understand which best practice you are referring to.

    Thank you for your patience. I look forward to your reply.

    Comment


      #3
      I apologize for that,

      Yes, I am referring to the section of the NinjaScript Best Practices page regarding class level variables.

      Hopefully the image appears this time below.

      Click image for larger version  Name:	ninjatrader best practices question.png Views:	0 Size:	85.2 KB ID:	1219199

      Comment


        #4
        Hello Don22Trader1,

        Thank you for confirming; the image did appear this time.

        In the example from the help guide, there are three variables being declared at the class level (multiplier, counter, and myList). The variable multiplier is also initialized at the class level with a value of 5 that will not change. The variables counter and myList are not moved completely out of the class level; they are declared at the class level and the value is set in State.Configure. This value may change (set, reset) throughout the life of the script. Here is another way to look at that example with different comments to make it more clear where in the code everything is happening:

        Code:
        // three variables being declared at the class level
        private const int multiplier = 5;     // this variable uses the const keyword to signal that it will not change.  it is initialized here (declared and set) with a value of 5
        private int counter;     // counter is being declared at the class level
        private List<int> myList;     // myList is being declared at the class level
        
        
        protected override voide OnStateChange()
        {
             // setting the values for counter and myList in State.Configure
             if (State == State.Configure)
             {
                  counter = 0;
                  myList = new List<int>();
             }
        }

        Please let us know if we may be of further assistance.

        Comment


          #5
          Ninjatrader_Emily,

          Awesome, thank you for your clarification.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          89 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          152 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          80 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          53 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          63 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X