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
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
-
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.
-Brett
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.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by ninza33, Today, 07:16 AM
|
0 responses
1 view
0 likes
|
Last Post
by ninza33
Today, 07:16 AM
|
||
Started by linkcou, Today, 07:01 AM
|
0 responses
3 views
0 likes
|
Last Post
by linkcou
Today, 07:01 AM
|
||
Started by brunoviveiros, 02-17-2020, 05:31 AM
|
4 responses
63 views
0 likes
|
Last Post Today, 06:25 AM | ||
Started by volIQ, 03-27-2024, 04:28 PM
|
3 responses
21 views
0 likes
|
Last Post
by RJay
Today, 05:41 AM
|
||
Started by Nickgiaco, 02-26-2024, 10:23 AM
|
2 responses
72 views
0 likes
|
Last Post Today, 05:12 AM |
Comment