Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Thread Tools Display Modes
Old 01-01-2014, 02:01 PM   #1
Senior Member
Join Date: Jan 2013
Posts: 368
Thanks: 45
Thanked 27 times in 24 posts
Default Indicator Sets Session Template

Is it possible to set the session template in an indicator? I have an indicator that requires different 24 hour sessions for ES, CL, ZN, ect...but I don't want to change the default instrument session template, which is the regular RTH hours. Only when I call this indicator do I want to use the 24 hour template.
habibalex is offline  
Reply With Quote
Old 01-01-2014, 03:34 PM   #2
Senior Member
Join Date: Oct 2007
Posts: 3,383
Thanks: 258
Thanked 803 times in 605 posts

Originally Posted by habibalex View Post
Is it possible to set the session template in an indicator? I have an indicator that requires different 24 hour sessions for ES, CL, ZN, ect...but I don't want to change the default instrument session template, which is the regular RTH hours. Only when I call this indicator do I want to use the 24 hour template.

You can select the session template for each bar series that has been added when you open a chart. The session template configures the bars, as the last bar of each session is cut off at the session break.

If you add an indicator, this indicator will always use the session template of the bar series that is selected as input series for this indicator via the indicator dialogue box. The indicator cannot run on a different session template.

A special case are multi-instrument indicators. If for an instrument no bar series has been added to the chart and if such a bar series for the instrument is loaded by the indicator itself, the session template stored under <instrument settings> will be used.

For example it is impossible to calculate indicator values from an ETH session template and display those value on a chart that uses a RTH session template.
Last edited by Harry; 01-01-2014 at 03:40 PM.
Harry is offline  
Reply With Quote
The following user says thank you to Harry for this post:
Old 02-13-2018, 01:52 PM   #3
Junior Member
Join Date: Nov 2008
Posts: 28
Thanks: 2
Thanked 0 times in 0 posts
Default NinjaTrader 8 Indicator using different Session Template to instrument's chart?


Is it possible for an instrument's (e.g. ES) chart to be using a CME US Index Futures ETH session template but for an indicator to calculate the prior sessions OHLC based on the CME US Index Futures RTH session template? If so could someone kindly point me in the right direction please?

Many Thanks.
dowtrader is offline  
Reply With Quote
Old 02-13-2018, 03:54 PM   #4
NinjaTrader Customer Service
NinjaTrader_PatrickH's Avatar
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,549
Thanks: 780
Thanked 1,994 times in 1,921 posts

Hello dowtrader,

Thank you for your post.

It is possible to do this through NinjaTrader 8. You can add a bar series to the script of the instrument with the desired Trading Hours Template but you would need to hard code the instrument name and would not be able to dynamically apply the Trading Hours Template to any instrument without it being hard coded in the indicator. Please visit the following link for more information: https://ninjatrader.com/support/help...dataseries.htm

In NinjaTrader 7 there is no option for this through the Add() function.

Another alternative that would work in NinjaTrader 7 and NinjaTrader 8 is to use a time filter and assign the opening price to a variable, the closing price to a variable, and then calculate the highest high through the time range and the lowest low through the time range.

For example:
		private double myTimeRangeOpen = 0;
		private double myTimeRangeClose = 0;
		private double myTimeRangeHigh = double.MinValue;
		private double myTimeRangeLow = double.MaxValue;
		protected override void OnBarUpdate()
			if (ToTime(Time[0]) >= ToTime(9,0,0)
				&& ToTime(Time[0]) <= ToTime(17,0,0))
				if (myTimeRangeOpen == 0)
					myTimeRangeOpen = Open[0];
				if (High[0] > myTimeRangeHigh)
					myTimeRangeHigh = High[0];
				if (Low[0] < myTimeRangeLow)
					myTimeRangeLow = Low[0];
			if (ToTime(Time[0]) >= ToTime(17,0,0)
				&& myTimeRangeClose == 0)
				myTimeRangeClose = Close[0];
Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
The following user says thank you to NinjaTrader_PatrickH for this post:
Old 02-14-2018, 08:59 AM   #5
Senior Member
Join Date: Jul 2009
Posts: 366
Thanks: 118
Thanked 52 times in 38 posts

You don't need to hard code the FullName of the instrument on the chart which is Instrument.FullName. The trading hours argument of the method can be ANY valid session name from the list of available Trading Hours Templates but make sure you get all the characters exactly right. Refer to the documentation for the AddDataSeries method in the help guide. Have a nice Current Day, and Prior Day, too!

         ~ variable declarations ~

         private string sessionStringE

         ~ State.Configure ~

         sessionStringE="CME US Index Futures ETH";
		 (     Instrument.FullName,
			new BarsPeriod() {BarsPeriodType = BarsPeriodType.Tick, Value = 1},					
Attached Images
File Type: png RTY 03-18 (20 Tick) 2018_02_14.png (85.2 KB, 8 views)
Last edited by Ricam; 02-14-2018 at 09:09 AM.
Ricam is offline  
Reply With Quote
The following user says thank you to Ricam for this post:

session template

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
how to create a multi session session template br8080 Platform Technical Support 1 02-02-2013 09:56 PM
Session Template, Indicator not working jmflukeiii Indicator Development 9 04-12-2012 05:30 AM
Backtest session template different from real time session chart Francis Platform Technical Support 1 10-10-2011 07:10 AM
Multi timeframe indicator passses output value for default session template poseidon_sthlm Indicator Development 3 01-07-2011 12:37 PM

All times are GMT -6. The time now is 02:07 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.