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
How to Access Sessions Ninjascript?
Collapse
X
-
Hello cryfgg,
Thank you for your post.
The primary input series for the indicator will use the Trading Hours (session) template for that data series. Otherwise, your indicator could call AddDataSeries() with syntax that allows you to specify tradingHoursName if you'd like to add additional data using different sessions. The following warning should be kept in mind:- "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."
- AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm
Please let us know if we may be of further assistance.Emily C.NinjaTrader Customer Service
- "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."
-
Originally posted by cryfgg View PostI'm trying to build an indicator that will use two different session (1. Regular & 2. Extended session). How do I access Session Ninjascript?
Code:// class wide variables private SessionIterator sessionIterator; private DateTime session_startTime, session_endTime; private DateTime session_endTime; protected override void OnStateChange() { if (State == State.SetDefaults) { } // initialize the sessionIterator variable else if (State == State.DataLoaded) { //stores the session object once bars are ready, but before OnBarUpdate is called sessionIterator = new SessionIterator(Bars); } } // In OnBarUpdate() // local variables in OBU bool _IsFirstBarOfSession; DateTime intraSession_startTime; double elapsedTime; _IsFirstBarOfSession = Bars.IsFirstBarOfSession; if (_IsFirstBarOfSession) { // use the current bar time to calculate the next session sessionIterator.GetNextSession(Time[0], true); // store the desired session information session_startTime = sessionIterator.ActualSessionBegin; session_endTime = sessionIterator.ActualSessionEnd; if (isDebugOn) Print( String.Format("session_startTime: {0}, session_endTime: {1}", session_startTime, session_endTime) ); } elapsedTime = 930; // offset to add to the ETH session start time to identify the RTH session time intraSession_startTime = session_startTime.AddMinutes( elapsedTime ); if ( Time[0] > intraSession_startTime && Time[0] <= session_endTime) { // handle RTH bars } else { // handle ETH bars }
Last edited by trendisyourfriend; 09-25-2023, 12:32 PM.
Comment
-
Originally posted by NinjaTrader_Emily View PostHello cryfgg,
Thank you for your post.
The primary input series for the indicator will use the Trading Hours (session) template for that data series. Otherwise, your indicator could call AddDataSeries() with syntax that allows you to specify tradingHoursName if you'd like to add additional data using different sessions. The following warning should be kept in mind:- "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."
- AddDataSeries() - https://ninjatrader.com/support/help...dataseries.htm
https://ninjatrader.com/support/help...nstruments.htm
Please let us know if we may be of further assistance.
Comment
- "If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries."
-
Originally posted by cryfgg View Post
I know how to add DataSeries. I'm trying to figure out how to add sessions. For example, I want a moving average indicator that calculates and draws the moving average based on the regular session (9:30AM to 4pm) as well as based on the extended session (6pm to 5pm). In other words, there will be two moving averages on my chart based on two different sessions.
Otherwise, you could add a moving average indicator to your chart twice, once based on one session and a second time for data from the other session. You could even follow the steps in this video from our YouTube channel about plotting indicators on a "hidden" data series:
Please feel free to reach out with any additional questions or concerns.Emily C.NinjaTrader Customer Service
- Likes 1
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pibrew, Today, 06:37 AM
|
0 responses
0 views
0 likes
|
Last Post
by pibrew
Today, 06:37 AM
|
||
Started by rbeckmann05, Yesterday, 06:48 PM
|
1 response
12 views
0 likes
|
Last Post
by bltdavid
Today, 05:43 AM
|
||
Started by llanqui, Today, 03:53 AM
|
0 responses
6 views
0 likes
|
Last Post
by llanqui
Today, 03:53 AM
|
||
Started by burtoninlondon, Today, 12:38 AM
|
0 responses
10 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
15 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
Comment