Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error

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

    Error

    I had a totally working code. Now the code keeps giving me this:

    **NT** Error on calling 'OnBarUpdate' method for strategy: Sequence contains no elements

    #2
    Hello,

    Your NinjaScript / C# Code will always be logically processed and evaluate according to your set logic – this can of course lead to unexpected results at times, thus we would suggest to simplify and debug your code to better understand the event sequence it would go through - if you would like please post an example script which replicates the error mentioned so that we may examine it

    First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

    For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

    It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.

    If you would prefer the debug assist of a professional NinjaScript consultant, please check into the following listings - Click here for a list of certified NinjaScript Consultants
    LanceNinjaTrader Customer Service

    Comment


      #3
      Somehow it will not pass through this step

      Code:
      if(ToDay(Time[0]) == ToDay(DateTime.Now.AddDays(-1)))
                          {
      Yet this exists in the chart. I am not sure why.

      Comment


        #4
        Hello,

        I'm not able to replicate this error with this bit of code alone. While I dont know for sure without seeing the rest of the code you may consider adding the following as a check to ensure enough bars have been loaded before your processing begins.

        Code:
        // Checks to make sure we have at least 20 or more bars
             if (CurrentBar < 20)
                  return;
        LanceNinjaTrader Customer Service

        Comment


          #5
          Thanks! I just found the issue. I had some misunderstandings in the code where the code was called way before it should have. It called the code and then it realized that the lists that I use in the code are empty at this time. Soo that why I got the error.

          Comment

          Latest Posts

          Collapse

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