Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling "OnBarUpdate" method on bar0

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

    Error on calling "OnBarUpdate" method on bar0

    I created a strategy using strategy builder. But when I backtest, I get this error message: Error on calling "OnBarUpdate" method on bar0: Index was outside of the array.

    Any help please. Thanks.

    #2
    Hello AdeptistJune,

    Thank you for your post.

    I'd like to take a look at the strategy and see why it may be throwing that error. You can export the strategy from Tools > Export > NinjaScript Add-on. Do not check the box to export as a compiled assembly or I will not be able to review the logic. Please attach the resulting .Zip file to your reply.

    Thanks in advance; I look forward to assisting you further.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks so much. I attached the file as instructed
      Attached Files

      Comment


        #4
        Hello AdeptistJune,

        Thank you for your reply.

        Your problem isn't the strategy itself, it's the indicators it calls.

        All 5 indicators need to look back at least 1 and up to 5 bars in order to calculate. If you don't tell the script to wait to calculate until you have at least the largest lookback number of bars, you'll get an error when the strategy tries to call the indicator.

        This is an easy fix, however, you just need to add a current bar check at the top of OnBarUpdate in each indicator, like seen below:

        protected override void OnBarUpdate()
        {
        // don't start processing until 5 bars are available to look back at
        if(CurrentBar < 5)
        return;


        Value[0] = Close[5] - Close[4];
        }

        You'll need to adjust all of the indicators to add a CurrentBar check like the bolded code above and then you should be able to run the strategy without an error.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Thank so much.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by proptradingshop, Yesterday, 11:30 AM
          9 responses
          30 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by NRITV, Today, 09:05 AM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by xiinteractive, Today, 08:29 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by DT215, 08-08-2023, 11:03 AM
          3 responses
          445 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by Thomas79, Today, 08:14 AM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X