Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Times[] and Opens[] range
Collapse
X
-
Times[] and Opens[] range
Hi, how do I know current valid range of Opens[idx][] and Times[idx][] arrays, with idx referring to last, bid and ask data? I need to access all items of the Opens[idx] and Times[idx] in OnBarUpdate() to process historical tick data, but their range seems to vary during the session, e.g. after reloading the indicator. I can get Opens[idx].Count and Times[idx].Count property, but upper and lower limits seem to vary, they are definitely not from 0 to Count-1. Another thing, the range is not the same under some circumstances (quite often, but I cannot find a specific way to reproduce) and I get AurgumentOutOfRange exception when accessing the arrays at the same index. Any help appreciated. Thanks.Tags: None
-
Hello mantak007,
You generally only have to check this at the start of the series. Using something like the following prevents the script from accessing invalid values.
if (CurrentBars[1] < 0) return;
If this doesn't work for you, can you please share an example of what you're doing and the steps needed to see the same on our end?Ryan M.NinjaTrader Customer Service
-
OK, here is the sample. How do I set correct minRange and MaxRange variables to be able to iterate through the whole Times[lastIdx][] array? For simplicity I reduced the code just to reproduce the error. Thank you.Code:public class OpensTimesSample : Indicator { #region Variables private bool historicalDataLoaded = false; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { CalculateOnBarClose = false; Overlay = true; string instrumentName = "CL 09-11"; Add(instrumentName, PeriodType.Tick, 1, MarketDataType.Last); Add(instrumentName, PeriodType.Tick, 1, MarketDataType.Ask); Add(instrumentName, PeriodType.Tick, 1, MarketDataType.Bid); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[1] < 0) return; if(!historicalDataLoaded) { historicalDataLoaded = true; const int lastIdx = 1; int minRange = 0; int maxRange = Times[lastIdx].Count; for(int i=minRange; i < maxRange; i++) { Print(Times[lastIdx][i].ToString()); } } } #region Properties #endregion }
Comment
-
I don"t want you to debug the code, I need an information that is missing in the documentation - what is the valid range of Times[][] array. BTW, why are you asking for a sample if you don't want to use it at all? As for CurrentBar, how does it relate to Times and Opens? There is nothing in the documentation.
Comment
-
Hello,
Sorry for the miscommunication there on Berts response.
I checked into here and what your missing is CurrentBars[0].
This is the total number of bars in each bar series.
For example.
Times[0][CurrentBars[0]]
//primary series
or
Times[1][CurrentBars[1]]
//for the secondary series
This would be the first bar in the series and would be the end range. You can add and iterate with a counter all the way up to this value to go through all previous values and then if > this value stop or else you will run into a open
Caution here, this is going to be CPU intensive if you plan on running this live.
-BrettBrettNinjaTrader Product Management
Comment
-
Hi Brett, that's it, works great, thank you. As it looks, the CurerntBars[0] is the maximum index and the array Times goes to negative, but there is no lower limit. Let's say Times[0].Count is 100 and CurrentBars[0] is 10. Valid indices for Times[0][i] should be i={10, 9, ..., 0, -1, -2, ...,-98, -99}. But I can use i={-100, -101,...}all in fact returning the last value in the array. Is this a bug or is it by design? I think ArgumentOutOfRange should be thrown. No big problem of course, I'm just curious if I have not overlooked something else.
Comment
-
Hello,
It is possible to reference a value to the future with a negative bar reference. This is ok and expected and the reason why we don't do the exception.
You would only want to use values >0 to go back in the bars. Rarely would you use negative values here.
Let me know if I can be of further assistance.BrettNinjaTrader Product Management
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
601 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
347 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
559 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment