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

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 GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,227 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          440 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          12 views
          0 likes
          Last Post FAQtrader  
          Working...
          X