Announcement

Collapse
No announcement yet.

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.

    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.

        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 NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          92 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          152 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          80 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          53 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          63 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X