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 guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        68 views
        0 likes
        Last Post jeronymite  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        4 responses
        18 views
        0 likes
        Last Post trilliantrader  
        Started by mgco4you, Yesterday, 09:46 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by wzgy0920, Yesterday, 09:53 PM
        0 responses
        10 views
        0 likes
        Last Post wzgy0920  
        Working...
        X