PDA

View Full Version : where should variables be declared?


Folls
05-04-2007, 08:57 AM
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

NinjaTrader_Ray
05-04-2007, 09:25 AM
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

Folls
05-04-2007, 11:12 AM
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