![]() |
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
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
(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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Yes. I would use FirstBarOfSession.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks Ray and Dierk!
tb |
|
|
|
|
|
#6 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#9 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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
Josh
NinjaTrader Customer Service
Last edited by NinjaTrader_Josh; 07-07-2008 at 04:52 AM.
|
|
|
|
|
|
#10 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
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... |
|
|
|
|
|
#11 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
tb,
I am unable to reproduce your behavior on my end. Please attach a simple as possible reference that demonstrates what you are experiencing.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: May 2008
Posts: 50
Thanks: 0
Thanked 0 times in 0 posts
|
Josh,
thanks. I think I have the culprit. Can I can send you some code sample offline? Thanks tb |
|
|
|
|
|
#14 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
Please mail Josh a simple as possible strategy/scenario to josh AT ninjatrader DOT com. Thanks
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |