Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

indicator not showing in range chart

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

    indicator not showing in range chart

    My custom indicator works yesterday, but not today. Then I found out it works on minute charts but not range charts. Got error:

    Error on calling 'OnBarUpdate' method for indicator 'SwingIndex' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

    Can anyone help?

    Code as follow:

    #region Variables

    private bool _initialized = false;
    private int dailylimit = 10000;

    #endregion


    protected override void Initialize()
    {
    Add(new Plot(Color.Orange, "SwingIndex"));
    Add(new Line(Color.DarkViolet, 0,""));

    Overlay = false;
    }


    protected override void OnBarUpdate()
    {
    if (!_initialized)
    _initialized = true;

    double R1 = Math.Abs(High[0] - Close[1]);
    double R2 = Math.Abs(Low[0] - Close[1]);
    double R3 = Math.Abs(High[0] - Low[0]);
    double R4 = Math.Abs(Close[1] - Open[1]);
    double K = Math.Max(R1, R2);
    double R ;
    double X ;
    double T = dailylimit;

    if (R1 >= Math.Max(R2, R3))
    {
    R = R1 - R2/2 + R4/4;
    }
    else if (R2 >= Math.Max(R1, R3))
    {
    R = R2 - R1/2 + R4/4;
    }
    else
    {
    R = R3 + R4/4;
    }

    if (CurrentBar == 0)
    Value.Set(Input[0]);

    else
    {
    X = (Close[0] - Close[1]) + (Close[0] - Open[0])/2 + (Close[1] - Open[1])/4;
    Value.Set(50 * (X/R) * (K/T));
    }

    }

    #2
    Welcome to our forums - you likely see this as you're missing a check for having enough CurrentBars at the OnBarUpdate() start :

    Comment


      #3
      Thanks, works fine now!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      579 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      334 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      551 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X