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 CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        52 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        29 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        194 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        355 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        274 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X