PDA

View Full Version : Accessing BarsArray[0].Period.Value inside Initialize()


jbeninga
03-18-2007, 04:51 AM
Don't know if this is pilot error on my part or not.... but I added the following line to my Initialize() method.

int myPeriod = BarsArray[0].Period.Value;

also tried:

int myPeriod = Bars.Period.Value;

with the following results.

1) Code compiled cleanly
2) Click "Backtest" in StrategyAnalyzer.
3) Backtest dialog box comes up but has no parameters (it is completely blank!)
4) Clicking on OKgenerates a System.NullReferenceException

I'm trying to create a larger timeframe view that is a multiple of the current period in a multibar strategy. So I need the Period of the base chart in order to cumpute the longer timeframe.

Thanks,

Jim

jbeninga
03-18-2007, 04:55 AM
Follow up to previous post. I am able to access Bars and BarsArray inside OnBarUpdate() successfully. But by then it is too late to Add() additional chart views.

Chicken and egg problem?

NinjaTrader_Dierk
03-18-2007, 11:16 AM
You neither should access Bars nor BarsArray in Initialize method. Please try BarPeriods[0].

jbeninga
03-21-2007, 12:13 AM
OK, I tried

myBarPeriod = BarPeriods[0].Period.Value;

and received the following during compilation

"The name 'BarPeriods' does not exist in the current context"

no go....

I've hard coded the view sizes for now, so is not a big issue. It just seems like I *should* be able to find out the size and type of the primary chart while Initializing.

One more question if I may, should it be OK to store a reference to BarsArray in a class member in Initialize() or should I wait until the first OnBarUpdate()?

Thank you

Jim

NinjaTrader_Ray
03-21-2007, 01:58 AM
Dierk will respond to this one upon his return, he is out for a few days.

NinjaTrader_Dierk
03-22-2007, 12:56 AM
Is was referring to strategies not indicators. Code below is not supported for indicators.

jbeninga
03-22-2007, 01:05 AM
But..... This is a strategy :cool:

Jim

NinjaTrader_Dierk
03-22-2007, 01:12 AM
Please try:
BarsPeriods[0].Value

jbeninga
03-22-2007, 01:40 AM
That worked! :)


Processed 314213 bars in 00:00:41.0781250

So... feeling empowered I also tried

myBarType = BarsPeriods[0].Type;

which did not :XBut thank you for the first one.

Jim

NinjaTrader_Dierk
03-22-2007, 01:42 AM
Please try
BarsPeriods[0].Id

jbeninga
03-22-2007, 01:49 AM
That worked also! ;)Way Cool!


Processed 314213 bars in 00:00:38.9062500

Thank You!

Jim