NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 07-18-2012, 04:20 PM   #1
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
Default Bars.BarsInSession property?

Is there a way to obtain the number of bars in a session (trading day) before calculating it in OnBarUpdate( )? I would need it to simplify declaring and initializing a jagged array.

Kindly, FREEN
FREEN is offline  
Reply With Quote
Old 07-19-2012, 02:32 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

Unfortunately there would not be a supported property to query those ahead...you can use Bars.BarsSinceSession on the last of the first session completed to know the value. Alternatively for time based you would know the # of bars provided it's a liquid instrument.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-20-2012, 07:05 AM   #3
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
Default

Thanks Bertrand! Yes, I´m aware this:

if(Bars.LastBarOfSession)
{
Print((Bars.BarsSinceSession+1).ToString());
}

Sorry to ask without having tried yet, would it be possible to trigger the OnBarUpdate events only at first session, do the Initializing/declaring with collected data from that session, then run the the OnBarUpdate events as usually?
Last edited by FREEN; 07-20-2012 at 07:09 AM.
FREEN is offline  
Reply With Quote
Old 07-20-2012, 07:14 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

You could not re-trigger the Initialize() event then unfortunately - why not try working off a dynamic list that grows with your task?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-20-2012, 07:54 AM   #5
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
Default

"Although this method is called once on the start of an indicator or strategy, there are times that this method is also called (Opening an indicator dialog) when you may not expect it to."

Q 1: Is it possible to do the Initializing after OnBarUpdate event/-s?:

OnBarUpdate
-collect data

First Session end flag

Initialize

OnBarUpdate
-main code

Q 2: List.Add during first session? Thanks, I´ll look into if that does the trick.
FREEN is offline  
Reply With Quote
Old 07-20-2012, 08:00 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

FREEN, the event sequence seen is Initialize(), OnStartUp(), OnBarUpdate() - this could not be changed unfortunately.

Correct you would add to your list as the OnBarUpdate() runs, it would dynamically size as needed (contrary to classic array)

http://www.dotnetperls.com/list
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-20-2012, 08:04 AM   #7
FREEN
Senior Member
 
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
Default

So OnBarUpdate can never be called before Initialize and it can only be called once, correct?
FREEN is offline  
Reply With Quote
Old 07-20-2012, 08:13 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

OnBarUpdate() is always called after Initialize() for your script, however Initialize() can be called multiple times...so if you seek a method that's called one time before the first OnBarUpdate(), use OnStartUp().
NinjaTrader_Bertrand is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Bertrand for this post:
Reply

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
EntriesPerDirection property pureflame Strategy Development 1 10-12-2010 05:18 AM
Basing one Property/Parameter on Another Property/Parameter gregschr General Programming 5 08-10-2010 11:31 AM
Saving bars back property on charts JS999 Suggestions And Feedback 4 02-26-2010 01:19 AM
Added Property to Strategy but Not Showing on Property Grid stocastix Automated Trading 2 11-07-2008 04:00 PM
BarsInSession vs CurrentBar tb2000 General Programming 13 07-25-2008 02:33 AM


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