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 "OnBarUpdate" method on bar 0

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

    Error on calling "OnBarUpdate" method on bar 0

    I'm getting this error on a strategy I built. I have tried every conceivable way to resolve it from responses in the forum but it's still not working. Is it possible that it's just not reading the chart data for some reason, and not a simple conflict?

    Everything compiles fine. I started with strategy builder to get a base code, then built everything out from there, I recently added order instructions and when I went to do a dry run with it, I get the error as I try to enable it.

    #2
    Hello Conceptzx,

    What is the full error message?

    Ctrl + c to copy the error from the Log tab of the Control Center, Ctrl + v to paste in your reply.

    If the full error is stating an index error, see the forum post below.
    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Strategy 'CXreversal': Error on calling 'OnBarUpdate' method on bar 2: Index was outside the bounds of the array.
      9/11/2023 7:24:10 PM Strategy 'CXC/305165547': Ignored SubmitOrderManaged() method at 9/11/2023 7:24:10 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='ExitShorts' FromEntrySignal='ShortA, ShortB, ShortC' Reason='This was an exit order but no position exists to exit'
      8/21/2023 10:06:00 PM CancelAllOrders: BarsInProgress=0
      8/21/2023 10:06:00 PM CancelAllOrders: BarsInProgress=1​

      is the NS output I get



      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 2)
      return;

      ​is how I have it currently configured. Look back set to infinite, tried 1000 days for data series and everything I could think of. I've tried several Protected Override Void settings. The script compiles with no errors and only one warning because I made a parameter to change the Entries per direction in the settings rather then the code.
      Last edited by Conceptzx; 09-11-2023, 01:33 PM.

      Comment


        #4
        Hello Conceptzx,

        What is the full error message?

        Ctrl + c to copy the error from the Log tab of the Control Center, Ctrl + v to paste in your reply.​

        What line of code is causing the error? (If you are unsure add unique prints above each condition or action)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I thought I added it, but it disappeared when I added the second clipping, I updated the previous post

          Comment


            #6
            Hello Conceptzx,

            I see the error is an indexing error.

            What is the line of code causing the error?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              How do I find the line causing the error? Everything looks good in Ninjascript Editor

              Comment


                #8
                Hello Conceptzx,

                If you are unsure add unique prints above each condition or action.

                Below is a link to a forum post on using prints to understand behavior.


                The last print to appear will be one line above the line with the error.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  Strategy 'CXreversal': Error on calling 'OnBarUpdate' method on bar 2: Index was outside the bounds of the array.
                  System.Collections.ObjectModel.Collection`1[NinjaTrader.NinjaScript.StrategyBase] CXreversal
                  8/21/2023 10:06:00 PM CancelAllOrders: BarsInProgress=0
                  8/21/2023 10:06:00 PM CancelAllOrders: BarsInProgress=1​

                  Does this make any sense? It fails when I enable.

                  Comment


                    #10
                    Is there a print input that would give a full report of operations?

                    Comment


                      #11
                      Are you calling AddDataSeries in your script?

                      Comment


                        #12
                        Hello Conceptzx,

                        Have you added unique prints above each condition and action?

                        Print("step 1");

                        if (Conditions)

                        Print("step 2");

                        etc?

                        Which of the prints was the last to appear?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          I do not have a data series defined because it was intended to be used on several instruments and time frames. I tried step 1, step 2... But I get the same output.

                          Comment


                            #14
                            Hello Conceptzx,

                            Just to confirm, you are getting this output from the NinjaScript Output window?

                            None of the prints you have added at all are appearing?

                            Try printing from OnStateChange() above the State conditions (for all states).

                            Does this print appear?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              I tried on printing from onstatechange already as well. Yes that's why I get from the output window when I try to enable the strategy.

                              I'll probably just start from scratch again and add things one by one to see where it finally breaks.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by PhillT, 04-19-2024, 02:16 PM
                              4 responses
                              34 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Started by ageeholdings, 05-01-2024, 05:22 AM
                              5 responses
                              37 views
                              0 likes
                              Last Post ageeholdings  
                              Started by reynoldsn, Today, 02:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post reynoldsn  
                              Started by nightstalker, Today, 02:05 PM
                              0 responses
                              18 views
                              0 likes
                              Last Post nightstalker  
                              Started by llanqui, Yesterday, 09:59 AM
                              8 responses
                              30 views
                              0 likes
                              Last Post llanqui
                              by llanqui
                               
                              Working...
                              X