NinjaTrader Support Forum  
X

Attention!

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


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

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 07-03-2008, 12:09 PM   #1
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default BarsInSession vs CurrentBar

OnBarUpdate() I get

BarsInSession == 0
CurrentBar == 0
Time[0] == .. // verified as 15:31 (SessionStart is set to 15:30)
but
Bars.DayBreak == false

The thing I'm stubmling across is that DayBreak and BarsInSession seem not to be aligned???

tx
tb
tb2000 is offline  
Reply With Quote
Old 07-03-2008, 01:31 PM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

(Removed some posts, since I got confused)

Bars.DayBreak is not NinjaScript nor documented. It's your own risk if you see value in using non-documented features. However, we don't provide support for that.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 07-03-2008, 02:24 PM   #3
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default

Well - sorry, I inherited that code ...

Besides, Intellisync does show it (on VS I admit)...


So BarsSinceSession seems to be the proper (documented) identification for a session start and that one is in sync with

bool SessionStart == Bars.FirstBarOfSession or (Bars.BarsSinceSession==0)


ok? just to make sure..

tb
tb2000 is offline  
Reply With Quote
Old 07-03-2008, 03:36 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Yes. I would use FirstBarOfSession.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-03-2008, 09:36 PM   #5
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default

Thanks Ray and Dierk!
tb
tb2000 is offline  
Reply With Quote
Old 07-06-2008, 03:06 PM   #6
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default

I tried a bit further and still it seems it is possibly that FirstBarOfSession is false while BarsInSession==0, a contradiction ?
My conclusion would be that BarsInSession==0 is the only reliable indicaton of where we stand OnBarUpdate()-wise.
All that seems at the left edge of a chart if the database has an incomplete session (starting mid day e.g.).
tb
tb2000 is offline  
Reply With Quote
Old 07-06-2008, 03:40 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Why do you see it as a contradiction? FirstBarOfSession should be true when BarsSinceSession = 1. BarsSinceSession = 0 means there is nothing there so there is no first bar yet.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-07-2008, 04:26 AM   #8
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default

Josh, thanks - not sure you're right here, I keep getting FirstBarOfSession==true while BarsSinceSession==0.

Sometimes however - I guess depending on the tick database - I have seen FirstBarOfSession==false while CurrentBar==0 and BarsSinceSession==0,
thats where my Problem was.

Now the doc states
CurrentBar is starting from 0 - so here the index starts at 0
and on
BarsInSession it says "BarsElapsed" - so 0 Bars elapsed would mean no Bar is elapsed - we're either in building the 1st Bar (tick chart) or latest at the finish of the 1st bar (CalculateOnBarClose==true). So yes, we have no other Bars in session - but first occurence of BarsSinceSession==0 should be identical with FirstBarInSession.

Further details:

I have the following coming in on a minute chart:

//first OnBarUpdate event
CurrentBar==0
Bars.BarsSinceSession==0
FirstTickOfBar==true
Bars.FirstBarOfSession==true /*sometimes - it seems depending on the bars database - this can be false too - apparently (at least my conclusion) only if the timestamp of the 1st bar is at session start per primary chart property, FirstBarOfSession would be true. Not sure though.*/

//subsequent OnBarUpdate events where BarsSinceSession==0
CurrentBar==count
Bars.BarsSinceSession==0
FirstTickOfBar==true
Bars.FirstBarOfSession==true
//each next OnBarUpdate event after BarsSinceSession==0
CurrentBar==count+1
Bars.BarsSinceSession==1
FirstTickOfBar==true
Bars.FirstBarOfSession==false

-----

Why bother?

I need to start computing asap. regardless if SessionBreak or mid day.
So I took FirstBarOfSession - which seemingly was inadequate at the left edge
So now I take
BarsInSession==0 - that seems to work properly at the left edge and at the beginning of any subsequent new session.

Please correct me if I'm wrong..

tb
tb2000 is offline  
Reply With Quote
Old 07-07-2008, 04:43 AM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Sorry for the confusion. I was thinking about something else.

On a blank chart. You have 0 bars. This is a "0" beyond the 0 on BarsSinceSession. This is flat out nothing so Bars.___ won't return any values.

On a chart with data. The very first bar corresponds with BarsSinceSession = 0. This is the case because during this bar there have been no prior bars therefore bars since this session - none. On this bar you get FirstBarOfSession = true.

