PDA

View Full Version : intra-bar/inter-tick variable persistance ?


zoltran
04-03-2007, 06:02 PM
Another amibroker-ish question.

AFL has no intra-bar 'memory'. Ie, it recalculates every bar from the begining of the series every tick. This isn't an issue with daily or bar-close indicators, but it sure is an issue in R/T as new intra-bar ticks can move your indicator all over the place

How is this handled in NinjaScript. ?
For example,
ie
1) if x = true then do something
2) x = close> sma(9)

Tick1
- x is false the 1st tick into the bar and statement 1 does not branch out.
- Statement 2 is executed and sets it to be true.
Tick 2
- Will x remain set for the next tick/pass ?

NinjaTrader_Dierk
04-03-2007, 06:14 PM
Hmm not sure I follow. Since NinjaScript basically is C#, the livetime concepts of C# for variables do apply.

a) Any class variable you defined in your strategy (see "Variables" region) is persisted as long as the strategy is running.

b) If you define a varoiable within the scope of the OnBarUpdate method then it's not persisted as you processed the current tick and returned from the OnBarUpdate method.

NinjaTrader_Ray
04-04-2007, 12:46 AM
Here are examples to illustrate what Dierk was stating.With example 1, x is preserved from tick to tick. Example 2 likely behaves like AFL where x is not preserved from tick to tick.



Example 1:

private bool x = false;

OnBarUpdate()
{
if (x)
// Do something

x = close > SMA(9)[0]
}





Example 2:

OnBarUpdate()
{
bool x = false;

if (x)
// Do something

x = close > SMA(9)[0]
}

zoltran
04-04-2007, 01:12 AM
Thanks Dierk and Ray!