Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Errors getting indicator values

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

    Errors getting indicator values

    I'm trying to create an Indicator that is using current and historical values of an ATR.

    I can call:
    Code:
    [INDENT]if(BarsInProgress > 20)[/INDENT][INDENT=2]return;[/INDENT][INDENT]{[/INDENT][INDENT=2]atrValue = ATR(10)[0];[/INDENT][INDENT]}[/INDENT]
    And have no issues but if I call:

    Code:
    [INDENT]
    if(BarsInProgress > 20)[/INDENT][INDENT=2]return;[/INDENT][INDENT]{[/INDENT][INDENT=2]prevATR = ATR(10)[1];[/INDENT][INDENT]}[/INDENT]
    I get the following error:
    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.

    I've tried many different methods to try to get the ATR's historical values including attempting to store the values in a Series<T>. In this attempt for example
    Code:
    else if (State == State.DataLoaded)[INDENT]{[/INDENT][INDENT=2]ATRdata = new Series<double>(this, MaximumBarsLookBack.Infinite);[/INDENT][INDENT]}[/INDENT]
      
    protected override void OnBarUpdate()[INDENT]{[/INDENT][INDENT=2]if (BarsInProgress > 20)[/INDENT][INDENT=3]return;[/INDENT][INDENT=2]{[/INDENT][INDENT=3]ATRdata[0] = ATR(10)[0];[/INDENT][INDENT=3]Print("Current ATR is " ATRdata[0]);[/INDENT][INDENT=3]prevATR = ATRdata[1];[/INDENT][INDENT=3]Print("Previous ATR is " + prevATR);[/INDENT][INDENT=2]}[/INDENT][INDENT]}[/INDENT]
    But still get " Error on calling 'OnBarUpdate' method on bar 0:" when trying to get the prevATR value.

    I'm rather new to NT8 coding.
    Any help would be appreciated. Perhaps something I missed.

    #2
    Hello Displacer,

    It looks like you have a few problems here. I'm am basing my reply off the fact that you used the curly braces with the BarsInProgress condition, I take it that you meant 20 bars here.

    To use 1 BarsAgo with the ATR you would need the following:
    Code:
    if(CurrentBar < 1) return;
    atrValue = ATR(10)[1];
    The 1 bar would be required for 1 bars ago, you can still use 20 as well if you wanted but the minimum would be 1 for that statement.

    The curly braces you used makes the BarsInProgress condition confusing, if you actually did mean for that BarsInProgress condition then it would instead look like:

    Code:
    if (BarsInProgress > 20) return;
    if(CurrentBar < 1) return;
    atrValue = ATR(10)[1];

    Comment


      #3
      Thank you! This solved my issue.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X