FirstBarOfSession is true whenever it is actually the first bar. It doesn't matter what your chart property for session start time is. If you have session start time at 4AM, but your first bar is timestamped at 4:05AM it will still come out true on that bar.

FirstBarOfSession should always be proper at the start of each new session. If you find otherwise please outline exact settings and such so we can try to reproduce.

Code:
6/23/2008 4:12:00 AM CurrentBar: 0 BarsSinceSession: 0 FirstBarOfSession: True
6/23/2008 4:14:00 AM CurrentBar: 1 BarsSinceSession: 1 FirstBarOfSession: False
6/23/2008 4:30:00 AM CurrentBar: 2 BarsSinceSession: 2 FirstBarOfSession: False
6/23/2008 4:31:00 AM CurrentBar: 3 BarsSinceSession: 3 FirstBarOfSession: False
...
6/23/2008 4:58:00 PM CurrentBar: 561 BarsSinceSession: 561 FirstBarOfSession: False
6/23/2008 4:59:00 PM CurrentBar: 562 BarsSinceSession: 562 FirstBarOfSession: False
6/23/2008 5:00:00 PM CurrentBar: 563 BarsSinceSession: 563 FirstBarOfSession: False
6/24/2008 4:03:00 AM CurrentBar: 564 BarsSinceSession: 0 FirstBarOfSession: True
6/24/2008 4:04:00 AM CurrentBar: 565 BarsSinceSession: 1 FirstBarOfSession: False
6/24/2008 4:20:00 AM CurrentBar: 566 BarsSinceSession: 2 FirstBarOfSession: False
6/24/2008 4:21:00 AM CurrentBar: 567 BarsSinceSession: 3 FirstBarOfSession: False
There is no discrepancy as far as I can tell. FirstBarOfSession is true when it is suppose to be and BarsSinceSession is 0 as expected. BarsInSession is not supported so you are on your own if you want to use that.
Last edited by NinjaTrader_Josh; 07-07-2008 at 04:52 AM.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-07-2008, 06:13 AM   #10
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default

Josh,
presently I can not verify this any more - I'll keep a lookout.
I am positively sure I had the boolean be false on the first tick - consistently - while the count was 0 correctly (all VS debug reads), so you might want to have a look at your side of the code if you like.
Thanks anyways!
tb

PS: The only thing I had modified at system level was a delete of a default workspace gone bad, not sure thats relevant...
tb2000 is offline  
Reply With Quote
Old 07-24-2008, 02:57 PM   #11
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi again!

Today on ES 09-08 (IB) database I can repeatedly trace that when starting NT the first OnBarUpdate() I am receiving is CurrentBar==1 - instead of an expected 0 (which the code I got uses - as there are redraws starting without an Initialize() and we need to find session start).

FirstTickOfBar is true
Bars.BarsSinceSession is 1 (also - instead of 0)
CalculateOnBarClose is false.
The chart is set to 1 min bars.

One observation: ChartControl.SessionBegin is 01.01.0001 00:00 - and the first tick I get carries the 09.07.2008 00:02:00 timestamp.

Once I set the session start to e.g. 09:30 for the symbol, that first tick is coming in with CurrentBar==0 - but regardless of that the first Bar I get with NT start seems always CurrentBar==1 (but 0 after pressing F5 to reload).

So what's the safest to determine session start at the left side of a chart?

Thanks ahead!

tb
tb2000 is offline  
Reply With Quote
Old 07-25-2008, 12:07 AM   #12
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

tb,

I am unable to reproduce your behavior on my end. Please attach a simple as possible reference that demonstrates what you are experiencing.
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-25-2008, 02:05 AM   #13
tb2000
Member
 
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
Default

Josh,
thanks. I think I have the culprit.
Can I can send you some code sample offline?
Thanks
tb
tb2000 is offline  
Reply With Quote
Old 07-25-2008, 02:33 AM   #14
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Please mail Josh a simple as possible strategy/scenario to josh AT ninjatrader DOT com. Thanks
NinjaTrader_Dierk is offline  
Reply With Quote
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
CurrentBar and Multi Time Frame maxpi Strategy Development 7 07-31-2009 01:07 PM
Display currentBar ? csmith87 Charting 3 06-20-2008 01:52 PM
(CurrentBar == 0) jriverac General Programming 7 05-21-2008 08:37 AM
Drawing a 'ray' starting from CurrentBar? FireFly Indicator Development 4 05-01-2008 09:17 AM


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