Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 traderqz, Today, 12:06 AM
      9 responses
      16 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by kevinenergy, 02-17-2023, 12:42 PM
      117 responses
      2,766 views
      1 like
      Last Post jculp
      by jculp
       
      Started by Mongo, Today, 11:05 AM
      5 responses
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by SightCareAubetter, Today, 12:50 PM
      0 responses
      2 views
      0 likes
      Last Post SightCareAubetter  
      Started by Skifree, Today, 03:41 AM
      5 responses
      14 views
      0 likes
      Last Post Skifree
      by Skifree
       
      Working...
      X