![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
|
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.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
You could not re-trigger the Initialize() event then unfortunately - why not try working off a dynamic list that grows with your task?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
|
"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. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Mar 2010
Location: Sweden
Posts: 123
Thanks: 6
Thanked 4 times in 3 posts
|
So OnBarUpdate can never be called before Initialize and it can only be called once, correct?
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
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().
Bertrand
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Bertrand for this post: |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |