for(int d = 0; d < lookback && !conditionOccurred; d++) { Print(Closes[1][d]); }
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
Multi-time frame Indicator
Collapse
X
-
Multi-time frame Indicator
I've created an indicator that I want to check prices of previous daily bars while loading on shorter time frame charts. For some reason that I can't work out it's generating an error that there's not enough bars loaded. It's a simple loop that prints the closing prices of the daily bars. It seems to stop after 3 or 4 bars for the secondary series, and won't go back any further, even though the data is there. Any help would be appreciated.
Code:Error on calling 'OnBarUpdate' method on bar 6134: 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.Last edited by Matts; 12-10-2016, 12:41 AM. -
Hello,
Thank you for the post.
To find the problem, it would be best to add some more information and print it out to find out what specifically is happening.
A good place to start would be to print the CurrentBar and the d variable:
Code:Print("Current Bar: " + CurrentBars[1] + " d: " + d);
You can also add a check in the for loop to break if the period is too great:
Code:if(d >= CurrentBars[1]) break;
I look forward to being of further assistance.JesseNinjaTrader Customer Service
-
This is the output:
Current Bar: 4 d: 0
Closes 0.74401
Current Bar: 4 d: 1
Closes 0.74021
Current Bar: 4 d: 2
Closes 0.73871
Current Bar: 4 d: 3
Closes 0.73937
Current Bar: 4 d: 4
Closes 0.73571
Current Bar: 4 d: 5
Indicator 'HzPriceLine': Error on calling 'OnBarUpdate' method on bar 6136: 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.
Comment
-
Originally posted by Matts View PostIs it possible to load the secondary series independently of the data loaded on the chart, such as loading 1 year worth of daily bars, with a few days of minute data on the chart?
As for your original post, I was wondering if the following could provide you with what you were looking for........
Code:protected override void OnBarUpdate() { if (BarsInProgress == 1) { if(CurrentBars[1] != 0) { Print(Closes[1][0]); } } }
Comment
-
Thanks Paul, is there a way to make sure that enough bars are loaded on the primary series? I'd like to have a way of making sure that the user loads enough bars on the chart, by having a lookback parameter set the number of days to load, instead of having it return if there's not enough bars. Are there any performance issues with loading about 500,000 bars on a shorter timeframe?
Assiduous
Comment
-
(edited)
Hello,
It is possible to request an arbitrary amount of data by doing a BarsRequest instead of adding a secondary series.
You can ensure that the script does not run in there is not enough data by adding a return.
For example:
if (CurrentBars[0] < 10 || CurrentBars[1] < 10)
return;
This would prevent the script from executing until both the primary and secondary series have 10 bars each.
You could also check the BarsPeriods[0].BarsPeriodType and BarsPeriods[0].Value and ensure the values here are what are expected, and prevent the script from processing if they are not.
The more data you load, the more resources it will take in memory and the more calculations the script must do. Each computer is different. We cannot predict if a certain amount of data will cause performance issues with your machine.
Was there a different behavior you wanted to happen other than the script not running if the data is not satisfied?Last edited by NinjaTrader_ChelseaB; 12-13-2016, 04:17 PM.Chelsea B.NinjaTrader Customer Service
Comment
-
Hello Chelsea,
thanks for replying. I should firstly clear up that I’m not Assiduous, that was for the previous poster on the thread.
The behaviour that I want to happen, is that when the indicator is loaded an int variable would be set by the user for the number of days to load in the secondary series. The primary series would then load additional data if there wasn’t enough data on the chart. If preventing the script from running is the only option, I'd have to notify the user to load more data. The problem with this is that if more data isn't loaded the indicator simply won't work, and this will be expected for most shorter time frame charts, which will only have a few days of data loaded.
My question about performance is more related to the number of bars and what is generally a safe amount to load, as it needs to be able to run on any machine. Is data loaded on a 1 minute chart going to use a lot more resources than if loaded on a daily chart? I don't want to use something like BarsRequest that is instrument specific, as the indicator needs to work for any chart instrument. Can BarRequest be used to load the current instrument of the shorter time frame?
I noticed that it's possible to choose the barsToLoad parameter when adding a data series for a different instrument, but not when using the same instrument. It'd be good to have this option when adding data series for the same instrument.
Comment
-
Hello Matts,
I'm not quite sure what you mean when you say a BarsRequest is instrument specific.
A bars request will work for any instrument you supply to the BarsRequest. This is an addon function for non synchronized data. Meaning, this will not use the Instrument of the script, it will use the instrument that you supply to it.
I cannot predict how many bars will be a safe amount on your machine.
When using AddDataSeries, it is not possible to set a Days to load or Bars to load. This is only possible when doing a BarsRequest.Chelsea B.NinjaTrader Customer Service
Comment
-
What I meant was that it requires a string for the instrument name, and I don't know what instrument the chart will be loaded for, so it'd need to access the name of the instrument on the chart.
It looks like I can access the string through ChartBars.Bars.Instrument, so I'll try using BarsRequest with that.
* I ended up solving this by setting ChartBars.Properties.DaysBack to make sure there's enough data on the chart. It's a lot easier than BarRequest.Last edited by Matts; 12-13-2016, 06:30 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Lele2k24, Yesterday, 11:24 AM
|
8 responses
27 views
0 likes
|
Last Post
by Lele2k24
Today, 11:00 AM
|
||
Started by Padan, Today, 02:02 AM
|
4 responses
15 views
0 likes
|
Last Post
by Padan
Today, 10:46 AM
|
||
Started by kramnor2001, Yesterday, 02:30 PM
|
4 responses
24 views
0 likes
|
Last Post
by bltdavid
Today, 10:44 AM
|
||
Started by eduardodipp7, Today, 10:29 AM
|
0 responses
2 views
0 likes
|
Last Post
by eduardodipp7
Today, 10:29 AM
|
||
Started by AgriTrdr, 07-16-2023, 12:54 PM
|
39 responses
272 views
0 likes
|
Last Post
by f.saeidi
Today, 10:23 AM
|
Comment