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

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 bortz, 11-06-2023, 08:04 AM
      47 responses
      1,603 views
      0 likes
      Last Post aligator  
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      8 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      4 views
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      12 views
      0 likes
      Last Post Javierw.ok  
      Working...
      X