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 cmoran13, 04-16-2026, 01:02 PM
      0 responses
      42 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      25 views
      0 likes
      Last Post PaulMohn  
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      162 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      98 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      157 views
      2 likes
      Last Post CaptainJack  
      Working...
      X