Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
What is BarsSinceSession
Collapse
X
-
Here is an indicator that collects the high and low of the pre-session and then calculates the opening range after the regular session has started. The indicator comes open source, so you can study how it works.
Basically, you need to determine the start of the trading day in line with the session template. Then you compare the timestamp of the bar with the time that you have selected for the anchor point of your range. You let OnBarUpdate() loop through all the bars until the specified closing time of your range. With each loop you collect the bar high and low of each bar, and if needed update the high and low of the range.
There is one problem, if you look at bars built from ticks. Usually tick bars do not align with the anchor and closing time of your range, but you will get two overlapping bars in the beginning and in the end of your range. Therefore it is a better solution to add a secondary bar series of 1-minute bars to your indicator and perform all calculations on 1-minute bars, as the 1-minute bars typically align with the anchor time and closing time of the range.
You can find the indicator here:
If you are not an elite member of that forum, please send me a private message with your e-mail, and I will send you the install file.
-
More Confusion between session and trading day
First of all: I'm a noob re: NT7, but have quite some programming experience in my previous life, however I'm at a loss regarding this Bars.BarsSinceSession thing ...
1. I want to find the High/Low for a certain range of time, let's say: What's the High/Low from 00:00:00h until 15:29h?
2. I want to find the bar within that timeframe which has the highest amount of volume tied to it (e.g. at 09:07 the volume was the highest at 4501 contracts traded that minute)
I spent the whole day digging up various sources, but I'm at a loss, so hopefully some of you nice people can point me in the right direction. Thanks much in advance.
- ABC
Leave a comment:
-
Hello adamus,
Bars.FirstBarOfSession will be true on the first Bar of the new session even if it is 5 mintues after the session has started if there is no data to generate a bar.
Let us know if we can be of any further assistance.
Leave a comment:
-
OK thanks.
Do you know whether FirstBarOfSession is true only for the bar at the time of the session start, or if I am missing a bar of data at the start, will the next bar be true instead?
Leave a comment:
-
Originally posted by adamus View PostIs BarsSinceSession correct when Historical is true or is it only valid for the last bar of the chart?
Is that the same for FirstBarOfSession too?Last edited by Harry; 01-24-2015, 06:56 AM.
Leave a comment:
-
Is BarsSinceSession correct when Historical is true or is it only valid for the last bar of the chart?
Is that the same for FirstBarOfSession too?
Leave a comment:
-
But it is easy to calculate the number of bars since the session start. Here is the code
Code:[COLOR=Blue]# region[/COLOR] Variables [COLOR=Blue]private int [/COLOR]count = 0; ........ [COLOR=Blue]#endregion[/COLOR] [COLOR=Blue]protected override void[/COLOR] OnBarUpdate() { [COLOR=Blue] if[/COLOR] (FirstTickOfBar) { [COLOR=Blue]if[/COLOR] (Bars.FirstBarOfSession) count = 0; [COLOR=Blue]else[/COLOR] count = count + 1; } ....... }
Leave a comment:
-
Hello beierde888,
What Harry said is correct. Basically, if there are multiple Sessions within one calendar day NinjaTrader will not reset the BarsSinceSession until the next calendar day (based on your Local PC).
I believe it is more of a design limitation but either way that is something on our Enhancement list for NT8 NinjaScript.
Let me know if you have any questions.Last edited by NinjaTrader_JC; 07-24-2013, 07:06 AM.
Leave a comment:
-
Confusion between session and trading day
This is one of the well known NinjaTrader bugs. For many NinjaScript methods there is a confusion about the concept of a trading session and a trading day, as originally, when the software was designed, the difference between "trading day" and "session" was not understood.
The method Bars.BarsSinceSession returns the bar number since the start of the trading day. The first bar of the trading day is counted as zero.The counting does not reset at the beginning of the afternoon session. NinjaTrader here calls the trading day a session.
There are quite a few other problems resulting from this confusion. For example in a strategy all orders GTD (good till day), will be cancelled at the end of the session instead at the end of the trading day. For that reason I am now partly coming back to the use of single session trading days, when running automated strategies. NinjaTrader here calls the session a trading day, which is the reverse problem to the one encountered above.
Please make sure that this confusion is being sorted out for NinjaTrader 8!
Leave a comment:
-
Hello, I have a question.
When I am using Bars.BarsSinceSession >= 2 , it works perfectly in the morning session, there will be no trades until the third bar. However during the afternoon session, trading starts from the first bar. I am using the ose session template.
Thanks in advance.
Leave a comment:
-
Hello savekad,
Yes, if you have data for 2 sessions then the Bars.BarsSinceSession will return the bar number of the latest/current session.
Leave a comment:
-
So it is the number of bars since the starting of the session according the to session template in use?
That means that there could be a chart loaded with bars of two sessions, and the BarsSinceSession will return the number of bars for the current one, ignoring the previous one, correct?
Leave a comment:
-
Hello savekad,
Bars since session returns how many bars has elapsed since the start of the session.
Session is the session template you apply on the chart via the Data Series parameter dialog.
Last edited by NinjaTrader_Joydeep; 08-23-2012, 03:45 AM.
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by PaulMohn, Today, 03:49 AM
|
0 responses
7 views
0 likes
|
Last Post
by PaulMohn
Today, 03:49 AM
|
||
Started by inanazsocial, Today, 01:15 AM
|
1 response
9 views
0 likes
|
Last Post Today, 02:18 AM | ||
Started by rocketman7, Today, 02:12 AM
|
0 responses
10 views
0 likes
|
Last Post
by rocketman7
Today, 02:12 AM
|
||
Started by dustydbayer, Today, 01:59 AM
|
0 responses
4 views
0 likes
|
Last Post
by dustydbayer
Today, 01:59 AM
|
||
Started by trilliantrader, 04-18-2024, 08:16 AM
|
5 responses
23 views
0 likes
|
Last Post Today, 12:32 AM |
Leave a comment: