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

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.



    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 port119, 04-27-2024, 02:43 PM
        2 responses
        21 views
        0 likes
        Last Post port119
        by port119
         
        Started by AaronKTradingForum, Yesterday, 02:37 PM
        4 responses
        37 views
        0 likes
        Last Post AaronKTradingForum  
        Started by iceman2018, 04-27-2024, 05:07 PM
        1 response
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by adaisguy, Yesterday, 10:27 PM
        0 responses
        8 views
        0 likes
        Last Post adaisguy  
        Started by Jltarrau, Yesterday, 10:18 PM
        0 responses
        8 views
        0 likes
        Last Post Jltarrau  
        Working...
        X