Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate error

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

    OnBarUpdate error

    I created a strategy but when enabled in chart I get this error (See quote below). I believe there is a snippet I need to add in the code but forget which one. Please advice. Thanks.

    Error on calling 'OnBarUpdate' method on bar 0: 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.​

    #2
    Never mind I figured it out it's this snippet below.

    Code:
    if (CurrentBars[0] < 5) //Need more than 5 bars to trade
                {
                    return;
                }​

    Comment


      #3
      Hello, thanks for writing in. You likely are accessing a series 1 bar ago on the first bar on the chart e.g. Close[1] would throw this error on CurrentBar == 0. Add this to the top of OnBarUpate:

      if(CurrentBar < 1) //1, or the max lookback in your script.
      return;

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kinfxhk, 07-14-2026, 09:39 AM
      0 responses
      19 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 10:18 AM
      0 responses
      60 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 09:50 AM
      0 responses
      43 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 07:21 AM
      0 responses
      47 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-11-2026, 02:11 AM
      0 responses
      38 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X