Thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Last bars of previous session
Collapse
X
-
Hello siroki,
Thank you for your post.
You can check the last five bars when the current bar is the first bar of the session and use highest and Lowest Bar to determine the range.
Code:if(Bars.FirstBarOfSession) { double last5MinRange = High[HighestBar(High, 5)] - Low[LowestBar(Low, 5)]; }- For information on FirstBarOfSession please visit the following link: http://www.ninjatrader.com/support/h...rofsession.htm
- For information on HighestBar please visit the following link: http://www.ninjatrader.com/support/h...highestbar.htm
- For information on the LowestBar please visit the following link: http://www.ninjatrader.com/support/h.../lowestbar.htm
-
Hello Siroki,
Thank you for your response.
My previous example would include the first bar of the new session. Please try the following to calculate this on the last bar of the session:
For information on GetNextBeginEnd() please visit the following link: http://www.ninjatrader.com/support/h...xtbeginend.htmCode:private DateTime sessionBegin; private DateTime sessionEnd; protected override void OnBarUpdate() { if(Bars.FirstBarOfSession) { Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd); } if(Time[0] == sessionEnd) { double last5MinRange = High[HighestBar(High, 5)] - Low[LowestBar(Low, 5)]; Print(last5MinRange); } }
Comment
-
Ah, interesting solution. I wasn't aware of the Bars.Session.GetNextBeginEnd method.
Do you think it would be a safer to use if(Bars. BarsSinceSession == 390) compared to if(Time[0] == sessionEnd)? I heard sometimes it might give problems with daylight saving etc.
btw: 390 are the number of 1 minute bars in a session.
Thanks for your help!Last edited by siroki; 03-27-2014, 03:17 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
662 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
376 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
110 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
580 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment