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!
See more
See less

Partner 728x90

Collapse

Error 'You are accessing an index with a value' for indicator requiring tick replay

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

    Error 'You are accessing an index with a value' for indicator requiring tick replay

    Hey guys,

    I'm likely doing something wrong for this simple request but I'm just trying to load this custom indicator that uses the OrderFlowCumulativeDelta indicator and print out the values. But, my output window is just saying:

    Error on calling 'OnBarUpdate' method on bar 20: 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.

    I've attached the custom indicator and my simple script. Can you offer a hand?

    Thank you.
    Attached Files

    #2
    Hello PN720,

    I see you have a CurrentBars check for the primary series, however you do not for the added series.

    Do you still see the error if you change:
    Code:
     
     if (CurrentBars[0] < 10 ) return;
    to
    Code:
    if (CurrentBars[0] < 10 || CurrentBars[1] < 10 ) return;
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hi Jesse,

      Ah, of course! It had to be something simple like that. Corrected syntax now reads:

      Code:
      if (CurrentBars[0] < 10 || CurrentBars[1] < 10 ) return;
      
      if (BarsInProgress == 0)
      {
      Print (Time[0] + " - Delta Up: " + DeltaInd.UpMomo[0] + ". Delta Down: " + DeltaInd.DownMomo[0]);
      }
      I have another question, though. When I run this code against a 1 minute chart and have Tick Replay checked, I just get zeros for values. If I change to BarsInProgress == 1, I get values but it's echoing out for every 1 tick. Is it not possible for me to show it for every 1 minute?

      Comment


        #4
        Hello PN720,

        In the indicator it looks like you are only assigning a plot value in BarsInProgress = 1, do you see the same problem if you assign the values from BarsInProgress=0 instead?

        The sample requires using BIP1 for updating the indicator, however the rest of your logic can reside in BIP0:

        Code:
        if (BarsInProgress == 0)
                    {
        
                          //Print("Delta Close: " + cumulativeDelta.DeltaClose[0]);   //where you would otherwise normally use the delta value
                    }
        else if (BarsInProgress == 1)
                    {
                          // We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync
                          // mainly used for updating. 
                          cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);
        Can you try moving the indicator logic into BIP 0 and then retest? I would likely need to dig into this further if that is not the case, this is the most obvious item I can see looking at the code.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Hi Jesse,
          I found a workaround to this so I'm good now, thanks for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,221 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          6 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          437 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          9 views
          0 likes
          Last Post FAQtrader  
          Working...
          X