Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Index Out of Range for multi-series

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_ChelseaB
    replied
    Hello habibalex,

    Thank you for including the output.

    The issue is that there are only 40 bars of the secondary series processed when this is called. (i.e. CurrentBars[1] is on bar 40)

    Look at the print you have provided.

    CurrentBars[1]: 40 | endI: 80

    The secondary series has only processed 40 bars (likely because this is a larger time frame than the primary series).

    However, you are calling the time of a bar on the secondary series 80 bars ago (endI).

    You cannot call a bar 80 bars ago when there are only 40 bars processed in that series.
    Last edited by NinjaTrader_ChelseaB; 12-30-2015, 08:31 AM.

    Leave a comment:


  • habibalex
    replied
    On ES using a 1 minute chart w/ the session set to <Use Instrument Settings> (CME US Index Futures RTH ) I get the following output from your indicator:

    key: 80 | BarsArray[0].Count: 1035 | BarsArray[1].Count: 207 | Times[1].Count - 1 - key: 126
    CurrentBars[1]: 40 | endI: 80
    Indicator 'FlipsTest': Error on calling 'OnBarUpdate' method on bar 205: 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.

    It is still failing on Line 89: Print(Times[1][endI]); Times[1].Count = 207 so endI should be valid between 0 and 206. endI is only 80 when the code is failing.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    habibalex,

    The next step would be to use the prints to find what is happening in your script when the textbox is being used.

    Specifically the print in the if statement with the print of Times[1][endI].
    Print(string.Format("CurrentBars[1]: {0} | endI: {1}", CurrentBars[1], endI));


    If you want to have the script trigger after the last historical bar, you can do this by checking that the CurrentBars[0] is equal to the BarsArray[0].Count minus 1 (because this index is 0 based) and CurrentBars[1] (for the second index) is also equal to its BarsArray[1] index (also minus 1).

    if (State == State.Historical && CurrentBars[0] == (BarsArray[0].Count - 1) && CurrentBars[1] == (BarsArray[1].Count - 1))


    But in the code there should be a check that the index about to be used, in this case endI, is less than the CurrentBar count for that BarsInProgress index (CurrentBars[1]).

    if (endI > CurrentBars[1])
    {
    Print(Times[1][endI];
    }


    You could also only process this on the secondary BarsInProgress index and return if the BarsInProgress is not the secondary series, the series for which the time is being printed. This would be added to the first line of OnBarUpdate().
    if (BarsInProgress != 1)
    return;

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello habibalex,

    During our remote session we found that by adding the indicator I have provided in post #13 to an ES 03-16 1 Minute chart with 5 days to load using <Use instrument settings> as the session template, we are able to reproduce the error on your computer.

    Reducing the code was able to highlight than an error can be triggered in the original script by adding to this script to a 1 Minute chart with 5 days to load as the indicator loads without typing into the text box. This textbox may also be causing an error at the time it is triggered with the parameters sent to findFlips as well.

    The next step is to understanding what line of code is causing the first error and why. Then we can address the error being generated by the text box.

    The script is going to have a secondary data series. There is no check in OnBarUpdate to decide which data series this findFlips method on. This means that OnBarUpdate is going to trigger for every bar for both the primary and secondary data series. It is important to know which data series is processing when the method is called.

    I've added a few prints:

    To the beginning on OnBarUpdate() I have added:
    Code:
    Print(string.Format("{0} | BIP: {1} | CurrentBar: {2} | Times[1].Count: {3} | Times[1].Count - 2: {4} | State: {5}", Time[0], BarsInProgress, CurrentBar, Times[1].Count, (Times[1].Count - 2), State));
    This lets me know when the first condition will evaluate as true.

    When calling findFlips I print the values used in the call:
    Code:
    Print(string.Format("{0} | CurrentBars[0]: {1} | CurrentBars[1]: {2} | calling findFlips({3}, {4}, {5})", Time[0], CurrentBars[0], CurrentBars[1], (Times[1].Count - 1), 0, .5));
    To the for loop in findFlips I have added:
    Code:
    Print(string.Format("key: {0} | BarsArray[0].Count: {1} | BarsArray[1].Count: {2} | Times[1].Count - 1 - key: {3}", key, BarsArray[0].Count, BarsArray[1].Count, (Times[1].Count - 1 - key)));
    This tells me when the condition in the findFlips method is true in the loop.

    Last I print:
    Code:
    Print(string.Format("CurrentBars[1]: {0} | endI: {1}", CurrentBars[1], endI));
    This tells me if you are calling a bar from Times[1] before that bar is evaluated in historical data.


    The last print is what is important.
    I am getting the following output:
    CurrentBars[1]: 151 | endI: 252
    Indicator 'FlipsTest': Error on calling 'OnBarUpdate' method on bar 755: Object reference not set to an instance of an object.

    This is telling me that as the primary bar series of 1 minute hits bar 755, the 5 minute bar series does not have that many bars. When the 1 minute series is on bar 755, the 5 minute series is on bar 151 (because there are 1/5th as many bars).

    So CurrentBars[1] is on bar 151 but we are calling Times[1][252] and there isn't a bar there in the 5 minute series yet.

    Attached is the script with the prints added so that you can see how I have arrived at this conclusion.
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 12-29-2015, 02:58 PM.

    Leave a comment:


  • habibalex
    replied
    Since I couldn't get the barsAgo (Times[1][barsAgo]) to work properly I found out I can use BarsArray[1] to access all the historical data. I'm not sure why NT8 isn't populating barsAgo correctly, but my indicator is working correctly now. In case you have the same problem use:
    BarsArray[1].GetTime(index),
    BarsArray[1].GetHigh(index), ect...to get OHLC for the secondary series. This works every time correctly for me.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello habibalex,

    I am unable to run this script on my end without an error.

    I would like to schedule a call with you so that I may test the indicator on your end and gather further information.

    Please send an email to platformsupport [at] ninjatrader [dot] com. In the email please add a link to this forum thread.

    Leave a comment:


  • habibalex
    replied
    I don't see any error on my side when your modified indicator is run, however it will not trigger after the chart is loaded.

    I was not getting any errors in OnBarUpdate, only when findFlips was called after the chart had loaded.
    Last edited by habibalex; 12-24-2015, 01:17 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi habibalex,

    Because multiple community members have mentioned in this thread this error, I took the time to remove all of the unnecessary code from your script and make it a barebones version of the script that is able to reproduce the error.

    Please study what I have removed. This is important so that in the future if you would like a member of the NinjaScript support staff to look at your code, you know what we are looking for so that we may assist you.

    We do not provide debugging services or modify scripts created by clients in the NinjaScript department and generally will not reduce your code to the exact issue as I have done for you. When presenting an issue, please do not include any code that is not absolutely necessary to reproduce the issue.

    May I confirm that this modified script is able to cause the error on your end? (I am able to reproduce this error with this reduced script just by adding this to a chart)

    Now that I have a simplified script, I will look further into the cause.
    Attached Files
    Last edited by NinjaTrader_ChelseaB; 12-24-2015, 01:08 PM.

    Leave a comment:


  • habibalex
    replied
    I was only getting an error when findFlips is run after the indicator was loaded. I was not getting an error when it was run from OnBarUpdate. It does not need to be executed through a textbox, but just after the chart is loaded. I guess if I'm connected to a live data feed, and OnBarUpdate is called it should have the same effect. I wanted to do it on demand though...either way how do I access the Time, Open, Low, High, Close chart data if the those objects aren't correctly populated?
    Last edited by habibalex; 12-24-2015, 01:02 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello habibalex,

    What I mean is, can you skip the part with the changing text box. Why is it necessary to trigger this with typing text into a text box?

    The typing of text only appears to trigger findFlips(Times[1].Count-1, 288,minFlipRotation);//endi USED TO BE 0 not -288.

    It doesn't appear that this needs to be called when typing text into the text box. It looks like the code just needs to trigger findFlips.

    Can you further explain why this must be done when the text in the text box is changed?

    I ask because it also appears to be triggered from OnBarUpdate and is able to generate the error when the indicator is first added to the chart.

    All the other code in the script appears unnecessary.

    Leave a comment:


  • habibalex
    replied
    Have you tried running the code? It throws an error on the Print statement which is mentioned in the first post when called from the textbox after the indicator is loaded.

    When the code findFlips is run from OnBarUpdate it works corrrectly as expected. When it is run when the textbox is changed, it fails on the Print(Times[1][endI]) statement. To change the textbox you need the TextBox_PreviewKeyDown function. To run the function you need the button_TextChanged function. You need AddButtToToolbar to add the button to the toolbar. Yes I didn't remove all the variables in there, sorry about that.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello habibalex,

    I am looking through the code, but I am not understanding why you have to have textbox or what this does.

    In OnBarUpdate this appears to be calling findFlips() directly which appears to be a loop that is doing some check with BarsArray and printing the Time of a certain number of bars ago endI.

    Can you explain why the text box is necessary to loop through the bar information?

    It almost appears that private void TextBox_PreviewKeyDown isn't necessary, button_TextChanged isn't necessary, rivate void AddButtonToToolbar() isn't necessary, and most of the variables in the script are not necessary.
    The majority of this script appears to not be necessary to reproduce the issue.

    Is the issue not that part but instead somewhere in the rest of the code?
    Which line of code is generating the error? (To find this add prints to the code after each step to see which print appears before the error is generated)

    TurtleBeach,

    You mention that you are also experiencing an index as well. Your code appears to be simple and direct. Do you have a barebones sample that I could test and assist with?

    Leave a comment:


  • habibalex
    replied
    Yes all the code there is necessary to demonstrate the problem. I had to add a data series to the chart, a textbox to the chart to fire off the findflips function, and handle code for the textbox.
    The findflips function is where the error is occurring. You can post it if you want.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello habibalex,

    I have received a script from you in my private inbox.

    In your post, most of what is in this script is not mentioned. May I confirm this script the minimal amount of code necessary to reproduce the issue?

    The code for this quite extensive. Is every bit of this to demonstrate what is causing the issue?

    May I post this script to the forum with any added prints?

    Leave a comment:


  • habibalex
    replied
    Chelsea i sent you a link to the indicator as a private message

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by Waxavi, Today, 02:10 AM
0 responses
3 views
0 likes
Last Post Waxavi
by Waxavi
 
Started by TradeForge, Today, 02:09 AM
0 responses
9 views
0 likes
Last Post TradeForge  
Started by Waxavi, Today, 02:00 AM
0 responses
2 views
0 likes
Last Post Waxavi
by Waxavi
 
Started by elirion, Today, 01:36 AM
0 responses
4 views
0 likes
Last Post elirion
by elirion
 
Started by gentlebenthebear, Today, 01:30 AM
0 responses
4 views
0 likes
Last Post gentlebenthebear  
Working...
X