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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X