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

'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 fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,404 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        95 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        7 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        159 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        8 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X