Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling "On BarUpdate" Indicator

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

    Error on calling "On BarUpdate" Indicator

    HI,

    I'm trying to write a simple indicator, that compares the current bar high value with the previous bar high value as follows:
    if (High[0]<High[1])
    {
    res=100;
    }

    However, I'm getting the run time error: Error on Calling OnBarUpdate....on bar 0. You are accessing an index with a value that is invalide since its out of range.
    1. Can someone explain why I get that error message?
    2. Is there a way to know how many bars are loaded into the cart (i.e. In case I need to look back to find whether a condition existed in the past).

    Thank you.



    #2
    Hello,

    it sounds like you're already on the right track for identifying the error.

    You will want to add a CurrentBar check at the start of your OnBarUpdate() to ensure enough bars have been loaded.

    http://www.ninjatrader.com/support/h...currentbar.htm

    Let me know if I can be of further assistance.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thank you for the quick response.
      As you suggested, I checked the value of CurrentBar and is really = 0.
      However, I don't really understand why.
      My Chart contain way more the 0 bars.
      Any idea?


      Adding later....:
      Ok...I think I understand now.
      I need to add the condition:
      if (CurrentBar<2)
      return....
      Last edited by rmaron; 06-12-2013, 04:29 PM.

      Comment


        #4
        This is because when you add an indicator to a chart it will begin calculating from bar 0 and load each bar in 1 at a time until it reaches the current bar.

        Adding the return is beneficial in many scripts that require more data to be loaded before calculating.
        LanceNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Renorail, Today, 01:38 PM
        1 response
        5 views
        0 likes
        Last Post Renorail  
        Started by BrianARice, Today, 01:16 PM
        0 responses
        5 views
        0 likes
        Last Post BrianARice  
        Started by Ousher, Today, 09:08 AM
        0 responses
        6 views
        0 likes
        Last Post Ousher
        by Ousher
         
        Started by Unsuitable, Today, 08:41 AM
        0 responses
        14 views
        0 likes
        Last Post Unsuitable  
        Started by newdill, Today, 07:54 AM
        0 responses
        7 views
        0 likes
        Last Post newdill
        by newdill
         
        Working...
        X