• 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

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, 03: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 ChazJ, Today, 02:54 PM
        2 responses
        3 views
        0 likes
        Last Post ChazJ
        by ChazJ
         
        Started by Boonfly8, Today, 02:04 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by Branpo, Today, 01:25 PM
        5 responses
        11 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by aslane, Today, 12:47 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by HavasuTrader, Today, 12:30 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Working...
        X