NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > Application Technical Support > Miscellaneous Support > Historical Version 7 Beta Threads > Version 7 Beta General Questions & Bug Reports

Version 7 Beta General Questions & Bug Reports Ask questions here and post bug reports.

 
 
Thread Tools Display Modes
Old 10-08-2010, 07:00 AM   #1
cgeorgan
Senior Member
 
Join Date: Dec 2008
Location: Ann Arbor, MI
Posts: 323
Thanks: 4
Thanked 0 times in 0 posts
Default Trapped exception - BarsArray in 'Initialize' method

I've been getting a lot of fatal errors recently, and I plucked the following message out of the trace file:

"...OnUnhandledThreadException
************exception trapped ************
'BarsArray' property can't be accessed from within 'Initialize' method.
at NinjaTrader.Indicator.IndicatorBase.get_BarsArray( )

This exception was thrown when the following was executed:
(DTN-IQ) Data.Bars.GetBarsNow: instrument = 'YM 12-12' from (all the stuff it normally asks for; it's on a different computer so I'm not going to type it all out).

All this was done on an optimization run.

Now, this is something I'm aware of - I do not, in fact, attempt to access the "BarsArray" property anywhere in my code on Initialize().

I do access the following, and have been doing so without error for weeks now:
PeriodType
BarsPeriod

That's it.

So, if somebody has an idea why I would get the "BarsArray" exception, please let me know -
cgeorgan is offline  
Old 10-08-2010, 07:33 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

cgeorgan, please do not access those properties in the Initialize(), as they would have not been defined in there, as there's no bars object yet.
NinjaTrader_Bertrand is offline  
Old 10-08-2010, 07:36 AM   #3
cgeorgan
Senior Member
 
Join Date: Dec 2008
Location: Ann Arbor, MI
Posts: 323
Thanks: 4
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
cgeorgan, please do not access those properties in the Initialize(), as they would have not been defined in there, as there's no bars object yet.
Wait, I don't follow - I can consistently access this information, and I've done so literally thousands of times through live trading.

I know the base property of my strategy - it knows what the base property of its own bars is. I access that value so that I can pass it to multiple new series that each have multiples of the base series.

This exception is rare - if it were a real problem I'd get hit with it literally dozens of times an hour. What's the story?
cgeorgan is offline  
Old 10-08-2010, 07:55 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

Correct, it might or might have not worked - the bottom line is - it should not be accessed in the Initialize() as there may be times when there's no object yet and thus you run into issues as you've seen -

http://www.ninjatrader.com/support/h...barsperiod.htm
NinjaTrader_Bertrand is offline  
Old 10-08-2010, 07:57 AM   #5
cgeorgan
Senior Member
 
Join Date: Dec 2008
Location: Ann Arbor, MI
Posts: 323
Thanks: 4
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
Correct, it might or might have not worked - the bottom line is - it should not be accessed in the Initialize() as there may be times when there's no object yet and thus you run into issues as you've seen -

http://www.ninjatrader.com/support/h...barsperiod.htm
Again, this is something that I have a hard time making sense of. Programming isn't magic, things occur regularly and in sequence.

When, exactly, is this information available for use to the programmer?
cgeorgan is offline  
Old 10-08-2010, 08:02 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

You can either work in OnStartUp() or the first OnBarUpdate() bar (CurrentBar == 0).
NinjaTrader_Bertrand is offline  
Old 10-08-2010, 08:06 AM   #7
cgeorgan
Senior Member
 
Join Date: Dec 2008
Location: Ann Arbor, MI
Posts: 323
Thanks: 4
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
You can either work in OnStartUp() or the first OnBarUpdate() bar (CurrentBar == 0).
Wow, I had no idea there was an additional method that essentially replicated "Initialize()". OnStartUp is exactly where this needs to be, thanks!
cgeorgan is offline  
Old 10-08-2010, 08:41 AM   #8
cgeorgan
Senior Member
 
Join Date: Dec 2008
Location: Ann Arbor, MI
Posts: 323
Thanks: 4
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
You can either work in OnStartUp() or the first OnBarUpdate() bar (CurrentBar == 0).
Alright, here's why I realize now this didn't work the first time I tried it.

I access the "PeriodType" and "BarsPeriod" values in the Initialize() method because I use that to create higher time frame series based on the original series fed to the strategy. These higher time frame series are then added with the add() method within the Initialize() method, because that's the only place a programmer can add data series.

I honestly can't think of another way to programmatically add different time series based off the initial time series without doing it this way. If your programmers know another way that does not include hard-coding the base time frame type and period, I'm interested in hearing it.

Thanks!
cgeorgan is offline  
Old 10-08-2010, 09:20 AM   #9
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

cgeorgan, your findings are accurate - we would unfortunately not support the dynamic adding of series 'on the fly' - you could just add a range of series per se and then access the bars array needed dynamically from the strategy (for example base 1 min, then add 2-15 in 1 min steps, drive strategy by BIP context then).
NinjaTrader_Bertrand is offline  
Old 10-08-2010, 09:43 AM   #10
cgeorgan
Senior Member
 
Join Date: Dec 2008
Location: Ann Arbor, MI
Posts: 323
Thanks: 4
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Bertrand View Post
cgeorgan, your findings are accurate - we would unfortunately not support the dynamic adding of series 'on the fly' - you could just add a range of series per se and then access the bars array needed dynamically from the strategy (for example base 1 min, then add 2-15 in 1 min steps, drive strategy by BIP context then).
Well, truth be told, you actually can do this...you're just subject to the occasional (and I want to stress that "occasional" means once out of every 100 instances) exception being thrown.
cgeorgan is offline  
Old 10-08-2010, 09:46 AM   #11
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
Default

Quote:
Originally Posted by cgeorgan View Post
Well, truth be told, you actually can do this...you're just subject to the occasional (and I want to stress that "occasional" means once out of every 100 instances) exception being thrown.
Correct, it might or might not work for you - officially the dynamic adding of series is unfortunately not supported by us.
NinjaTrader_Bertrand is offline  
Old 10-08-2010, 10:32 AM   #12
dave1992
Senior Member
 
Join Date: Nov 2008
Location: UK
Posts: 637
Thanks: 0
Thanked 1 time in 1 post
Default

Quote:
Originally Posted by cgeorgan View Post
Wow, I had no idea there was an additional method that essentially replicated "Initialize()". OnStartUp is exactly where this needs to be, thanks!
No, you can't rely on OnStartUp for bars 100% of the time. See post #13 here


http://www.ninjatrader.com/support/f...628#post178628
dave1992 is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
exception trapped trying to change audio alert NT7 gg80108 Miscellaneous Support 20 01-07-2011 02:18 PM
Add() method in Initialize() gregsallee Version 7 Beta General Questions & Bug Reports 3 02-24-2010 09:50 AM
Exception Trapped kiwibird Automated Trading 7 01-12-2009 08:41 AM
Syntax of BarsArray with LowestBar() method Sidhartha General Programming 7 04-13-2008 09:55 AM
Accessing BarsArray[0].Period.Value inside Initialize() jbeninga Strategy Development 10 03-22-2007 01:49 AM


All times are GMT -6. The time now is 03:49 PM.