NexusFi: Find Your Edge


Home Menu

 





NT8: DataSeries & Times Help!


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one kidvic with 2 posts (1 thanks)
    2. looks_two Quick Summary with 1 posts (0 thanks)
    3. looks_3 choke35 with 1 posts (1 thanks)
    4. looks_4 ratfink with 1 posts (3 thanks)
    1. trending_up 1,769 views
    2. thumb_up 5 thanks given
    3. group 2 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

NT8: DataSeries & Times Help!

  #1 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3

So I'm trying to get data from a secondary dataseries, week, and minutes.
I'm using the primary dataseries as 15 minutes.

The problem occurs when accessing the weekly dataseries, with a barsago value >= 2.......

the log tells me : Error on calling 'OnBarUpdate' method on bar 229: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

However, I have expanded days to load to 100, and infinite on the max bars lookback, so I don't know what's going!
Please help!
I have attached what's working, and what isn't.
 
Code
			else if (State == State.Configure)
			{
				AddDataSeries(BarsPeriodType.Week, 1); 
				AddDataSeries(BarsPeriodType.Minute, 60); 
			}
		}

		protected override void OnBarUpdate()
		{
			if (CurrentBars[0] <= 0 || CurrentBars[1] <= 0 || CurrentBars[2] <= 0) return;
			
			//these 3 work
			Print(Times[0][0]);
			Print(Times[1][0]);
			Print(Times[2][0]);
			
			//these 3 work
			Print(Times[0][1]);
			Print(Times[1][1]);
			Print(Times[2][1]);
			
			//these 2 work
			Print(Times[0][2]);
			Print(Times[2][2]);
			
			//but this one doesn't
			Print(Times[1][2]);
		}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
Quant vue
Trading Reviews and Vendors
REcommedations for programming help
Sierra Chart
 
  #3 (permalink)
 choke35 
Germany
 
Experience: Intermediate
Platform: Other
Trading: ES, YM, 6E
Posts: 2,668 since Feb 2013
Thanks Given: 5,101
Thanks Received: 6,558



kidvic View Post
 
Code
			
		
			if (CurrentBars[0] <= 0 || CurrentBars[1] <= 0 || CurrentBars[2] <= 0) return;

The problem is your above check. It doesn't prevent your code from trying to access bars that
yet don't exist at the time of the first non-return. E.g.: You are trying to access 2 weeks back
before your index provides 2 weekly bars back. Your CurrentBars might be >0 but that doesn't
ensure that the weekly index is >=2.

So in order to avoid that rookie fault: Access doesn't only depend on history which provides
the theoretical possibility of reaching the correct state at all. Particularly your logics must make
sure that at the point of access there is a sufficient number of bars.

It is helpful for most beginners to read the NT sections how bars develop, since the logical fault
of your code is really very basic.

Reply With Quote
Thanked by:
  #4 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,426


kidvic View Post
 
Code
	if (CurrentBars[0] < 3 || CurrentBars[1] < 3 || CurrentBars[2] < 3) return;

Try that instead. i.e. I'm checking for at least 3 bars to exist on all of the 3 data series before I can safely access any of them with subscripts [0], [1] or [2].

As @choke35 said, it's a question of whether the bars exist at all yet, effectively the series get going independently. [NB I am assuming 8 behaves similarly to 7 in this respect.]

Just vary the number of bars checked for, depending on your worst-case subscript. In this case I've set them all the same for simplicity. Since many bars will never be seen on screen the 'tightness' of the check is quite arbitrary really, so long as it is safe.

Cheers

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #5 (permalink)
kidvic
Los Angeles, CA
 
Posts: 92 since Mar 2015
Thanks Given: 13
Thanks Received: 3


choke35 View Post
The problem is your above check. It doesn't prevent your code from trying to access bars that
yet don't exist at the time of the first non-return. E.g.: You are trying to access 2 weeks back
before your index provides 2 weekly bars back. Your CurrentBars might be >0 but that doesn't
ensure that the weekly index is >=2.

So in order to avoid that rookie fault: Access doesn't only depend on history which provides
the theoretical possibility of reaching the correct state at all. Particularly your logics must make
sure that at the point of access there is a sufficient number of bars.

It is helpful for most beginners to read the NT sections how bars develop, since the logical fault
of your code is really very basic.

Thanks, it worked.

Reply With Quote
Thanked by:




Last Updated on October 7, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts