Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CurrentBars[1]

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

    CurrentBars[1]

    Whenever I try to reference the previous Bar using CurrentBars[1] I get an error 'outside the bounds of the array'.

    Which is the correct method to reference the previous bar?

    #2
    Hello several,

    Are you trying to get the index of the previous bar? CurrentBar is the index of the processing bar, to get the previous index would be CurrentBar - 1. If you are trying to use BarsAgo to get a price you need to use the series for that like Close: Close[1]

    Comment


      #3
      I'm just trying to compare a variable which has a bar number stored to the previous bar.

      So I've been doing;

      If (CurrentBars[0] - 1) == MyVar

      But it makes more sense to write:

      If CurrentBars[1] == MyVar

      Comment


        #4
        Hello several,

        You are using the Plural CurrentBars and not the singular CurrentBar, CurrentBars is used to get the index in a multi series script. For example CurrentBars[1] would represent the secondary series. In a single series script you have singular CurrentBar which does not take a bars ago, that's just the index of what bar is being processed. To know what the previous bars index was you would need to subtract 1 from CurrentBar.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        87 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by M4ndoo, 04-20-2026, 05:21 PM
        0 responses
        128 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by M4ndoo, 04-19-2026, 05:54 PM
        0 responses
        65 views
        0 likes
        Last Post M4ndoo
        by M4ndoo
         
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        117 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        67 views
        0 likes
        Last Post PaulMohn  
        Working...
        X