• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

accessing historical bar values of indicator

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

    accessing historical bar values of indicator

    Hi,

    Apologies in advance, as I guess I'm doing somthing stupid. I figured I could access historical bars in an indicator in the same way as the main dataseries, but for some reason, it does not work

    I have this code which updates 2 plots

    AskInt[0] = totalAsk;
    BidInt[0] = totalBid;
    if (Bars.Count>20)
    {
    if (BidInt.Count>20)
    {
    BidInt[0]= totalBid - BidInt[10];
    }
    if (AskInt.Count>20)
    {
    AskInt[0] = totalAsk - AskInt[10];
    }
    }

    The idea being to reduce the value each by the value from 10 bars ago. However, I always get this error, even though I checked enough bars exist

    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.

    If I comment out the above (except the plot update first 2 lines), all runs as expected.

    What an I doing wrong?

    Thanks.

    #2
    Hello,

    This is likely caused if you are not checking that X number of bars exist before checking X number of BarsAgo.

    In this case it looks like you are accessing BidInt[10]

    You would likely need to add a CurrentBar check to allow 10 bars to happen before this gets called:

    Code:
    protected override void OnBarUpdate()
    {
         if(CurrentBar < 10) return;
    .....
    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Ah, thanks. Somehow I though checking bars.count would yeild the same result.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by U0000999, Today, 05:17 AM
      0 responses
      3 views
      0 likes
      Last Post U0000999  
      Started by Prataturry89, Today, 03:40 AM
      0 responses
      5 views
      0 likes
      Last Post Prataturry89  
      Started by UltraFastKetoBoost28, Today, 02:43 AM
      0 responses
      6 views
      0 likes
      Last Post UltraFastKetoBoost28  
      Started by kojakojids, Today, 02:04 AM
      0 responses
      5 views
      0 likes
      Last Post kojakojids  
      Started by pitifak, Today, 01:01 AM
      0 responses
      4 views
      0 likes
      Last Post pitifak
      by pitifak
       
      Working...
      X