Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

where should variables be declared?

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

    where should variables be declared?

    Hi,

    I'm writing a custom indicator and have some questions.

    Do I declare all variables in the Initialize() section of code?

    If I declare them in the onBarUpdate section and set them to 0 are they then reset to 0 every bar?

    I see the variables I set up in the Wizard as user inputs in the Initialze() section. Why do these not have types? If I declare a variable in that manner in that section, I get a compiler error message.

    Thanks,

    Folls



    #2
    imported post

    If you are wanting to add a user defined input, you must declare a private variable in the "Variables" section, then create a property accessing that variable in the Properties section. Try creating an input via the wizard and then review the code generated to understand the concept. Then copy and paste and change the names. You can then set the property in the Initialize() method.

    Creating a variable in the OnBarUpdate() method is local to that method and will always be reset to zero. If you want to create a variable local to the indicator itself and not for use as an inputthat maintains its value between OnBarUpdate() calls, then declare it under the "Variables" section.

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Sorry Ray. I didn't notice those little collapse and expand boxes. The variables and properties boxes defaulted to collapse and thus I saw no code there. Now that I see the code, things make more sense. Sorry! My eyes can't see all those tiny light gray markings as I get older.

      Folls

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      571 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      330 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      548 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      548 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X