Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

'OnBarUpdate' method on bar 3: Object reference not set to an instance of an object.

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

    'OnBarUpdate' method on bar 3: Object reference not set to an instance of an object.

    The strategy will run, but when using the Strategy Analyzer for optimizing or backtesting an exception error occurs. pjsHeikenAshi Histogram indicator for Delta Mode uses OnPriceChange Close[0] - Open[0] to get the values that indicator that is needs to measure the Delta change. EMA820 uses OnBarClose for the type of calcuation

    Does the exception have to do with using multiple indicators with a combination different calculation types going to work for doing analysis and backtesting?​
    Attached Files

    #2
    Hello Tonofit,

    Where you have mentioned:
    "a combination different calculation types"

    This is not allowed for hosted indicators. Any indicator called by a strategy (or other host indicator) must be using the same calculation mode.
    Use Calculate.OnEachTick so this will satisfy host and hosted dependents, and code the scripts that need to trigger actions when the bar closes with IsFirstTickOfBar.
    Use TickReplay in historical, should you want this to update properly in historical data.

    The error is that barsAgo index is invalid. Meaning that indicator may not have a value yet.
    Try using if (CurrentBars[0] < 2) return;
    (Or is this a script locked for editing in the Strategy Builder? In which case the indicator code needs to be corrected)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I changed the strategy to use Calculate.OnEachTick and added a data series of native Ticks,but one of the histograms needs to use Calculate.OnPriceChange. When the strategy starts I'm using variables that act as signals to control that only a single trade occurs with OnBarUpdate. How should I setup the initalization so the variables are set to false when real-time occurs?

      Comment


        #4
        Hello Tonofit,

        Any script that works on price change will also work on each tick.

        You can initialize variables when State is State.DataLoaded in OnStateChange().
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        560 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        325 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        547 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X