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, 03-31-2026, 09:41 PM
        1 response
        43 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        21 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        30 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        50 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        40 views
        0 likes
        Last Post CarlTrading  
        Working...
        X