PDA

View Full Version : initializing a varable


ceesvh
06-19-2007, 01:44 PM
Hi,

I need a counter in the following example code.

if(......)
{
count=count+1;
}

However I need to give the varable count an initial value otherwise I get an error. But putting int count=1; above the code does not work, because every time count is reset to 1. Putting int count=1; in the initialize section does not work either, neither the statements
int count;
if (currentBar==1) count=1;

I am a newbie to NT but have experience with other programming languages and EL.

Any help will be appreciated

NinjaTrader_Dierk
06-19-2007, 02:05 PM
Not sure I follow. Why can't you declare your variable like this:
int count = 0;

This code will compile fine. The variable will be set to 0 every time you e.g. throw an indicator or strategy on you chart.

NinjaTrader_Ray
06-19-2007, 03:33 PM
Please make sure you declare the variable outside of the OnBarUpdate() method. Since you likely want the scope of this variable to be for the indicator and not local to any method (function) you will then need to declare it for the class itself. Look for the "Variables" section and put the variable there.

private int count = 0;

then you can use this variable in any method within the indicator.